use own event handler for layout views if set

This commit is contained in:
milarin 2023-04-24 14:49:22 +02:00
parent 66605df473
commit 8a0bf8f515
4 changed files with 20 additions and 0 deletions

View File

@ -138,6 +138,10 @@ func (g *BorderLayout) Layout() (prefWidth, prefHeight int) {
}
func (g *BorderLayout) OnKeyPressed(event *tui.KeyEvent) (consumed bool) {
if g.KeyPressed != nil {
return g.KeyPressed(event)
}
for _, view := range g.Views() {
if consumed := view.OnKeyPressed(event); consumed {
return true
@ -147,6 +151,10 @@ func (g *BorderLayout) OnKeyPressed(event *tui.KeyEvent) (consumed bool) {
}
func (g *BorderLayout) OnMouseEvent(event *tui.MouseEvent) (consumed bool) {
if g.MouseEvent != nil {
return g.MouseEvent(event)
}
for slot, dim := range g.viewDims {
if event.Position.In(dim) {
g.views[slot].OnMouseEvent(event)

View File

@ -41,6 +41,10 @@ func (v *CoordLayout) Layout() (prefWidth, prefHeight int) {
}
func (g *CoordLayout) OnKeyPressed(event *tui.KeyEvent) (consumed bool) {
if g.KeyPressed != nil {
return g.KeyPressed(event)
}
for _, view := range g.Views() {
if view.OnKeyPressed(event) {
return true

View File

@ -141,6 +141,10 @@ func (g *FlowLayout) Layout() (prefWidth, prefHeight int) {
}
func (g *FlowLayout) OnKeyPressed(event *tui.KeyEvent) (consumed bool) {
if g.KeyPressed != nil {
return g.KeyPressed(event)
}
for _, view := range g.Views() {
if view.OnKeyPressed(event) {
return true

View File

@ -102,6 +102,10 @@ func (g *SeperatorLayout) Layout() (prefWidth, prefHeight int) {
}
func (g *SeperatorLayout) OnKeyPressed(event *tui.KeyEvent) (consumed bool) {
if g.KeyPressed != nil {
return g.KeyPressed(event)
}
for _, view := range g.Views() {
if view.OnKeyPressed(event) {
return true