separator.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2018 visualfc. All rights reserved.
  2. package tk
  3. import "fmt"
  4. // separator
  5. type Separator struct {
  6. BaseWidget
  7. }
  8. func NewSeparator(parent Widget, orient Orient, attributes ...*WidgetAttr) *Separator {
  9. iid := makeNamedWidgetId(parent, "atk_separator")
  10. attributes = append(attributes, &WidgetAttr{"orient", orient})
  11. info := CreateWidgetInfo(iid, WidgetTypeSeparator, true, attributes)
  12. if info == nil {
  13. return nil
  14. }
  15. w := &Separator{}
  16. w.id = iid
  17. w.info = info
  18. RegisterWidget(w)
  19. return w
  20. }
  21. func (w *Separator) Attach(id string) error {
  22. info, err := CheckWidgetInfo(id, WidgetTypeSeparator)
  23. if err != nil {
  24. return err
  25. }
  26. w.id = id
  27. w.info = info
  28. RegisterWidget(w)
  29. return nil
  30. }
  31. func (w *Separator) SetOrient(orient Orient) error {
  32. return eval(fmt.Sprintf("%v configure -orient {%v}", w.id, orient))
  33. }
  34. func (w *Separator) Orient() Orient {
  35. r, err := evalAsString(fmt.Sprintf("%v cget -orient", w.id))
  36. return parserOrientResult(r, err)
  37. }
  38. func (w *Separator) SetTakeFocus(takefocus bool) error {
  39. return eval(fmt.Sprintf("%v configure -takefocus {%v}", w.id, boolToInt(takefocus)))
  40. }
  41. func (w *Separator) IsTakeFocus() bool {
  42. r, _ := evalAsBool(fmt.Sprintf("%v cget -takefocus", w.id))
  43. return r
  44. }
  45. func SeparatorAttrOrient(orient Orient) *WidgetAttr {
  46. return &WidgetAttr{"orient", orient}
  47. }
  48. func SeparatorAttrTakeFocus(takefocus bool) *WidgetAttr {
  49. return &WidgetAttr{"takefocus", boolToInt(takefocus)}
  50. }