aboutsummaryrefslogtreecommitdiff
path: root/ui/view-main.go
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-04-21 21:53:52 +0300
committerTulir Asokan <tulir@maunium.net>2018-04-21 21:53:52 +0300
commit7abfd97cda9584263d9c4e33383523f0a4efeef1 (patch)
tree1daef4585ed84b5f0f3fe68af720513c1ac91bdb /ui/view-main.go
parent7da1555c847edfc5a1d75b1ed26362901d3f9609 (diff)
Allow clicking on room list entries to switch room. Fixes #30
Diffstat (limited to 'ui/view-main.go')
-rw-r--r--ui/view-main.go17
1 files changed, 14 insertions, 3 deletions
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
}