Exemplo n.º 1
0
Arquivo: list.go Projeto: nelsam/gxui
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
}
Exemplo n.º 2
0
func (t *TextBoxController) indexUp(i, stored int) int {
	line := t.LineIndex(i)
	storedLine := t.LineIndex(stored)
	x := stored - t.LineStart(storedLine)
	if line > 0 {
		return math.Min(t.LineStart(line-1)+x, t.LineEnd(line-1))
	}
	return 0
}
Exemplo n.º 3
0
// TODO: figure out why pressing down at the end of the file goes back one character
func (t *TextBoxController) indexDown(i, stored int) int {
	line := t.LineIndex(i)
	storedLine := t.LineIndex(stored)
	x := stored - t.LineStart(storedLine)
	if line < t.LineCount()-1 {
		return math.Min(t.LineStart(line+1)+x, t.LineEnd(line+1))
	}
	return len(t.text) - 1
}
Exemplo n.º 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
}
Exemplo n.º 5
0
func (t *TextBoxController) IndexRight(sel TextSelection) TextSelection {
	sel.start = math.Min(sel.start+1, len(t.text))
	sel.end = math.Min(sel.end+1, len(t.text))
	return sel.Store()
}