Hierarchy is now responsible for focusing boxes when they are clicked

This commit is contained in:
Sasha Koshka 2024-07-26 17:34:14 -04:00
parent a92951f891
commit 180a5eb8d1
2 changed files with 9 additions and 7 deletions

View File

@ -336,13 +336,6 @@ func (this *box) handleMouseDown (button input.Button) (caught bool) {
this.invalidateStyle()
}
if this.focusable {
this.SetFocused(true)
} else {
hierarchy := this.getHierarchy()
if hierarchy == nil { return }
hierarchy.focus(nil)
}
for _, listener := range this.on.buttonDown.Listeners() {
if listener(button) { caught = true }
}

View File

@ -62,7 +62,16 @@ func (this *Hierarchy) HandleKeyUp (key input.Key, numberPad bool) {
// information, HandleMouseMove must be called *before* HandleMouseDown.
func (this *Hierarchy) HandleMouseDown (button input.Button) {
boxes := []anyBox { }
first := true
this.boxesUnder(this.mousePosition)(func (box anyBox) bool {
if first {
if box.canBeFocused() {
this.focus(box)
} else {
this.focus(nil)
}
first = false
}
boxes = append(boxes, box)
return !box.handleMouseDown(button)
})