Update code for objects

This commit is contained in:
Sasha Koshka 2024-07-25 12:58:38 -04:00
parent 25a59d888c
commit 85fbe9c996
17 changed files with 247 additions and 163 deletions

View File

@ -30,14 +30,13 @@ func NewButton (text string) *Button {
}
box.SetRole(tomo.R("objects", "Button"))
box.label.SetAttr(tomo.AAlign(tomo.AlignMiddle, tomo.AlignMiddle))
box.SetLayout(buttonLayout)
box.SetAttr(tomo.ALayout(buttonLayout))
box.SetText(text)
box.CatchDND(true)
box.CatchMouse(true)
box.SetInputMask(true)
box.OnButtonDown(box.handleButtonDown)
box.OnButtonUp(box.handleButtonUp)
box.OnKeyDown(box.handleKeyDown)
box.OnKeyUp(box.handleKeyUp)
box.SetFocusable(true)
return box
@ -80,27 +79,34 @@ func (this *Button) OnClick (callback func ()) event.Cookie {
func (this *Button) applyLayout () {
if this.labelActive && this.icon == nil {
this.SetLayout(buttonLayout)
this.SetAttr(tomo.ALayout(buttonLayout))
} else if !this.labelActive && this.icon != nil {
this.SetLayout(iconButtonLayout)
this.SetAttr(tomo.ALayout(iconButtonLayout))
} else {
this.SetLayout(bothButtonLayout)
this.SetAttr(tomo.ALayout(bothButtonLayout))
}
}
func (this *Button) handleKeyUp (catch func (), key input.Key, numberPad bool) {
if key != input.KeyEnter && key != input.Key(' ') { return }
func (this *Button) handleKeyDown (key input.Key, numberPad bool) bool {
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()
return true
}
func (this *Button) handleButtonDown (catch func (), button input.Button) {
catch()
func (this *Button) handleButtonDown (button input.Button) bool {
if button != input.ButtonLeft { return false }
return true
}
func (this *Button) handleButtonUp (catch func (), button input.Button) {
catch()
if button != input.ButtonLeft { return }
func (this *Button) handleButtonUp (button input.Button) bool {
if button != input.ButtonLeft { return false }
if this.Window().MousePosition().In(this.Bounds()) {
this.on.click.Broadcast()
}
return true
}

View File

@ -27,7 +27,7 @@ func NewCalendar (tm time.Time) *Calendar {
time: tm,
}
calendar.SetRole(tomo.R("objects", "Calendar"))
calendar.SetLayout(layouts.ContractVertical)
calendar.SetAttr(tomo.ALayout(layouts.ContractVertical))
prevButton := NewButton("")
prevButton.SetIcon(tomo.IconGoPrevious)
@ -46,8 +46,8 @@ func NewCalendar (tm time.Time) *Calendar {
calendar.grid = tomo.NewContainerBox()
calendar.grid.SetRole(tomo.R("objects", "CalendarGrid"))
calendar.grid.SetLayout(layouts.NewGrid (
true, true, true, true, true, true, true)())
calendar.grid.SetAttr(tomo.ALayout(layouts.NewGrid (
true, true, true, true, true, true, true)()))
calendar.Add(NewInnerContainer (
layouts.Row { false, true, false },
prevButton, calendar.monthLabel, nextButton))
@ -128,13 +128,13 @@ func (this *Calendar) refresh () {
}
}
func (this *Calendar) handleScroll (catch func (), x, y float64) {
catch()
func (this *Calendar) handleScroll (x, y float64) bool {
if y < 0 {
this.prevMonth()
} else {
this.nextMonth()
}
return true
}
func firstOfMonth (tm time.Time) time.Time {

View File

@ -23,6 +23,7 @@ func NewCheckbox (value bool) *Checkbox {
box.OnButtonDown(box.handleButtonDown)
box.OnButtonUp(box.handleButtonUp)
box.OnKeyDown(box.handleKeyDown)
box.OnKeyUp(box.handleKeyUp)
box.SetFocusable(true)
return box
@ -52,19 +53,26 @@ func (this *Checkbox) OnValueChange (callback func ()) event.Cookie {
return this.on.valueChange.Connect(callback)
}
func (this *Checkbox) handleKeyUp (catch func (), key input.Key, numberPad bool) {
if key != input.KeyEnter && key != input.Key(' ') { return }
func (this *Checkbox) handleKeyDown (key input.Key, numberPad bool) bool {
if key != input.KeyEnter && key != input.Key(' ') { return false }
this.Toggle()
return true
}
func (this *Checkbox) handleButtonDown (catch func (), button input.Button) {
catch()
func (this *Checkbox) handleKeyUp (key input.Key, numberPad bool) bool {
if key != input.KeyEnter && key != input.Key(' ') { return false}
return true
}
func (this *Checkbox) handleButtonUp (catch func (), button input.Button) {
catch()
if button != input.ButtonLeft { return }
func (this *Checkbox) handleButtonDown (button input.Button) bool {
if button != input.ButtonLeft { return false }
return true
}
func (this *Checkbox) handleButtonUp (button input.Button) bool {
if button != input.ButtonLeft { return false }
if this.Window().MousePosition().In(this.Bounds()) {
this.Toggle()
}
return true
}

View File

@ -29,7 +29,7 @@ func NewColorPicker (value color.Color) *ColorPicker {
ContainerBox: tomo.NewContainerBox(),
}
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.Add(picker.pickerMap)
@ -97,20 +97,23 @@ func newColorPickerMap (parent *ColorPicker) *colorPickerMap {
return picker
}
func (this *colorPickerMap) handleButtonDown (catch func (), button input.Button) {
if button != input.ButtonLeft { return }
func (this *colorPickerMap) handleButtonDown (button input.Button) bool {
if button != input.ButtonLeft { return false }
this.dragging = true
this.drag()
return true
}
func (this *colorPickerMap) handleButtonUp (catch func (), button input.Button) {
if button != input.ButtonLeft || !this.dragging { return }
func (this *colorPickerMap) handleButtonUp (button input.Button) bool {
if button != input.ButtonLeft { return false }
this.dragging = false
return true
}
func (this *colorPickerMap) handleMouseMove () {
if !this.dragging { return }
func (this *colorPickerMap) handleMouseMove () bool {
if !this.dragging { return false }
this.drag()
return true
}
func (this *colorPickerMap) drag () {

View File

@ -15,7 +15,7 @@ func newContainer (layout tomo.Layout, children ...tomo.Object) *Container {
this := &Container {
ContainerBox: tomo.NewContainerBox(),
}
this.SetLayout(layout)
this.SetAttr(tomo.ALayout(layout))
for _, child := range children {
this.Add(child)
}

View File

@ -24,7 +24,7 @@ func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
box.Add(box.checkbox)
box.Add(box.label)
box.SetLayout(layouts.Row { false, true })
box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
box.OnButtonDown(box.handleButtonDown)
box.OnButtonUp(box.handleButtonUp)
@ -52,15 +52,16 @@ func (this *LabelCheckbox) OnValueChange (callback func ()) event.Cookie {
return this.checkbox.OnValueChange(callback)
}
func (this *LabelCheckbox) handleButtonDown (capture func (), button input.Button) {
capture()
func (this *LabelCheckbox) handleButtonDown (button input.Button) bool {
if button != input.ButtonLeft { return false }
return true
}
func (this *LabelCheckbox) handleButtonUp (capture func (), button input.Button) {
capture()
if button != input.ButtonLeft { return }
func (this *LabelCheckbox) handleButtonUp (button input.Button) bool {
if button != input.ButtonLeft { return false }
if this.Window().MousePosition().In(this.Bounds()) {
this.checkbox.SetFocused(true)
this.checkbox.Toggle()
}
return true
}

View File

@ -26,7 +26,7 @@ func NewLabelSwatch (value color.Color, text string) *LabelSwatch {
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
box.Add(box.swatch)
box.Add(box.label)
box.SetLayout(layouts.Row { false, true })
box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
box.OnButtonDown(box.handleButtonDown)
box.OnButtonUp(box.handleButtonUp)
@ -60,15 +60,16 @@ func (this *LabelSwatch) OnConfirm (callback func ()) event.Cookie {
return this.swatch.OnConfirm(callback)
}
func (this *LabelSwatch) handleButtonDown (catch func (), button input.Button) {
catch()
func (this *LabelSwatch) handleButtonDown (button input.Button) bool {
if button != input.ButtonLeft { return true }
return true
}
func (this *LabelSwatch) handleButtonUp (catch func (), button input.Button) {
catch()
if button != input.ButtonLeft { return }
func (this *LabelSwatch) handleButtonUp (button input.Button) bool {
if button != input.ButtonLeft { return true }
if this.Window().MousePosition().In(this.Bounds()) {
this.swatch.SetFocused(true)
this.swatch.Choose()
}
return true
}

45
menu.go
View File

@ -13,7 +13,7 @@ type Menu struct {
parent tomo.Window
bounds image.Rectangle
rootContainer tomo.ContainerBox
tearLine tomo.Box
tearLine tomo.Object
torn bool
}
@ -36,22 +36,10 @@ func NewMenu (anchor tomo.Object, items ...tomo.Object) (*Menu, error) {
}
menu.rootContainer = tomo.NewContainerBox()
menu.rootContainer.SetLayout(layouts.ContractVertical)
menu.rootContainer.SetAttr(tomo.ALayout(layouts.ContractVertical))
if !menu.torn {
menu.tearLine = tomo.NewBox()
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.tearLine = menu.newTearLine()
menu.rootContainer.Add(menu.tearLine)
}
@ -92,6 +80,33 @@ func (this *Menu) TearOff () {
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 {
bounds := anchor.GetBox().Bounds()
return image.Rect (

View File

@ -27,16 +27,15 @@ func NewMenuItem (text string) *MenuItem {
}
box.SetRole(tomo.R("objects", "MenuItem"))
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.label)
box.CatchDND(true)
box.CatchMouse(true)
box.SetInputMask(true)
box.OnButtonDown(box.handleButtonDown)
box.OnButtonUp(box.handleButtonUp)
box.OnKeyDown(box.handleKeyDown)
box.OnKeyUp(box.handleKeyUp)
box.SetFocusable(true)
return box
@ -59,19 +58,26 @@ func (this *MenuItem) OnClick (callback func ()) event.Cookie {
return this.on.click.Connect(callback)
}
func (this *MenuItem) handleKeyUp (catch func(), key input.Key, numberPad bool) {
if key != input.KeyEnter && key != input.Key(' ') { return }
func (this *MenuItem) handleKeyDown (key input.Key, numberPad bool) bool {
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()
return true
}
func (this *MenuItem) handleButtonDown (catch func(), button input.Button) {
catch()
func (this *MenuItem) handleButtonDown (button input.Button) bool {
if button != input.ButtonLeft { return false }
return true
}
func (this *MenuItem) handleButtonUp (catch func(), button input.Button) {
catch()
if button != input.ButtonLeft { return }
func (this *MenuItem) handleButtonUp (button input.Button) bool {
if button != input.ButtonLeft { return false }
if this.Window().MousePosition().In(this.Bounds()) {
this.on.click.Broadcast()
}
return true
}

View File

@ -32,15 +32,15 @@ func NewNumberInput (value float64) *NumberInput {
box.Add(box.input)
box.Add(box.decrement)
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.decrement.SetIcon(tomo.IconValueDecrement)
box.SetValue(value)
box.OnScroll(box.handleScroll)
box.OnKeyUp(box.handleKeyUp)
box.OnKeyDown(box.handleKeyDown)
box.OnKeyUp(box.handleKeyUp)
box.input.OnConfirm(box.handleConfirm)
box.input.OnValueChange(box.on.valueChange.Broadcast)
box.increment.OnClick(func () { box.shift(1) })
@ -76,29 +76,32 @@ func (this *NumberInput) shift (by int) {
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 {
case input.KeyUp:
this.shift(1)
catch()
return true
case input.KeyDown:
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 {
case input.KeyUp: catch()
case input.KeyDown: catch()
case input.KeyUp: return true
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 {
catch()
this.shift(-int(math.Round(y)))
return true
}
return false
}
func (this *NumberInput) handleConfirm () {

View File

@ -33,11 +33,9 @@ func newScrollbar (orient string) *Scrollbar {
}
this.Add(this.handle)
this.SetFocusable(true)
this.CatchDND(true)
this.CatchMouse(true)
this.SetInputMask(true)
this.OnKeyUp(this.handleKeyUp)
this.OnKeyDown(this.handleKeyDown)
this.OnButtonDown(this.handleButtonDown)
@ -68,7 +66,7 @@ func (this *Scrollbar) Link (box tomo.ContentObject) event.Cookie {
this.layout.linked = box
this.linkCookie = this.newLinkCookie (
box.OnContentBoundsChange(this.handleLinkedContentBoundsChange))
this.SetLayout(this.layout)
this.SetAttr(tomo.ALayout(this.layout))
return this.linkCookie
}
@ -81,7 +79,7 @@ func (this *Scrollbar) handleLinkedContentBoundsChange () {
} else {
this.layout.value = this.layout.contentPos() / trackLength
}
this.SetLayout(this.layout)
this.SetAttr(tomo.ALayout(this.layout))
if this.layout.value != previousValue {
this.on.valueChange.Broadcast()
}
@ -139,13 +137,17 @@ func (this *Scrollbar) StepSize () int {
return 16
}
func (this *Scrollbar) handleKeyUp (catch func (), key input.Key, numpad bool) {
catch()
func (this *Scrollbar) handleKeyUp (key input.Key, numpad bool) bool {
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) {
catch()
func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) bool {
var increment float64; if this.layout.vertical {
increment = -0.05
} else {
@ -161,22 +163,25 @@ func (this *Scrollbar) handleKeyDown (catch func (), key input.Key, numpad bool)
} else {
this.SetValue(this.Value() - increment)
}
return true
case input.KeyDown, input.KeyRight:
if modifiers.Alt {
this.SetValue(1)
} else {
this.SetValue(this.Value() + increment)
}
return true
case input.KeyHome:
this.SetValue(0)
return true
case input.KeyEnd:
this.SetValue(1)
return true
}
return false
}
func (this *Scrollbar) handleButtonDown (catch func (), button input.Button) {
catch()
func (this *Scrollbar) handleButtonDown (button input.Button) bool {
pointer := this.Window().MousePosition()
handle := this.handle.Bounds()
@ -213,25 +218,26 @@ func (this *Scrollbar) handleButtonDown (catch func (), button input.Button) {
this.scrollBy(-this.StepSize())
}
}
return true
}
func (this *Scrollbar) handleButtonUp (catch func (), button input.Button) {
catch()
if button != input.ButtonLeft || !this.dragging { return }
func (this *Scrollbar) handleButtonUp (button input.Button) bool {
if button != input.ButtonLeft || !this.dragging { return true }
this.dragging = false
return true
}
func (this *Scrollbar) handleMouseMove () {
if !this.dragging { return }
this.drag()
func (this *Scrollbar) handleMouseMove () bool {
if !this.dragging { return false }
return true
}
func (this *Scrollbar) handleScroll (catch func(), x, y float64) {
catch()
if this.layout.linked == nil { return }
func (this *Scrollbar) handleScroll (x, y float64) bool {
if this.layout.linked == nil { return false }
this.layout.linked.ScrollTo (
this.layout.linked.ContentBounds().Min.
Sub(image.Pt(int(x), int(y))))
return true
}
func (this *Scrollbar) drag () {
@ -289,7 +295,7 @@ func (this *scrollbarCookie) Close () {
cookie.Close()
}
this.owner.layout.linked = nil
this.owner.SetLayout(this.owner.layout)
this.owner.SetAttr(tomo.ALayout(this.owner.layout))
}
type scrollbarLayout struct {

View File

@ -73,7 +73,7 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
this.OnKeyUp(this.handleKeyUp)
this.SetRole(tomo.R("objects", "ScrollContainer"))
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
}
@ -172,46 +172,46 @@ func (this *ScrollContainer) handleValueChange () {
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) {
if this.root == nil { return }
if this.root == nil { return }
if vector == (image.Point { }) { return }
this.root.ScrollTo (
this.root.ContentBounds().Min.
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()
vector := image.Point { }
switch key {
case input.KeyPageUp:
catch()
if modifiers.Shift {
vector.X -= this.PageSize().X
} else {
vector.Y -= this.PageSize().Y
}
return true
case input.KeyPageDown:
catch()
if modifiers.Shift {
vector.X += this.PageSize().X
} else {
vector.Y += this.PageSize().Y
}
return true
}
if vector != (image.Point { }) {
this.scrollBy(vector)
}
return false
}
func (this *ScrollContainer) handleKeyUp (catch func (), key input.Key, numpad bool) {
func (this *ScrollContainer) handleKeyUp (key input.Key, numpad bool) bool {
switch key {
case input.KeyPageUp: catch()
case input.KeyPageDown: catch()
case input.KeyPageUp: return true
case input.KeyPageDown: return true
}
return false
}

View File

@ -42,11 +42,9 @@ func newSlider (orient string, value float64) *Slider {
this.Add(this.handle)
this.SetFocusable(true)
this.CatchDND(true)
this.CatchMouse(true)
this.SetValue(value)
this.SetInputMask(true)
this.OnKeyUp(this.handleKeyUp)
this.OnKeyDown(this.handleKeyDown)
this.OnButtonDown(this.handleButtonDown)
@ -77,7 +75,7 @@ func (this *Slider) SetValue (value float64) {
if value > 1 { value = 1 }
if value == this.layout.value { return }
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.
@ -97,9 +95,7 @@ func (this *Slider) OnConfirm (callback func ()) event.Cookie {
return this.on.confirm.Connect(callback)
}
func (this *Slider) handleKeyDown (catch func (), key input.Key, numpad bool) {
catch()
func (this *Slider) handleKeyDown (key input.Key, numpad bool) bool {
var increment float64; if this.layout.vertical {
increment = -0.05
} else {
@ -114,6 +110,7 @@ func (this *Slider) handleKeyDown (catch func (), key input.Key, numpad bool) {
this.SetValue(this.Value() - increment)
}
this.on.valueChange.Broadcast()
return true
case input.KeyDown, input.KeyRight:
if this.Window().Modifiers().Alt {
this.SetValue(1)
@ -121,22 +118,30 @@ func (this *Slider) handleKeyDown (catch func (), key input.Key, numpad bool) {
this.SetValue(this.Value() + increment)
}
this.on.valueChange.Broadcast()
return true
case input.KeyHome:
this.SetValue(0)
this.on.valueChange.Broadcast()
return true
case input.KeyEnd:
this.SetValue(1)
this.on.valueChange.Broadcast()
return true
}
return false
}
func (this *Slider) handleKeyUp (catch func (), key input.Key, numpad bool) {
catch()
func (this *Slider) handleKeyUp (key input.Key, numpad bool) bool {
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) {
catch()
func (this *Slider) handleButtonDown (button input.Button) bool {
pointer := this.Window().MousePosition()
handle := this.handle.Bounds()
@ -181,25 +186,28 @@ func (this *Slider) handleButtonDown (catch func (), button input.Button) {
this.on.confirm.Broadcast()
}
}
return true
}
func (this *Slider) handleButtonUp (catch func (), button input.Button) {
catch()
if button != input.ButtonLeft || !this.dragging { return }
func (this *Slider) handleButtonUp (button input.Button) bool {
if button != input.ButtonLeft || !this.dragging { return true }
this.dragging = false
this.on.confirm.Broadcast()
return true
}
func (this *Slider) handleMouseMove () {
if !this.dragging { return }
func (this *Slider) handleMouseMove () bool {
if !this.dragging { return false }
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
this.SetValue(this.Value() + delta)
this.on.valueChange.Broadcast()
this.on.confirm.Broadcast()
return true
}
func (this *Slider) drag () {

View File

@ -30,7 +30,9 @@ func NewSwatch (value color.Color) *Swatch {
swatch.SetDrawer(swatch)
swatch.SetValue(value)
swatch.OnButtonDown(swatch.handleButtonDown)
swatch.OnButtonUp(swatch.handleButtonUp)
swatch.OnKeyDown(swatch.handleKeyDown)
swatch.OnKeyUp(swatch.handleKeyUp)
swatch.SetFocusable(true)
return swatch
@ -155,14 +157,26 @@ func (this *Swatch) userSetValue (value color.Color) {
this.on.valueChange.Broadcast()
}
func (this *Swatch) handleKeyUp (catch func (), key input.Key, numberPad bool) {
if key != input.KeyEnter && key != input.Key(' ') { return }
this.Choose()
func (this *Swatch) handleKeyDown (key input.Key, numberPad bool) bool {
if key != input.KeyEnter && key != input.Key(' ') { return false }
return true
}
func (this *Swatch) handleButtonUp (catch func (), button input.Button) {
if button != input.ButtonLeft { return }
func (this *Swatch) handleKeyUp (key input.Key, numberPad bool) bool {
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()) {
this.Choose()
}
return true
}

View File

@ -19,7 +19,7 @@ func NewTabbedContainer () *TabbedContainer {
ContainerBox: tomo.NewContainerBox(),
}
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.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.SetText(name)
tab.OnButtonDown(func (catch func (), button input.Button) {
if button != input.ButtonLeft { return }
tab.OnButtonDown(func (button input.Button) bool {
if button != input.ButtonLeft { return false }
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)
@ -102,7 +107,7 @@ func (this *TabbedContainer) ClearTabs () {
func (this *TabbedContainer) setTabRowLayout () {
row := make(layouts.Row, 1 + len(this.tabs) + 1)
row[len(row) - 1] = true
this.tabsRow.SetLayout(row)
this.tabsRow.SetAttr(tomo.ALayout(row))
}
func (this *TabbedContainer) findTab (name string) (int, *tab) {

View File

@ -21,11 +21,12 @@ func NewTextInput (text string) *TextInput {
this := &TextInput { TextBox: tomo.NewTextBox() }
this.SetRole(tomo.R("objects", "TextInput"))
this.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
this.SetAttr(tomo.AOverflow(true, false))
this.SetText(text)
this.SetFocusable(true)
this.SetSelectable(true)
this.SetOverflow(true, false)
this.OnKeyDown(this.handleKeyDown)
this.OnKeyUp(this.handleKeyUp)
this.OnScroll(this.handleScroll)
return this
}
@ -53,7 +54,15 @@ func (this *TextInput) OnValueChange (callback func ()) event.Cookie {
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()
modifiers := this.Window().Modifiers()
word := modifiers.Control
@ -103,16 +112,14 @@ func (this *TextInput) handleKeyDown (catch func (), key input.Key, numpad bool)
this.SetText(string(this.text))
this.on.valueChange.Broadcast()
}
return true
}
// 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) handleKeyUp (key input.Key, numpad bool) bool {
return true
}
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))))
return true
}

View File

@ -15,12 +15,13 @@ func NewTextView (text string) *TextView {
this.SetFocusable(true)
this.SetSelectable(true)
this.SetText(text)
this.SetOverflow(false, true)
this.SetWrap(true)
this.SetAttr(tomo.AOverflow(false, true))
this.SetAttr(tomo.AWrap(true))
this.OnScroll(this.handleScroll)
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))))
return true
}