moveToOverflow moves overflow out of children to the OverflowItems list
()
| 118 | |
| 119 | // moveToOverflow moves overflow out of children to the OverflowItems list |
| 120 | func (tb *Toolbar) moveToOverflow() { |
| 121 | if !tb.HasChildren() { |
| 122 | return |
| 123 | } |
| 124 | ma := tb.Styles.Direction.Dim() |
| 125 | avail := tb.parentSize() |
| 126 | li := tb.Children[tb.NumChildren()-1] |
| 127 | tb.overflowButton = nil |
| 128 | if li != nil { |
| 129 | if ob, ok := li.(*Button); ok { |
| 130 | tb.overflowButton = ob |
| 131 | } |
| 132 | } |
| 133 | if tb.overflowButton == nil { |
| 134 | return |
| 135 | } |
| 136 | ovsz := tb.overflowButton.Geom.Size.Actual.Total.Dim(ma) |
| 137 | avsz := avail - ovsz |
| 138 | sz := &tb.Geom.Size |
| 139 | sz.Alloc.Total.SetDim(ma, avail) |
| 140 | sz.setContentFromTotal(&sz.Alloc) |
| 141 | n := len(tb.Children) |
| 142 | pn := len(tb.allItemsPlan.Children) |
| 143 | ovidx := n - 1 |
| 144 | hasOv := false |
| 145 | szsum := float32(0) |
| 146 | tb.ForWidgetChildren(func(i int, cw Widget, cwb *WidgetBase) bool { |
| 147 | if i >= n-1 { |
| 148 | return tree.Break |
| 149 | } |
| 150 | ksz := cwb.Geom.Size.Alloc.Total.Dim(ma) |
| 151 | szsum += ksz |
| 152 | if szsum > avsz { |
| 153 | if !hasOv { |
| 154 | ovidx = i |
| 155 | hasOv = true |
| 156 | } |
| 157 | pi := tb.allItemsPlan.Children[i] |
| 158 | tb.overflowItems = append(tb.overflowItems, pi) |
| 159 | } |
| 160 | return tree.Continue |
| 161 | }) |
| 162 | if hasOv { |
| 163 | p := &tree.Plan{Parent: tb.This} |
| 164 | p.Children = tb.allItemsPlan.Children[:ovidx] |
| 165 | p.Children = append(p.Children, tb.allItemsPlan.Children[pn-1]) // ovm |
| 166 | p.Update(tb) |
| 167 | } |
| 168 | if len(tb.overflowItems) == 0 && len(tb.OverflowMenus) == 0 { |
| 169 | tb.overflowButton.SetState(true, states.Invisible) |
| 170 | } else { |
| 171 | tb.overflowButton.SetState(false, states.Invisible) |
| 172 | tb.overflowButton.Update() |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | // overflowMenu adds the overflow menu to the given Scene. |
| 177 | func (tb *Toolbar) overflowMenu(m *Scene) { |
no test coverage detected