Add logic for focusing

This commit is contained in:
Sasha Koshka 2023-07-16 00:54:25 -04:00
parent 4259e8f021
commit 17d7035200
3 changed files with 32 additions and 12 deletions

8
box.go
View File

@ -294,6 +294,14 @@ func (this *box) boxUnder (point image.Point) anyBox {
}
}
func (this *box) handleFocusEnter () {
this.on.focusEnter.Broadcast()
}
func (this *box) handleFocusLeave () {
this.on.focusLeave.Broadcast()
}
func (this *box) handleMouseDown (button input.Button) {
for _, listener := range this.on.mouseDown.Listeners() {
listener(button)

View File

@ -48,8 +48,19 @@ type anyBox interface {
boxUnder (image.Point) anyBox
recalculateMinimumSize ()
handleMouseDown (input.Button)
handleMouseUp (input.Button)
handleFocusEnter ()
handleFocusLeave ()
// handleDndEnter ()
// handleDndLeave ()
// handleDndDrop (data.Data)
// handleMouseEnter ()
// handleMouseLeave ()
// handleMouseMove ()
handleMouseDown (input.Button)
handleMouseUp (input.Button)
// handleScroll (float64, float64)
// handleKeyDown (input.Key, bool)
// handleKeyUp (input.Key, bool)
}
func assertAnyBox (unknown tomo.Box) anyBox {
@ -100,9 +111,18 @@ func (window *window) invalidateLayout (box anyBox) {
func (window *window) focus (box anyBox) {
if window.focused == box { return }
window.invalidateDraw(window.focused)
previous := window.focused
window.focused = box
window.invalidateDraw(box)
if previous != nil {
window.invalidateDraw(previous)
previous.handleFocusLeave()
}
if box != nil {
window.invalidateDraw(box)
box.handleFocusEnter()
}
}
func (this *window) boxUnder (point image.Point) anyBox {

View File

@ -149,14 +149,6 @@ func (this *textBox) doLayout () {
innerBounds := this.InnerBounds()
this.drawer.SetMaxWidth(innerBounds.Dx())
this.drawer.SetMaxHeight(innerBounds.Dy())
// if this.hOverflow && !this.wrap {
// this.drawer.SetMaxWidth(0)
// } else {
// }
// if this.vOverflow {
// this.drawer.SetMaxHeight(0)
// } else {
// }
this.contentBounds = this.normalizedLayoutBoundsSpace().Sub(this.scroll)