diff options
Diffstat (limited to 'tui')
| -rw-r--r-- | tui/layout.go | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/tui/layout.go b/tui/layout.go index 039ce52..f8ea4bc 100644 --- a/tui/layout.go +++ b/tui/layout.go @@ -361,7 +361,8 @@ func (b *Box) computePositions(axis int) { } } -func (b *Box) drawComputed(parentRect rect, parentStyle Style) { +func (b *Box) drawComputed( + parentRect rect, parentStyle Style, mouse MouseEvent) { var viewRect rect = parentRect; for i := 0; i < 2; i++ { bMin := b.computedRect.min[i] + b.Margins[i * 2] @@ -424,19 +425,20 @@ func (b *Box) drawComputed(parentRect rect, parentStyle Style) { } } for _, c := range b.children { - c.drawComputed(viewRect, style) + c.drawComputed(viewRect, style, mouse) } + b.mouseEvents(viewRect, mouse) } -func (b *Box) mouseEvents(ev MouseEvent) { +func (b *Box) mouseEvents(viewRect rect, ev MouseEvent) { bev := ev bev.X -= b.computedRect.min[0] bev.Y -= b.computedRect.min[1] bev.Pressed = false bev.Released = false bev.Scroll = 0 - if bev.X >= 0 && bev.Y >= 0 && - bev.X < b.computedSize[0] && bev.Y < b.computedSize[1] { + if ev.X >= viewRect.min[0] && ev.Y >= viewRect.min[1] && + ev.X < viewRect.max[0] && ev.Y < viewRect.max[1] { bev.Pressed = ev.Pressed bev.Released = ev.Released bev.Scroll = ev.Scroll @@ -445,9 +447,6 @@ func (b *Box) mouseEvents(ev MouseEvent) { } } b.mouseEvent = bev - for _, c := range b.children { - c.mouseEvents(ev) - } } func DrawLayout() { @@ -471,17 +470,19 @@ func DrawLayout() { size := Size() parentRect.max = [2]int {size.Width, size.Height} b.computedRect = parentRect - b.drawComputed(parentRect, DefaultStyle) ev := getLastEvent() + var mouse MouseEvent if menuState.open { processContextMenu(ev.Mouse) var releaseEvent MouseEvent releaseEvent.Button = ev.Mouse.Button releaseEvent.ReleasedAnywhere = ev.Mouse.ReleasedAnywhere - b.mouseEvents(releaseEvent) + mouse = releaseEvent } else { - b.mouseEvents(ev.Mouse) + mouse = ev.Mouse } + + b.drawComputed(parentRect, DefaultStyle, mouse) drawContextMenu() } |
