github.com/jmigpin/editor@v1.6.0/ui/columns.go (about) 1 package ui 2 3 import ( 4 "image" 5 6 "github.com/jmigpin/editor/util/uiutil/widget" 7 ) 8 9 type Columns struct { 10 widget.ENode 11 ColsLayout *widget.SplBg // exported to access sp values 12 Root *Root 13 } 14 15 func NewColumns(root *Root) *Columns { 16 cols := &Columns{Root: root} 17 18 // when where are no cols, or the first column is pushed aside 19 noCols0 := widget.NewRectangle(root.UI) 20 noCols0.SetThemePaletteNamePrefix("columns_nocols_") 21 noCols := WrapInTopShadowOrSeparator(root.UI, noCols0) 22 23 cols.ColsLayout = widget.NewSplBg(noCols) 24 cols.ColsLayout.Spl.MinimumChildSize = 15 // TODO 25 cols.Append(cols.ColsLayout) 26 27 return cols 28 } 29 30 func (cols *Columns) NewColumn() *Column { 31 col := NewColumn(cols) 32 cols.InsertColumnBefore(col, nil) 33 34 // ensure up-to-date values now (ex: bounds, drawer.getpoint) 35 cols.LayoutMarked() 36 37 return col 38 } 39 40 func (cols *Columns) InsertBefore(col widget.Node, next *widget.EmbedNode) { 41 panic("!") 42 } 43 44 func (cols *Columns) InsertColumnBefore(col, next *Column) { 45 var nexte *widget.EmbedNode 46 if next != nil { 47 nexte = next.Embed() 48 } 49 cols.ColsLayout.Spl.InsertBefore(col, nexte) 50 } 51 52 func (cols *Columns) removeColumn(col *Column) { 53 cols.ColsLayout.Spl.Remove(col) 54 } 55 56 //---------- 57 58 func (cols *Columns) PointColumn(p *image.Point) (*Column, bool) { 59 for _, c := range cols.Columns() { 60 if p.In(c.Bounds) { 61 return c, true 62 } 63 } 64 return nil, false 65 } 66 func (cols *Columns) PointColumnExtra(p *image.Point) (*Column, bool) { 67 col, ok := cols.PointColumn(p) 68 if ok { 69 return col, true 70 } 71 72 // detect outside of limits through X coord 73 // assume at least one column is present 74 if p.X < cols.FirstChildColumn().Embed().Bounds.Min.X { 75 return cols.FirstChildColumn(), true 76 } else if p.X > cols.LastChildColumn().Embed().Bounds.Max.X { 77 return cols.LastChildColumn(), true 78 } else { 79 for _, c := range cols.Columns() { 80 x0, x1 := c.Bounds.Min.X, c.Bounds.Max.X 81 if p.X >= x0 && p.X < x1 { 82 return c, true 83 } 84 } 85 } 86 87 return nil, false 88 } 89 90 //---------- 91 92 func (cols *Columns) FirstChildColumn() *Column { 93 u := cols.ColsLayout.Spl.FirstChildWrapper() 94 if u == nil { 95 return nil 96 } 97 return u.(*Column) 98 } 99 func (cols *Columns) LastChildColumn() *Column { 100 u := cols.ColsLayout.Spl.LastChildWrapper() 101 if u == nil { 102 return nil 103 } 104 return u.(*Column) 105 } 106 107 func (cols *Columns) Columns() []*Column { 108 u := make([]*Column, 0, cols.ColsLayout.Spl.ChildsLen()) 109 cols.ColsLayout.Spl.IterateWrappers2(func(c widget.Node) { 110 u = append(u, c.(*Column)) 111 }) 112 return u 113 }