Update code for objects
This commit is contained in:
parent
25a59d888c
commit
85fbe9c996
34
button.go
34
button.go
@ -30,14 +30,13 @@ func NewButton (text string) *Button {
|
|||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "Button"))
|
box.SetRole(tomo.R("objects", "Button"))
|
||||||
box.label.SetAttr(tomo.AAlign(tomo.AlignMiddle, tomo.AlignMiddle))
|
box.label.SetAttr(tomo.AAlign(tomo.AlignMiddle, tomo.AlignMiddle))
|
||||||
box.SetLayout(buttonLayout)
|
box.SetAttr(tomo.ALayout(buttonLayout))
|
||||||
box.SetText(text)
|
box.SetText(text)
|
||||||
|
|
||||||
box.CatchDND(true)
|
box.SetInputMask(true)
|
||||||
box.CatchMouse(true)
|
|
||||||
|
|
||||||
box.OnButtonDown(box.handleButtonDown)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
box.OnButtonUp(box.handleButtonUp)
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
|
box.OnKeyDown(box.handleKeyDown)
|
||||||
box.OnKeyUp(box.handleKeyUp)
|
box.OnKeyUp(box.handleKeyUp)
|
||||||
box.SetFocusable(true)
|
box.SetFocusable(true)
|
||||||
return box
|
return box
|
||||||
@ -80,27 +79,34 @@ func (this *Button) OnClick (callback func ()) event.Cookie {
|
|||||||
|
|
||||||
func (this *Button) applyLayout () {
|
func (this *Button) applyLayout () {
|
||||||
if this.labelActive && this.icon == nil {
|
if this.labelActive && this.icon == nil {
|
||||||
this.SetLayout(buttonLayout)
|
this.SetAttr(tomo.ALayout(buttonLayout))
|
||||||
} else if !this.labelActive && this.icon != nil {
|
} else if !this.labelActive && this.icon != nil {
|
||||||
this.SetLayout(iconButtonLayout)
|
this.SetAttr(tomo.ALayout(iconButtonLayout))
|
||||||
} else {
|
} else {
|
||||||
this.SetLayout(bothButtonLayout)
|
this.SetAttr(tomo.ALayout(bothButtonLayout))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Button) handleKeyUp (catch func (), key input.Key, numberPad bool) {
|
func (this *Button) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
if key != input.KeyEnter && key != input.Key(' ') { return false }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Button) handleKeyUp (key input.Key, numberPad bool) bool {
|
||||||
|
if key != input.KeyEnter && key != input.Key(' ') { return false }
|
||||||
this.on.click.Broadcast()
|
this.on.click.Broadcast()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Button) handleButtonDown (catch func (), button input.Button) {
|
func (this *Button) handleButtonDown (button input.Button) bool {
|
||||||
catch()
|
if button != input.ButtonLeft { return false }
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Button) handleButtonUp (catch func (), button input.Button) {
|
func (this *Button) handleButtonUp (button input.Button) bool {
|
||||||
catch()
|
if button != input.ButtonLeft { return false }
|
||||||
if button != input.ButtonLeft { return }
|
|
||||||
if this.Window().MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.on.click.Broadcast()
|
this.on.click.Broadcast()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
10
calendar.go
10
calendar.go
@ -27,7 +27,7 @@ func NewCalendar (tm time.Time) *Calendar {
|
|||||||
time: tm,
|
time: tm,
|
||||||
}
|
}
|
||||||
calendar.SetRole(tomo.R("objects", "Calendar"))
|
calendar.SetRole(tomo.R("objects", "Calendar"))
|
||||||
calendar.SetLayout(layouts.ContractVertical)
|
calendar.SetAttr(tomo.ALayout(layouts.ContractVertical))
|
||||||
|
|
||||||
prevButton := NewButton("")
|
prevButton := NewButton("")
|
||||||
prevButton.SetIcon(tomo.IconGoPrevious)
|
prevButton.SetIcon(tomo.IconGoPrevious)
|
||||||
@ -46,8 +46,8 @@ func NewCalendar (tm time.Time) *Calendar {
|
|||||||
|
|
||||||
calendar.grid = tomo.NewContainerBox()
|
calendar.grid = tomo.NewContainerBox()
|
||||||
calendar.grid.SetRole(tomo.R("objects", "CalendarGrid"))
|
calendar.grid.SetRole(tomo.R("objects", "CalendarGrid"))
|
||||||
calendar.grid.SetLayout(layouts.NewGrid (
|
calendar.grid.SetAttr(tomo.ALayout(layouts.NewGrid (
|
||||||
true, true, true, true, true, true, true)())
|
true, true, true, true, true, true, true)()))
|
||||||
calendar.Add(NewInnerContainer (
|
calendar.Add(NewInnerContainer (
|
||||||
layouts.Row { false, true, false },
|
layouts.Row { false, true, false },
|
||||||
prevButton, calendar.monthLabel, nextButton))
|
prevButton, calendar.monthLabel, nextButton))
|
||||||
@ -128,13 +128,13 @@ func (this *Calendar) refresh () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Calendar) handleScroll (catch func (), x, y float64) {
|
func (this *Calendar) handleScroll (x, y float64) bool {
|
||||||
catch()
|
|
||||||
if y < 0 {
|
if y < 0 {
|
||||||
this.prevMonth()
|
this.prevMonth()
|
||||||
} else {
|
} else {
|
||||||
this.nextMonth()
|
this.nextMonth()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func firstOfMonth (tm time.Time) time.Time {
|
func firstOfMonth (tm time.Time) time.Time {
|
||||||
|
22
checkbox.go
22
checkbox.go
@ -23,6 +23,7 @@ func NewCheckbox (value bool) *Checkbox {
|
|||||||
|
|
||||||
box.OnButtonDown(box.handleButtonDown)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
box.OnButtonUp(box.handleButtonUp)
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
|
box.OnKeyDown(box.handleKeyDown)
|
||||||
box.OnKeyUp(box.handleKeyUp)
|
box.OnKeyUp(box.handleKeyUp)
|
||||||
box.SetFocusable(true)
|
box.SetFocusable(true)
|
||||||
return box
|
return box
|
||||||
@ -52,19 +53,26 @@ func (this *Checkbox) OnValueChange (callback func ()) event.Cookie {
|
|||||||
return this.on.valueChange.Connect(callback)
|
return this.on.valueChange.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Checkbox) handleKeyUp (catch func (), key input.Key, numberPad bool) {
|
func (this *Checkbox) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
if key != input.KeyEnter && key != input.Key(' ') { return false }
|
||||||
this.Toggle()
|
this.Toggle()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Checkbox) handleButtonDown (catch func (), button input.Button) {
|
func (this *Checkbox) handleKeyUp (key input.Key, numberPad bool) bool {
|
||||||
catch()
|
if key != input.KeyEnter && key != input.Key(' ') { return false}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Checkbox) handleButtonUp (catch func (), button input.Button) {
|
func (this *Checkbox) handleButtonDown (button input.Button) bool {
|
||||||
catch()
|
if button != input.ButtonLeft { return false }
|
||||||
if button != input.ButtonLeft { return }
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Checkbox) handleButtonUp (button input.Button) bool {
|
||||||
|
if button != input.ButtonLeft { return false }
|
||||||
if this.Window().MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.Toggle()
|
this.Toggle()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func NewColorPicker (value color.Color) *ColorPicker {
|
|||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
}
|
}
|
||||||
picker.SetRole(tomo.R("objects", "ColorPicker"))
|
picker.SetRole(tomo.R("objects", "ColorPicker"))
|
||||||
picker.SetLayout(layouts.Row { true, false, false })
|
picker.SetAttr(tomo.ALayout(layouts.Row { true, false, false }))
|
||||||
picker.pickerMap = newColorPickerMap(picker)
|
picker.pickerMap = newColorPickerMap(picker)
|
||||||
picker.Add(picker.pickerMap)
|
picker.Add(picker.pickerMap)
|
||||||
|
|
||||||
@ -97,20 +97,23 @@ func newColorPickerMap (parent *ColorPicker) *colorPickerMap {
|
|||||||
return picker
|
return picker
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) handleButtonDown (catch func (), button input.Button) {
|
func (this *colorPickerMap) handleButtonDown (button input.Button) bool {
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return false }
|
||||||
this.dragging = true
|
this.dragging = true
|
||||||
this.drag()
|
this.drag()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) handleButtonUp (catch func (), button input.Button) {
|
func (this *colorPickerMap) handleButtonUp (button input.Button) bool {
|
||||||
if button != input.ButtonLeft || !this.dragging { return }
|
if button != input.ButtonLeft { return false }
|
||||||
this.dragging = false
|
this.dragging = false
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) handleMouseMove () {
|
func (this *colorPickerMap) handleMouseMove () bool {
|
||||||
if !this.dragging { return }
|
if !this.dragging { return false }
|
||||||
this.drag()
|
this.drag()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) drag () {
|
func (this *colorPickerMap) drag () {
|
||||||
|
@ -15,7 +15,7 @@ func newContainer (layout tomo.Layout, children ...tomo.Object) *Container {
|
|||||||
this := &Container {
|
this := &Container {
|
||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
}
|
}
|
||||||
this.SetLayout(layout)
|
this.SetAttr(tomo.ALayout(layout))
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
this.Add(child)
|
this.Add(child)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
|
|||||||
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
box.Add(box.checkbox)
|
box.Add(box.checkbox)
|
||||||
box.Add(box.label)
|
box.Add(box.label)
|
||||||
box.SetLayout(layouts.Row { false, true })
|
box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
||||||
|
|
||||||
box.OnButtonDown(box.handleButtonDown)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
box.OnButtonUp(box.handleButtonUp)
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
@ -52,15 +52,16 @@ func (this *LabelCheckbox) OnValueChange (callback func ()) event.Cookie {
|
|||||||
return this.checkbox.OnValueChange(callback)
|
return this.checkbox.OnValueChange(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *LabelCheckbox) handleButtonDown (capture func (), button input.Button) {
|
func (this *LabelCheckbox) handleButtonDown (button input.Button) bool {
|
||||||
capture()
|
if button != input.ButtonLeft { return false }
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *LabelCheckbox) handleButtonUp (capture func (), button input.Button) {
|
func (this *LabelCheckbox) handleButtonUp (button input.Button) bool {
|
||||||
capture()
|
if button != input.ButtonLeft { return false }
|
||||||
if button != input.ButtonLeft { return }
|
|
||||||
if this.Window().MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.checkbox.SetFocused(true)
|
this.checkbox.SetFocused(true)
|
||||||
this.checkbox.Toggle()
|
this.checkbox.Toggle()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ func NewLabelSwatch (value color.Color, text string) *LabelSwatch {
|
|||||||
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
box.Add(box.swatch)
|
box.Add(box.swatch)
|
||||||
box.Add(box.label)
|
box.Add(box.label)
|
||||||
box.SetLayout(layouts.Row { false, true })
|
box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
||||||
|
|
||||||
box.OnButtonDown(box.handleButtonDown)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
box.OnButtonUp(box.handleButtonUp)
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
@ -60,15 +60,16 @@ func (this *LabelSwatch) OnConfirm (callback func ()) event.Cookie {
|
|||||||
return this.swatch.OnConfirm(callback)
|
return this.swatch.OnConfirm(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *LabelSwatch) handleButtonDown (catch func (), button input.Button) {
|
func (this *LabelSwatch) handleButtonDown (button input.Button) bool {
|
||||||
catch()
|
if button != input.ButtonLeft { return true }
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *LabelSwatch) handleButtonUp (catch func (), button input.Button) {
|
func (this *LabelSwatch) handleButtonUp (button input.Button) bool {
|
||||||
catch()
|
if button != input.ButtonLeft { return true }
|
||||||
if button != input.ButtonLeft { return }
|
|
||||||
if this.Window().MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.swatch.SetFocused(true)
|
this.swatch.SetFocused(true)
|
||||||
this.swatch.Choose()
|
this.swatch.Choose()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
45
menu.go
45
menu.go
@ -13,7 +13,7 @@ type Menu struct {
|
|||||||
parent tomo.Window
|
parent tomo.Window
|
||||||
bounds image.Rectangle
|
bounds image.Rectangle
|
||||||
rootContainer tomo.ContainerBox
|
rootContainer tomo.ContainerBox
|
||||||
tearLine tomo.Box
|
tearLine tomo.Object
|
||||||
torn bool
|
torn bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,22 +36,10 @@ func NewMenu (anchor tomo.Object, items ...tomo.Object) (*Menu, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
menu.rootContainer = tomo.NewContainerBox()
|
menu.rootContainer = tomo.NewContainerBox()
|
||||||
menu.rootContainer.SetLayout(layouts.ContractVertical)
|
menu.rootContainer.SetAttr(tomo.ALayout(layouts.ContractVertical))
|
||||||
|
|
||||||
if !menu.torn {
|
if !menu.torn {
|
||||||
menu.tearLine = tomo.NewBox()
|
menu.tearLine = menu.newTearLine()
|
||||||
menu.tearLine.SetRole(tomo.R("objects", "TearLine"))
|
|
||||||
menu.tearLine.SetFocusable(true)
|
|
||||||
menu.tearLine.OnKeyUp(func (catch func (), key input.Key, numberPad bool) {
|
|
||||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
|
||||||
menu.TearOff()
|
|
||||||
})
|
|
||||||
menu.tearLine.OnButtonUp(func (catch func (), button input.Button) {
|
|
||||||
if button != input.ButtonLeft { return }
|
|
||||||
if menu.tearLine.Window().MousePosition().In(menu.tearLine.Bounds()) {
|
|
||||||
menu.TearOff()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
menu.rootContainer.Add(menu.tearLine)
|
menu.rootContainer.Add(menu.tearLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,6 +80,33 @@ func (this *Menu) TearOff () {
|
|||||||
this.Window.SetVisible(visible)
|
this.Window.SetVisible(visible)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *Menu) newTearLine () tomo.Object {
|
||||||
|
tearLine := tomo.NewBox()
|
||||||
|
tearLine.SetRole(tomo.R("objects", "TearLine"))
|
||||||
|
tearLine.SetFocusable(true)
|
||||||
|
tearLine.OnKeyDown(func (key input.Key, numberPad bool) bool {
|
||||||
|
if key != input.KeyEnter && key != input.Key(' ') { return false }
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
tearLine.OnKeyUp(func (key input.Key, numberPad bool) bool {
|
||||||
|
if key != input.KeyEnter && key != input.Key(' ') { return false }
|
||||||
|
this.TearOff()
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
tearLine.OnButtonDown(func (button input.Button) bool {
|
||||||
|
if button != input.ButtonLeft { return false }
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
tearLine.OnButtonUp(func (button input.Button) bool {
|
||||||
|
if button != input.ButtonLeft { return false }
|
||||||
|
if tearLine.Window().MousePosition().In(tearLine.Bounds()) {
|
||||||
|
this.TearOff()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return tearLine
|
||||||
|
}
|
||||||
|
|
||||||
func menuBoundsFromAnchor (anchor tomo.Object) image.Rectangle {
|
func menuBoundsFromAnchor (anchor tomo.Object) image.Rectangle {
|
||||||
bounds := anchor.GetBox().Bounds()
|
bounds := anchor.GetBox().Bounds()
|
||||||
return image.Rect (
|
return image.Rect (
|
||||||
|
28
menuitem.go
28
menuitem.go
@ -27,16 +27,15 @@ func NewMenuItem (text string) *MenuItem {
|
|||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "MenuItem"))
|
box.SetRole(tomo.R("objects", "MenuItem"))
|
||||||
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
box.SetLayout(layouts.Row { false, true })
|
box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
||||||
|
|
||||||
box.Add(box.icon)
|
box.Add(box.icon)
|
||||||
box.Add(box.label)
|
box.Add(box.label)
|
||||||
|
|
||||||
box.CatchDND(true)
|
box.SetInputMask(true)
|
||||||
box.CatchMouse(true)
|
|
||||||
|
|
||||||
box.OnButtonDown(box.handleButtonDown)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
box.OnButtonUp(box.handleButtonUp)
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
|
box.OnKeyDown(box.handleKeyDown)
|
||||||
box.OnKeyUp(box.handleKeyUp)
|
box.OnKeyUp(box.handleKeyUp)
|
||||||
box.SetFocusable(true)
|
box.SetFocusable(true)
|
||||||
return box
|
return box
|
||||||
@ -59,19 +58,26 @@ func (this *MenuItem) OnClick (callback func ()) event.Cookie {
|
|||||||
return this.on.click.Connect(callback)
|
return this.on.click.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MenuItem) handleKeyUp (catch func(), key input.Key, numberPad bool) {
|
func (this *MenuItem) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
if key != input.KeyEnter && key != input.Key(' ') { return false }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MenuItem) handleKeyUp (key input.Key, numberPad bool) bool {
|
||||||
|
if key != input.KeyEnter && key != input.Key(' ') { return false }
|
||||||
this.on.click.Broadcast()
|
this.on.click.Broadcast()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MenuItem) handleButtonDown (catch func(), button input.Button) {
|
func (this *MenuItem) handleButtonDown (button input.Button) bool {
|
||||||
catch()
|
if button != input.ButtonLeft { return false }
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MenuItem) handleButtonUp (catch func(), button input.Button) {
|
func (this *MenuItem) handleButtonUp (button input.Button) bool {
|
||||||
catch()
|
if button != input.ButtonLeft { return false }
|
||||||
if button != input.ButtonLeft { return }
|
|
||||||
if this.Window().MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.on.click.Broadcast()
|
this.on.click.Broadcast()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
@ -32,15 +32,15 @@ func NewNumberInput (value float64) *NumberInput {
|
|||||||
box.Add(box.input)
|
box.Add(box.input)
|
||||||
box.Add(box.decrement)
|
box.Add(box.decrement)
|
||||||
box.Add(box.increment)
|
box.Add(box.increment)
|
||||||
box.SetLayout(layouts.Row { true, false, false })
|
box.SetAttr(tomo.ALayout(layouts.Row { true, false, false }))
|
||||||
box.increment.SetIcon(tomo.IconValueIncrement)
|
box.increment.SetIcon(tomo.IconValueIncrement)
|
||||||
box.decrement.SetIcon(tomo.IconValueDecrement)
|
box.decrement.SetIcon(tomo.IconValueDecrement)
|
||||||
|
|
||||||
box.SetValue(value)
|
box.SetValue(value)
|
||||||
|
|
||||||
box.OnScroll(box.handleScroll)
|
box.OnScroll(box.handleScroll)
|
||||||
box.OnKeyUp(box.handleKeyUp)
|
|
||||||
box.OnKeyDown(box.handleKeyDown)
|
box.OnKeyDown(box.handleKeyDown)
|
||||||
|
box.OnKeyUp(box.handleKeyUp)
|
||||||
box.input.OnConfirm(box.handleConfirm)
|
box.input.OnConfirm(box.handleConfirm)
|
||||||
box.input.OnValueChange(box.on.valueChange.Broadcast)
|
box.input.OnValueChange(box.on.valueChange.Broadcast)
|
||||||
box.increment.OnClick(func () { box.shift(1) })
|
box.increment.OnClick(func () { box.shift(1) })
|
||||||
@ -76,29 +76,32 @@ func (this *NumberInput) shift (by int) {
|
|||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *NumberInput) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
func (this *NumberInput) handleKeyDown (key input.Key, numpad bool) bool {
|
||||||
switch key {
|
switch key {
|
||||||
case input.KeyUp:
|
case input.KeyUp:
|
||||||
this.shift(1)
|
this.shift(1)
|
||||||
catch()
|
return true
|
||||||
case input.KeyDown:
|
case input.KeyDown:
|
||||||
this.shift(-1)
|
this.shift(-1)
|
||||||
catch()
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *NumberInput) handleKeyUp (catch func (), key input.Key, numpad bool) {
|
func (this *NumberInput) handleKeyUp (key input.Key, numpad bool) bool {
|
||||||
switch key {
|
switch key {
|
||||||
case input.KeyUp: catch()
|
case input.KeyUp: return true
|
||||||
case input.KeyDown: catch()
|
case input.KeyDown: return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *NumberInput) handleScroll (catch func (), x, y float64) {
|
func (this *NumberInput) handleScroll (x, y float64) bool {
|
||||||
if x == 0 {
|
if x == 0 {
|
||||||
catch()
|
|
||||||
this.shift(-int(math.Round(y)))
|
this.shift(-int(math.Round(y)))
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *NumberInput) handleConfirm () {
|
func (this *NumberInput) handleConfirm () {
|
||||||
|
54
scrollbar.go
54
scrollbar.go
@ -33,11 +33,9 @@ func newScrollbar (orient string) *Scrollbar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.Add(this.handle)
|
this.Add(this.handle)
|
||||||
|
|
||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
|
this.SetInputMask(true)
|
||||||
this.CatchDND(true)
|
|
||||||
this.CatchMouse(true)
|
|
||||||
|
|
||||||
this.OnKeyUp(this.handleKeyUp)
|
this.OnKeyUp(this.handleKeyUp)
|
||||||
this.OnKeyDown(this.handleKeyDown)
|
this.OnKeyDown(this.handleKeyDown)
|
||||||
this.OnButtonDown(this.handleButtonDown)
|
this.OnButtonDown(this.handleButtonDown)
|
||||||
@ -68,7 +66,7 @@ func (this *Scrollbar) Link (box tomo.ContentObject) event.Cookie {
|
|||||||
this.layout.linked = box
|
this.layout.linked = box
|
||||||
this.linkCookie = this.newLinkCookie (
|
this.linkCookie = this.newLinkCookie (
|
||||||
box.OnContentBoundsChange(this.handleLinkedContentBoundsChange))
|
box.OnContentBoundsChange(this.handleLinkedContentBoundsChange))
|
||||||
this.SetLayout(this.layout)
|
this.SetAttr(tomo.ALayout(this.layout))
|
||||||
return this.linkCookie
|
return this.linkCookie
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +79,7 @@ func (this *Scrollbar) handleLinkedContentBoundsChange () {
|
|||||||
} else {
|
} else {
|
||||||
this.layout.value = this.layout.contentPos() / trackLength
|
this.layout.value = this.layout.contentPos() / trackLength
|
||||||
}
|
}
|
||||||
this.SetLayout(this.layout)
|
this.SetAttr(tomo.ALayout(this.layout))
|
||||||
if this.layout.value != previousValue {
|
if this.layout.value != previousValue {
|
||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
}
|
}
|
||||||
@ -139,13 +137,17 @@ func (this *Scrollbar) StepSize () int {
|
|||||||
return 16
|
return 16
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleKeyUp (catch func (), key input.Key, numpad bool) {
|
func (this *Scrollbar) handleKeyUp (key input.Key, numpad bool) bool {
|
||||||
catch()
|
switch key {
|
||||||
|
case input.KeyUp, input.KeyLeft: return true
|
||||||
|
case input.KeyDown, input.KeyRight: return true
|
||||||
|
case input.KeyHome: return true
|
||||||
|
case input.KeyEnd: return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) bool {
|
||||||
catch()
|
|
||||||
|
|
||||||
var increment float64; if this.layout.vertical {
|
var increment float64; if this.layout.vertical {
|
||||||
increment = -0.05
|
increment = -0.05
|
||||||
} else {
|
} else {
|
||||||
@ -161,22 +163,25 @@ func (this *Scrollbar) handleKeyDown (catch func (), key input.Key, numpad bool)
|
|||||||
} else {
|
} else {
|
||||||
this.SetValue(this.Value() - increment)
|
this.SetValue(this.Value() - increment)
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
case input.KeyDown, input.KeyRight:
|
case input.KeyDown, input.KeyRight:
|
||||||
if modifiers.Alt {
|
if modifiers.Alt {
|
||||||
this.SetValue(1)
|
this.SetValue(1)
|
||||||
} else {
|
} else {
|
||||||
this.SetValue(this.Value() + increment)
|
this.SetValue(this.Value() + increment)
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
case input.KeyHome:
|
case input.KeyHome:
|
||||||
this.SetValue(0)
|
this.SetValue(0)
|
||||||
|
return true
|
||||||
case input.KeyEnd:
|
case input.KeyEnd:
|
||||||
this.SetValue(1)
|
this.SetValue(1)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleButtonDown (catch func (), button input.Button) {
|
func (this *Scrollbar) handleButtonDown (button input.Button) bool {
|
||||||
catch()
|
|
||||||
|
|
||||||
pointer := this.Window().MousePosition()
|
pointer := this.Window().MousePosition()
|
||||||
handle := this.handle.Bounds()
|
handle := this.handle.Bounds()
|
||||||
|
|
||||||
@ -213,25 +218,26 @@ func (this *Scrollbar) handleButtonDown (catch func (), button input.Button) {
|
|||||||
this.scrollBy(-this.StepSize())
|
this.scrollBy(-this.StepSize())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleButtonUp (catch func (), button input.Button) {
|
func (this *Scrollbar) handleButtonUp (button input.Button) bool {
|
||||||
catch()
|
if button != input.ButtonLeft || !this.dragging { return true }
|
||||||
if button != input.ButtonLeft || !this.dragging { return }
|
|
||||||
this.dragging = false
|
this.dragging = false
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleMouseMove () {
|
func (this *Scrollbar) handleMouseMove () bool {
|
||||||
if !this.dragging { return }
|
if !this.dragging { return false }
|
||||||
this.drag()
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleScroll (catch func(), x, y float64) {
|
func (this *Scrollbar) handleScroll (x, y float64) bool {
|
||||||
catch()
|
if this.layout.linked == nil { return false }
|
||||||
if this.layout.linked == nil { return }
|
|
||||||
this.layout.linked.ScrollTo (
|
this.layout.linked.ScrollTo (
|
||||||
this.layout.linked.ContentBounds().Min.
|
this.layout.linked.ContentBounds().Min.
|
||||||
Sub(image.Pt(int(x), int(y))))
|
Sub(image.Pt(int(x), int(y))))
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) drag () {
|
func (this *Scrollbar) drag () {
|
||||||
@ -289,7 +295,7 @@ func (this *scrollbarCookie) Close () {
|
|||||||
cookie.Close()
|
cookie.Close()
|
||||||
}
|
}
|
||||||
this.owner.layout.linked = nil
|
this.owner.layout.linked = nil
|
||||||
this.owner.SetLayout(this.owner.layout)
|
this.owner.SetAttr(tomo.ALayout(this.owner.layout))
|
||||||
}
|
}
|
||||||
|
|
||||||
type scrollbarLayout struct {
|
type scrollbarLayout struct {
|
||||||
|
@ -73,7 +73,7 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
|
|||||||
this.OnKeyUp(this.handleKeyUp)
|
this.OnKeyUp(this.handleKeyUp)
|
||||||
this.SetRole(tomo.R("objects", "ScrollContainer"))
|
this.SetRole(tomo.R("objects", "ScrollContainer"))
|
||||||
this.SetTag(sides.String(), true)
|
this.SetTag(sides.String(), true)
|
||||||
this.SetLayout(layouts.NewGrid(true, false)(true, false))
|
this.SetAttr(tomo.ALayout(layouts.NewGrid(true, false)(true, false)))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,46 +172,46 @@ func (this *ScrollContainer) handleValueChange () {
|
|||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ScrollContainer) handleScroll (catch func (), x, y float64) {
|
|
||||||
catch()
|
|
||||||
if this.root == nil { return }
|
|
||||||
this.scrollBy(image.Pt(int(x), int(y)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ScrollContainer) scrollBy (vector image.Point) {
|
func (this *ScrollContainer) scrollBy (vector image.Point) {
|
||||||
if this.root == nil { return }
|
if this.root == nil { return }
|
||||||
|
if vector == (image.Point { }) { return }
|
||||||
this.root.ScrollTo (
|
this.root.ScrollTo (
|
||||||
this.root.ContentBounds().Min.
|
this.root.ContentBounds().Min.
|
||||||
Sub(vector))
|
Sub(vector))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ScrollContainer) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
func (this *ScrollContainer) handleScroll (x, y float64) bool {
|
||||||
|
if this.root == nil { return false }
|
||||||
|
this.scrollBy(image.Pt(int(x), int(y)))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ScrollContainer) handleKeyDown (key input.Key, numpad bool) bool {
|
||||||
modifiers := this.Window().Modifiers()
|
modifiers := this.Window().Modifiers()
|
||||||
vector := image.Point { }
|
vector := image.Point { }
|
||||||
switch key {
|
switch key {
|
||||||
case input.KeyPageUp:
|
case input.KeyPageUp:
|
||||||
catch()
|
|
||||||
if modifiers.Shift {
|
if modifiers.Shift {
|
||||||
vector.X -= this.PageSize().X
|
vector.X -= this.PageSize().X
|
||||||
} else {
|
} else {
|
||||||
vector.Y -= this.PageSize().Y
|
vector.Y -= this.PageSize().Y
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
case input.KeyPageDown:
|
case input.KeyPageDown:
|
||||||
catch()
|
|
||||||
if modifiers.Shift {
|
if modifiers.Shift {
|
||||||
vector.X += this.PageSize().X
|
vector.X += this.PageSize().X
|
||||||
} else {
|
} else {
|
||||||
vector.Y += this.PageSize().Y
|
vector.Y += this.PageSize().Y
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
if vector != (image.Point { }) {
|
return false
|
||||||
this.scrollBy(vector)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ScrollContainer) handleKeyUp (catch func (), key input.Key, numpad bool) {
|
func (this *ScrollContainer) handleKeyUp (key input.Key, numpad bool) bool {
|
||||||
switch key {
|
switch key {
|
||||||
case input.KeyPageUp: catch()
|
case input.KeyPageUp: return true
|
||||||
case input.KeyPageDown: catch()
|
case input.KeyPageDown: return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
46
slider.go
46
slider.go
@ -42,11 +42,9 @@ func newSlider (orient string, value float64) *Slider {
|
|||||||
|
|
||||||
this.Add(this.handle)
|
this.Add(this.handle)
|
||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
|
|
||||||
this.CatchDND(true)
|
|
||||||
this.CatchMouse(true)
|
|
||||||
|
|
||||||
this.SetValue(value)
|
this.SetValue(value)
|
||||||
|
|
||||||
|
this.SetInputMask(true)
|
||||||
this.OnKeyUp(this.handleKeyUp)
|
this.OnKeyUp(this.handleKeyUp)
|
||||||
this.OnKeyDown(this.handleKeyDown)
|
this.OnKeyDown(this.handleKeyDown)
|
||||||
this.OnButtonDown(this.handleButtonDown)
|
this.OnButtonDown(this.handleButtonDown)
|
||||||
@ -77,7 +75,7 @@ func (this *Slider) SetValue (value float64) {
|
|||||||
if value > 1 { value = 1 }
|
if value > 1 { value = 1 }
|
||||||
if value == this.layout.value { return }
|
if value == this.layout.value { return }
|
||||||
this.layout.value = value
|
this.layout.value = value
|
||||||
this.SetLayout(this.layout)
|
this.SetAttr(tomo.ALayout(this.layout))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value returns the value of the slider between 0 and 1.
|
// Value returns the value of the slider between 0 and 1.
|
||||||
@ -97,9 +95,7 @@ func (this *Slider) OnConfirm (callback func ()) event.Cookie {
|
|||||||
return this.on.confirm.Connect(callback)
|
return this.on.confirm.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
func (this *Slider) handleKeyDown (key input.Key, numpad bool) bool {
|
||||||
catch()
|
|
||||||
|
|
||||||
var increment float64; if this.layout.vertical {
|
var increment float64; if this.layout.vertical {
|
||||||
increment = -0.05
|
increment = -0.05
|
||||||
} else {
|
} else {
|
||||||
@ -114,6 +110,7 @@ func (this *Slider) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
|||||||
this.SetValue(this.Value() - increment)
|
this.SetValue(this.Value() - increment)
|
||||||
}
|
}
|
||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
|
return true
|
||||||
case input.KeyDown, input.KeyRight:
|
case input.KeyDown, input.KeyRight:
|
||||||
if this.Window().Modifiers().Alt {
|
if this.Window().Modifiers().Alt {
|
||||||
this.SetValue(1)
|
this.SetValue(1)
|
||||||
@ -121,22 +118,30 @@ func (this *Slider) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
|||||||
this.SetValue(this.Value() + increment)
|
this.SetValue(this.Value() + increment)
|
||||||
}
|
}
|
||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
|
return true
|
||||||
case input.KeyHome:
|
case input.KeyHome:
|
||||||
this.SetValue(0)
|
this.SetValue(0)
|
||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
|
return true
|
||||||
case input.KeyEnd:
|
case input.KeyEnd:
|
||||||
this.SetValue(1)
|
this.SetValue(1)
|
||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleKeyUp (catch func (), key input.Key, numpad bool) {
|
func (this *Slider) handleKeyUp (key input.Key, numpad bool) bool {
|
||||||
catch()
|
switch key {
|
||||||
|
case input.KeyUp, input.KeyLeft: return true
|
||||||
|
case input.KeyDown, input.KeyRight: return true
|
||||||
|
case input.KeyHome: return true
|
||||||
|
case input.KeyEnd: return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleButtonDown (catch func (), button input.Button) {
|
func (this *Slider) handleButtonDown (button input.Button) bool {
|
||||||
catch()
|
|
||||||
|
|
||||||
pointer := this.Window().MousePosition()
|
pointer := this.Window().MousePosition()
|
||||||
handle := this.handle.Bounds()
|
handle := this.handle.Bounds()
|
||||||
|
|
||||||
@ -181,25 +186,28 @@ func (this *Slider) handleButtonDown (catch func (), button input.Button) {
|
|||||||
this.on.confirm.Broadcast()
|
this.on.confirm.Broadcast()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleButtonUp (catch func (), button input.Button) {
|
func (this *Slider) handleButtonUp (button input.Button) bool {
|
||||||
catch()
|
if button != input.ButtonLeft || !this.dragging { return true }
|
||||||
if button != input.ButtonLeft || !this.dragging { return }
|
|
||||||
this.dragging = false
|
this.dragging = false
|
||||||
this.on.confirm.Broadcast()
|
this.on.confirm.Broadcast()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleMouseMove () {
|
func (this *Slider) handleMouseMove () bool {
|
||||||
if !this.dragging { return }
|
if !this.dragging { return false }
|
||||||
this.drag()
|
this.drag()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleScroll (catch func (), x, y float64) {
|
func (this *Slider) handleScroll (x, y float64) bool {
|
||||||
delta := (x + y) * 0.005
|
delta := (x + y) * 0.005
|
||||||
this.SetValue(this.Value() + delta)
|
this.SetValue(this.Value() + delta)
|
||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
this.on.confirm.Broadcast()
|
this.on.confirm.Broadcast()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) drag () {
|
func (this *Slider) drag () {
|
||||||
|
24
swatch.go
24
swatch.go
@ -30,7 +30,9 @@ func NewSwatch (value color.Color) *Swatch {
|
|||||||
swatch.SetDrawer(swatch)
|
swatch.SetDrawer(swatch)
|
||||||
swatch.SetValue(value)
|
swatch.SetValue(value)
|
||||||
|
|
||||||
|
swatch.OnButtonDown(swatch.handleButtonDown)
|
||||||
swatch.OnButtonUp(swatch.handleButtonUp)
|
swatch.OnButtonUp(swatch.handleButtonUp)
|
||||||
|
swatch.OnKeyDown(swatch.handleKeyDown)
|
||||||
swatch.OnKeyUp(swatch.handleKeyUp)
|
swatch.OnKeyUp(swatch.handleKeyUp)
|
||||||
swatch.SetFocusable(true)
|
swatch.SetFocusable(true)
|
||||||
return swatch
|
return swatch
|
||||||
@ -155,14 +157,26 @@ func (this *Swatch) userSetValue (value color.Color) {
|
|||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Swatch) handleKeyUp (catch func (), key input.Key, numberPad bool) {
|
func (this *Swatch) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
if key != input.KeyEnter && key != input.Key(' ') { return false }
|
||||||
this.Choose()
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Swatch) handleButtonUp (catch func (), button input.Button) {
|
func (this *Swatch) handleKeyUp (key input.Key, numberPad bool) bool {
|
||||||
if button != input.ButtonLeft { return }
|
if key != input.KeyEnter && key != input.Key(' ') { return false }
|
||||||
|
this.Choose()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Swatch) handleButtonDown (button input.Button) bool {
|
||||||
|
if button != input.ButtonLeft { return false }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Swatch) handleButtonUp (button input.Button) bool {
|
||||||
|
if button != input.ButtonLeft { return false }
|
||||||
if this.Window().MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.Choose()
|
this.Choose()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func NewTabbedContainer () *TabbedContainer {
|
|||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
}
|
}
|
||||||
container.SetRole(tomo.R("objects", "TabbedContainer"))
|
container.SetRole(tomo.R("objects", "TabbedContainer"))
|
||||||
container.SetLayout(layouts.Column { false, true } )
|
container.SetAttr(tomo.ALayout(layouts.Column { false, true }))
|
||||||
|
|
||||||
container.tabsRow = tomo.NewContainerBox()
|
container.tabsRow = tomo.NewContainerBox()
|
||||||
container.tabsRow.SetRole(tomo.R("objects", "TabRow"))
|
container.tabsRow.SetRole(tomo.R("objects", "TabRow"))
|
||||||
@ -59,9 +59,14 @@ func (this *TabbedContainer) AddTab (name string, root tomo.Object) {
|
|||||||
}
|
}
|
||||||
tab.SetRole(tomo.R("objects", "Tab"))
|
tab.SetRole(tomo.R("objects", "Tab"))
|
||||||
tab.SetText(name)
|
tab.SetText(name)
|
||||||
tab.OnButtonDown(func (catch func (), button input.Button) {
|
tab.OnButtonDown(func (button input.Button) bool {
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return false }
|
||||||
this.Activate(name)
|
this.Activate(name)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
tab.OnButtonUp(func (button input.Button) bool {
|
||||||
|
if button != input.ButtonLeft { return false }
|
||||||
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
this.tabs = append(this.tabs, tab)
|
this.tabs = append(this.tabs, tab)
|
||||||
@ -102,7 +107,7 @@ func (this *TabbedContainer) ClearTabs () {
|
|||||||
func (this *TabbedContainer) setTabRowLayout () {
|
func (this *TabbedContainer) setTabRowLayout () {
|
||||||
row := make(layouts.Row, 1 + len(this.tabs) + 1)
|
row := make(layouts.Row, 1 + len(this.tabs) + 1)
|
||||||
row[len(row) - 1] = true
|
row[len(row) - 1] = true
|
||||||
this.tabsRow.SetLayout(row)
|
this.tabsRow.SetAttr(tomo.ALayout(row))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *TabbedContainer) findTab (name string) (int, *tab) {
|
func (this *TabbedContainer) findTab (name string) (int, *tab) {
|
||||||
|
25
textinput.go
25
textinput.go
@ -21,11 +21,12 @@ func NewTextInput (text string) *TextInput {
|
|||||||
this := &TextInput { TextBox: tomo.NewTextBox() }
|
this := &TextInput { TextBox: tomo.NewTextBox() }
|
||||||
this.SetRole(tomo.R("objects", "TextInput"))
|
this.SetRole(tomo.R("objects", "TextInput"))
|
||||||
this.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
this.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
|
this.SetAttr(tomo.AOverflow(true, false))
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
this.SetSelectable(true)
|
this.SetSelectable(true)
|
||||||
this.SetOverflow(true, false)
|
|
||||||
this.OnKeyDown(this.handleKeyDown)
|
this.OnKeyDown(this.handleKeyDown)
|
||||||
|
this.OnKeyUp(this.handleKeyUp)
|
||||||
this.OnScroll(this.handleScroll)
|
this.OnScroll(this.handleScroll)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@ -53,7 +54,15 @@ func (this *TextInput) OnValueChange (callback func ()) event.Cookie {
|
|||||||
return this.on.valueChange.Connect(callback)
|
return this.on.valueChange.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *TextInput) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
// Type types a character at the current dot position.
|
||||||
|
func (this *TextInput) Type (char rune) {
|
||||||
|
dot := this.Dot()
|
||||||
|
this.text, dot = text.Type(this.text, dot, rune(char))
|
||||||
|
this.Select(dot)
|
||||||
|
this.SetText(string(this.text))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TextInput) handleKeyDown (key input.Key, numpad bool) bool {
|
||||||
dot := this.Dot()
|
dot := this.Dot()
|
||||||
modifiers := this.Window().Modifiers()
|
modifiers := this.Window().Modifiers()
|
||||||
word := modifiers.Control
|
word := modifiers.Control
|
||||||
@ -103,16 +112,14 @@ func (this *TextInput) handleKeyDown (catch func (), key input.Key, numpad bool)
|
|||||||
this.SetText(string(this.text))
|
this.SetText(string(this.text))
|
||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type types a character at the current dot position.
|
func (this *TextInput) handleKeyUp (key input.Key, numpad bool) bool {
|
||||||
func (this *TextInput) Type (char rune) {
|
return true
|
||||||
dot := this.Dot()
|
|
||||||
this.text, dot = text.Type(this.text, dot, rune(char))
|
|
||||||
this.Select(dot)
|
|
||||||
this.SetText(string(this.text))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *TextInput) handleScroll (catch func (), x, y float64) {
|
func (this *TextInput) handleScroll (x, y float64) bool {
|
||||||
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
|
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,13 @@ func NewTextView (text string) *TextView {
|
|||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
this.SetSelectable(true)
|
this.SetSelectable(true)
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
this.SetOverflow(false, true)
|
this.SetAttr(tomo.AOverflow(false, true))
|
||||||
this.SetWrap(true)
|
this.SetAttr(tomo.AWrap(true))
|
||||||
this.OnScroll(this.handleScroll)
|
this.OnScroll(this.handleScroll)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *TextView) handleScroll (catch func (), x, y float64) {
|
func (this *TextView) handleScroll (x, y float64) bool {
|
||||||
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
|
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user