Added a toggle button and lamp pattern

This commit is contained in:
Sasha Koshka
2023-04-20 18:40:05 -04:00
parent e5619ebf07
commit 2bd7d0fad5
8 changed files with 308 additions and 4 deletions

View File

@@ -79,6 +79,20 @@ func (entity *entity) propagate (callback func (*entity) bool) bool {
return callback(entity)
}
func (entity *entity) propagateAlt (callback func (*entity) bool) bool {
if !callback(entity) {
return false
}
for _, child := range entity.children {
if !child.propagate(callback) {
return false
}
}
return true
}
func (entity *entity) childAt (point image.Point) *entity {
for _, child := range entity.children {
if point.In(child.bounds) {

View File

@@ -76,7 +76,7 @@ func (system *system) focus (entity *entity) {
func (system *system) focusNext () {
found := system.focused == nil
focused := false
system.propagate (func (entity *entity) bool {
system.propagateAlt (func (entity *entity) bool {
if found {
// looking for the next element to select
child, ok := entity.element.(tomo.Focusable)
@@ -118,6 +118,11 @@ func (system *system) propagate (callback func (*entity) bool) {
system.child.propagate(callback)
}
func (system *system) propagateAlt (callback func (*entity) bool) {
if system.child == nil { return }
system.child.propagateAlt(callback)
}
func (system *system) childAt (point image.Point) *entity {
if system.child == nil { return nil }
return system.child.childAt(point)