func (l *List) VisibleItemRange(includePartiallyVisible bool) (startIndex, endIndex int) { if l.itemCount == 0 { return 0, 0 } s := l.outer.Size() p := l.outer.Padding() majorAxisItemSize := l.MajorAxisItemSize() if majorAxisItemSize == 0 { return 0, 0 } startIndex = l.scrollOffset if !includePartiallyVisible { startIndex += majorAxisItemSize - 1 } if l.orientation.Horizontal() { endIndex = l.scrollOffset + s.W - p.W() } else { endIndex = l.scrollOffset + s.H - p.H() } if includePartiallyVisible { endIndex += majorAxisItemSize - 1 } startIndex = math.Max(startIndex/majorAxisItemSize, 0) endIndex = math.Min(endIndex/majorAxisItemSize, l.itemCount) return startIndex, endIndex }
func (l *List) SetScrollOffset(scrollOffset int) { if l.adapter == nil { return } s := l.outer.Size().Contract(l.outer.Padding()) if l.orientation.Horizontal() { maxScroll := math.Max(l.itemSize.W*l.itemCount-s.W, 0) scrollOffset = math.Clamp(scrollOffset, 0, maxScroll) l.scrollBar.SetScrollPosition(scrollOffset, scrollOffset+s.W) } else { maxScroll := math.Max(l.itemSize.H*l.itemCount-s.H, 0) scrollOffset = math.Clamp(scrollOffset, 0, maxScroll) l.scrollBar.SetScrollPosition(scrollOffset, scrollOffset+s.H) } if l.scrollOffset != scrollOffset { l.scrollOffset = scrollOffset l.LayoutChildren() } }
// InputEventHandler overrides func (s *ScrollBar) Click(ev gxui.MouseEvent) (consume bool) { if !s.barRect.Contains(ev.Point) { p := s.positionAt(ev.Point) from, to := s.scrollPositionFrom, s.scrollPositionTo switch { case p < from: width := to - from from = math.Max(from-width, 0) s.SetScrollPosition(from, from+width) case p > to: width := to - from to = math.Min(to+width, s.scrollLimit) s.SetScrollPosition(to-width, to) } } return true }
func (p *PanelHolder) RemovePanel(panel gxui.Control) { index := p.PanelIndex(panel) if index < 0 { panic("PanelHolder does not contain panel") } entry := p.entries[index] entry.MouseDownSubscription.Unlisten() p.entries = append(p.entries[:index], p.entries[index+1:]...) p.tabLayout.RemoveChildAt(index) if panel == p.selected.Panel { if p.PanelCount() > 0 { p.Select(math.Max(index-1, 0)) } else { p.Select(-1) } } }
func (l *List) DesiredSize(min, max math.Size) math.Size { if l.adapter == nil { return min } count := math.Max(l.itemCount, 1) var s math.Size if l.orientation.Horizontal() { s = math.Size{W: l.itemSize.W * count, H: l.itemSize.H} } else { s = math.Size{W: l.itemSize.W, H: l.itemSize.H * count} } if l.scrollBarEnabled { if l.orientation.Horizontal() { s.H += l.scrollBar.DesiredSize(min, max).H } else { s.W += l.scrollBar.DesiredSize(min, max).W } } return s.Expand(l.outer.Padding()).Clamp(min, max) }
func generateLenHistogram(regexp string, maxLen int, args *GeneratorArgs) (counts []int) { generator, err := NewGenerator(regexp, args) if err != nil { panic(err) } iterations := math.Max(maxLen*4, SampleSize) for i := 0; i < iterations; i++ { str := generator.Generate() // Grow the slice if necessary. if len(str) >= len(counts) { newCounts := make([]int, len(str)+1) copy(newCounts, counts) counts = newCounts } counts[len(str)]++ } return }
func (t *TextBoxAdapter) Count() int { return math.Max(t.TextBox.controller.LineCount(), 1) }
func (t *TextBoxController) IndexLeft(i int) int { return math.Max(i-1, 0) }