Update code for objects

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

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 {