Exemple #1
0
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
}
Exemple #2
0
func (t *TextBox) updateHorizScrollLimit() {
	maxWidth := t.MaxLineWidth()
	size := t.Size().Contract(t.outer.Padding())
	maxScroll := math.Max(maxWidth-size.W, 0)
	math.Clamp(t.horizOffset, 0, maxScroll)
	t.horizScroll.SetScrollLimit(maxWidth)
}
Exemple #3
0
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()
	}
}
Exemple #4
0
// 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
}
Exemple #5
0
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)
		}
	}
}
Exemple #6
0
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)
}
Exemple #7
0
func (t *TextBoxAdapter) Count() int {
	return math.Max(t.TextBox.controller.LineCount(), 1)
}
Exemple #8
0
func (t *TextBoxController) IndexLeft(sel TextSelection) TextSelection {
	sel.start = math.Max(sel.start-1, 0)
	sel.end = math.Max(sel.end-1, 0)
	return sel.Store()
}