Example #1
0
func (t *TextBox) Init(outer TextBoxOuter, driver gxui.Driver, theme gxui.Theme, font gxui.Font) {
	t.List.Init(outer, theme)
	t.Focusable.Init(outer)
	t.outer = outer
	t.driver = driver
	t.font = font
	t.onRedrawLines = gxui.CreateEvent(func() {})
	t.controller = gxui.CreateTextBoxController()
	t.adapter = &TextBoxAdapter{TextBox: t}
	t.desiredWidth = 100
	t.SetScrollBarEnabled(false) // Defaults to single line
	t.OnGainedFocus(func() { t.onRedrawLines.Fire() })
	t.OnLostFocus(func() { t.onRedrawLines.Fire() })
	t.horizScroll = theme.CreateScrollBar()
	t.horizScrollChild = t.AddChild(t.horizScroll)
	t.horizScroll.SetOrientation(gxui.Horizontal)
	t.horizScroll.OnScroll(func(from, to int) {
		t.SetHorizOffset(from)
	})

	t.controller.OnTextChanged(func([]gxui.TextBoxEdit) {
		t.onRedrawLines.Fire()
		t.List.DataChanged(false)
	})
	t.controller.OnSelectionChanged(func() {
		t.onRedrawLines.Fire()
	})

	t.List.SetAdapter(t.adapter)

	// Interface compliance test
	_ = gxui.TextBox(t)
}
Example #2
0
func (l *ScrollLayout) Init(outer ScrollLayoutOuter, theme gxui.Theme) {
	l.Container.Init(outer, theme)
	l.BackgroundBorderPainter.Init(outer)

	l.outer = outer
	l.theme = theme
	l.canScrollX = true
	l.canScrollY = true
	scrollBarX := theme.CreateScrollBar()
	scrollBarX.SetOrientation(gxui.Horizontal)
	scrollBarX.OnScroll(func(from, to int) { l.SetScrollOffset(math.Point{X: from, Y: l.scrollOffset.Y}) })
	scrollBarY := theme.CreateScrollBar()
	scrollBarY.SetOrientation(gxui.Vertical)
	scrollBarY.OnScroll(func(from, to int) { l.SetScrollOffset(math.Point{X: l.scrollOffset.X, Y: from}) })
	l.scrollBarX = l.AddChild(scrollBarX)
	l.scrollBarY = l.AddChild(scrollBarY)
	l.SetMouseEventTarget(true)

	// Interface compliance test
	_ = gxui.ScrollLayout(l)
}
Example #3
0
File: list.go Project: nelsam/gxui
func (l *List) Init(outer ListOuter, theme gxui.Theme) {
	l.outer = outer
	l.Container.Init(outer, theme)
	l.BackgroundBorderPainter.Init(outer)
	l.Focusable.Init(outer)

	l.theme = theme
	l.scrollBar = theme.CreateScrollBar()
	l.scrollBarChild = l.AddChild(l.scrollBar)
	l.scrollBarEnabled = true
	l.scrollBar.OnScroll(func(from, to int) { l.SetScrollOffset(from) })

	l.SetOrientation(gxui.Vertical)
	l.SetBackgroundBrush(gxui.TransparentBrush)
	l.SetMouseEventTarget(true)

	l.details = make(map[gxui.AdapterItem]itemDetails)

	// Interface compliance test
	_ = gxui.List(l)
}