Add Focus to Widget interface

This commit is contained in:
Trevor Slocum 2023-10-28 22:23:18 -07:00
parent 4833fa2b27
commit 6e8eb92a2c
4 changed files with 14 additions and 12 deletions

11
box.go
View file

@ -51,19 +51,20 @@ func (b *Box) SetBackground(background color.RGBA) {
b.background = background
}
func (b *Box) Focus() bool {
return false
}
func (b *Box) SetFocus(focus bool) bool {
return false
}
func (b *Box) SetVisible(visible bool) {
b.visible = visible
}
func (b *Box) Visible() bool {
return b.visible
}
func (b *Box) Focus() bool {
return false
func (b *Box) SetVisible(visible bool) {
b.visible = visible
}
func (b *Box) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error) {

View file

@ -58,6 +58,10 @@ func (i *Input) SetRect(r image.Rectangle) {
i.Field.SetRect(r)
}
func (i *Input) Focus() bool {
return i.focus
}
func (i *Input) SetFocus(focus bool) bool {
i.focus = focus
@ -69,10 +73,6 @@ func (i *Input) SetFocus(focus bool) bool {
return true
}
func (i *Input) Focused() bool {
return i.focus
}
func (i *Input) HandleKeyboard(key ebiten.Key, r rune) (handled bool, err error) {
if !i.focus {
return false, nil

View file

@ -44,11 +44,11 @@ func (t *Text) SetBackground(background color.RGBA) {
t.background = background
}
func (t *Text) SetFocus(focus bool) bool {
func (t *Text) Focus() bool {
return false
}
func (t *Text) Focus() bool {
func (t *Text) SetFocus(focus bool) bool {
return false
}

View file

@ -12,9 +12,10 @@ type Widget interface {
SetRect(r image.Rectangle)
Background() color.RGBA
SetBackground(background color.RGBA)
Focus() bool
SetFocus(focus bool) (accept bool)
SetVisible(visible bool)
Visible() bool
SetVisible(visible bool)
HandleKeyboard(ebiten.Key, rune) (handled bool, err error)
HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)
Draw(screen *ebiten.Image) error