Пример #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
}
Пример #2
0
func (t *TextBoxController) IndexDown(i int) int {
	l := t.LineIndex(i)
	x := i - t.LineStart(l)
	if l < t.LineCount()-1 {
		return math.Min(t.LineStart(l+1)+x, t.LineEnd(l+1))
	} else {
		return t.LineEnd(l)
	}
}
Пример #3
0
func (t *TextBoxController) IndexUp(i int) int {
	l := t.LineIndex(i)
	x := i - t.LineStart(l)
	if l > 0 {
		return math.Min(t.LineStart(l-1)+x, t.LineEnd(l-1))
	} else {
		return 0
	}
}
Пример #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
}
Пример #5
0
func (t *TextBoxController) UnindentSelection(tabWidth int) {
	text, edit, edits := t.text, TextBoxEdit{}, []TextBoxEdit{}
	lastLine := -1
	for i := len(t.selections) - 1; i >= 0; i-- {
		s := t.selections[i]
		lis, lie := t.LineIndex(s.start), t.LineIndex(s.end)
		if lastLine == lie {
			lie--
		}
		for l := lie; l >= lis; l-- {
			c := math.Min(t.LineIndent(l), tabWidth)
			if c > 0 {
				ls := t.LineStart(l)
				text, edit = t.ReplaceAt(text, ls, ls+c, []rune{})
				edits = append(edits, edit)
			}
		}
		lastLine = lis
	}
	t.SetTextEdits(text, edits)
}
Пример #6
0
func (t *TextBoxController) IndexRight(i int) int {
	return math.Min(i+1, len(t.text))
}