diff options
-rw-r--r-- | ui/room-list.go | 7 | ||||
-rw-r--r-- | ui/view-main.go | 17 |
2 files changed, 21 insertions, 3 deletions
diff --git a/ui/room-list.go b/ui/room-list.go index 5f59136..1162ad5 100644 --- a/ui/room-list.go +++ b/ui/room-list.go @@ -83,6 +83,13 @@ func (list *RoomList) SetSelected(room *rooms.Room) { list.selected = room } +func (list *RoomList) Get(n int) *rooms.Room { + if n < 0 || n >= len(list.items) { + return nil + } + return list.items[n] +} + // Draw draws this primitive onto the screen. func (list *RoomList) Draw(screen tcell.Screen) { list.Box.Draw(screen) diff --git a/ui/view-main.go b/ui/view-main.go index 3034102..0b0708c 100644 --- a/ui/view-main.go +++ b/ui/view-main.go @@ -201,6 +201,11 @@ func (view *MainView) KeyEventHandler(roomView *RoomView, key *tcell.EventKey) * const WheelScrollOffsetDiff = 3 +func isInArea(x, y int, p tview.Primitive) bool { + rx, ry, rw, rh := p.GetRect() + return x >= rx && y >= ry && x < rx+rw && y < ry+rh +} + func (view *MainView) MouseEventHandler(roomView *RoomView, event *tcell.EventMouse) *tcell.EventMouse { if event.Buttons() == tcell.ButtonNone || event.HasMotion() { return event @@ -228,13 +233,19 @@ func (view *MainView) MouseEventHandler(roomView *RoomView, event *tcell.EventMo roomView.Room.MarkRead() } default: - mx, my, mw, mh := msgView.GetRect() - if x >= mx && y >= my && x < mx+mw && y < my+mh { + if isInArea(x, y, msgView) { + mx, my, _, _ := msgView.GetRect() if msgView.HandleClick(x-mx, y-my, event.Buttons()) { view.parent.Render() } + } else if isInArea(x, y, view.roomList) && event.Buttons() == tcell.Button1 { + _, rly, _, _ := msgView.GetRect() + n := y-rly+1 + if n >= 0 && n < len(view.roomIDs) { + view.SwitchRoom(n) + } } else { - debug.Print("Mouse event received:", event.Buttons(), event.Modifiers(), x, y) + debug.Print("Unhandled mouse event:", event.Buttons(), event.Modifiers(), x, y) } return event } |