Update code for layouts, objects

This commit is contained in:
Sasha Koshka 2024-07-21 11:48:28 -04:00
parent 9077015db6
commit 6ca6771fc6
26 changed files with 447 additions and 389 deletions

View File

@ -28,17 +28,16 @@ func NewButton (text string) *Button {
ContainerBox: tomo.NewContainerBox(), ContainerBox: tomo.NewContainerBox(),
label: NewLabel(text), label: NewLabel(text),
} }
box.SetRole(tomo.R("objects", "Button", "")) box.SetRole(tomo.R("objects", "Button"))
box.label.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle) box.label.SetAttr(tomo.AAlign(tomo.AlignMiddle, tomo.AlignMiddle))
box.SetLayout(buttonLayout) box.SetLayout(buttonLayout)
box.SetText(text) box.SetText(text)
box.CaptureDND(true) box.CatchDND(true)
box.CaptureMouse(true) box.CatchMouse(true)
box.CaptureScroll(true)
box.CaptureKeyboard(true)
box.OnMouseUp(box.handleMouseUp) box.OnButtonDown(box.handleButtonDown)
box.OnButtonUp(box.handleButtonUp)
box.OnKeyUp(box.handleKeyUp) box.OnKeyUp(box.handleKeyUp)
box.SetFocusable(true) box.SetFocusable(true)
return box return box
@ -89,14 +88,19 @@ func (this *Button) applyLayout () {
} }
} }
func (this *Button) handleKeyUp (key input.Key, numberPad bool) { func (this *Button) handleKeyUp (catch func (), key input.Key, numberPad bool) {
if key != input.KeyEnter && key != input.Key(' ') { return } if key != input.KeyEnter && key != input.Key(' ') { return }
this.on.click.Broadcast() this.on.click.Broadcast()
} }
func (this *Button) handleMouseUp (button input.Button) { func (this *Button) handleButtonDown (catch func (), button input.Button) {
catch()
}
func (this *Button) handleButtonUp (catch func (), button input.Button) {
catch()
if button != input.ButtonLeft { return } if button != input.ButtonLeft { return }
if this.MousePosition().In(this.Bounds()) { if this.Window().MousePosition().In(this.Bounds()) {
this.on.click.Broadcast() this.on.click.Broadcast()
} }
} }

View File

@ -26,7 +26,7 @@ func NewCalendar (tm time.Time) *Calendar {
ContainerBox: tomo.NewContainerBox(), ContainerBox: tomo.NewContainerBox(),
time: tm, time: tm,
} }
calendar.SetRole(tomo.R("objects", "Calendar", "")) calendar.SetRole(tomo.R("objects", "Calendar"))
calendar.SetLayout(layouts.ContractVertical) calendar.SetLayout(layouts.ContractVertical)
prevButton := NewButton("") prevButton := NewButton("")