From f6216bb6213a15cdcdf50089f3c4a8e9a30d9337 Mon Sep 17 00:00:00 2001 From: Jeffas Date: Thu, 5 Sep 2019 23:32:36 +0100 Subject: Add Mouseable This adds the Mouseable interface. When this is implemented for a component that item can accept and process mouseevents. At the top level when a mouse event is received it is passed to the grid's handler and then it trickles down until it reaches a component that can actually handle it, such as the tablist, dirlist or msglist. A mouse event is passed so that components can handle other things such as scrolling with the mousewheel. The components themselves then perform the necessary actions. Clicking emails in the messagelist opens them in a new tab. Textinputs can be clicked to position the cursor inside them. Mouseevents are not forwarded to the terminal at the moment. Elements which do not handle mouse events are not required to implement the Mouseable interface. --- lib/ui/textinput.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/ui/textinput.go') diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go index 00e91ee..3935173 100644 --- a/lib/ui/textinput.go +++ b/lib/ui/textinput.go @@ -97,6 +97,20 @@ func (ti *TextInput) Draw(ctx *Context) { } } +func (ti *TextInput) MouseEvent(localX int, localY int, event tcell.Event) { + switch event := event.(type) { + case *tcell.EventMouse: + switch event.Buttons() { + case tcell.Button1: + if localX >= len(ti.prompt)+1 && localX <= len(ti.text[ti.scroll:])+len(ti.prompt)+1 { + ti.index = localX - len(ti.prompt) - 1 + ti.ensureScroll() + ti.Invalidate() + } + } + } +} + func (ti *TextInput) Focus(focus bool) { ti.focus = focus if focus && ti.ctx != nil { -- cgit v1.2.3