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. --- widgets/compose.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'widgets/compose.go') diff --git a/widgets/compose.go b/widgets/compose.go index bd4301a..0e7f09e 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -40,10 +40,12 @@ type Composer struct { worker *types.Worker layout HeaderLayout - focusable []ui.DrawableInteractive + focusable []ui.MouseableDrawableInteractive focused int onClose []func(ti *Composer) + + width int } func NewComposer(conf *config.AercConfig, @@ -87,10 +89,10 @@ func NewComposer(conf *config.AercConfig, func buildComposeHeader(layout HeaderLayout, defaults map[string]string) ( newLayout HeaderLayout, editors map[string]*headerEditor, - focusable []ui.DrawableInteractive, + focusable []ui.MouseableDrawableInteractive, ) { editors = make(map[string]*headerEditor) - focusable = make([]ui.DrawableInteractive, 0) + focusable = make([]ui.MouseableDrawableInteractive, 0) for _, row := range layout { for _, h := range row { @@ -99,7 +101,7 @@ func buildComposeHeader(layout HeaderLayout, defaults map[string]string) ( switch h { case "From": // Prepend From to support backtab - focusable = append([]ui.DrawableInteractive{e}, focusable...) + focusable = append([]ui.MouseableDrawableInteractive{e}, focusable...) default: focusable = append(focusable, e) } @@ -176,6 +178,7 @@ func (c *Composer) OnClose(fn func(composer *Composer)) { } func (c *Composer) Draw(ctx *ui.Context) { + c.width = ctx.Width() c.grid.Draw(ctx) } @@ -617,6 +620,16 @@ func (he *headerEditor) Draw(ctx *ui.Context) { he.input.Draw(ctx.Subcontext(size, 0, ctx.Width()-size, 1)) } +func (he *headerEditor) MouseEvent(localX int, localY int, event tcell.Event) { + switch event := event.(type) { + case *tcell.EventMouse: + width := runewidth.StringWidth(he.name + " ") + if localX >= width { + he.input.MouseEvent(localX-width, localY, event) + } + } +} + func (he *headerEditor) Invalidate() { he.input.Invalidate() } -- cgit v1.2.3