diff options
author | Jeffas <dev@jeffas.io> | 2019-09-05 23:32:36 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-09-11 11:41:34 -0400 |
commit | f6216bb6213a15cdcdf50089f3c4a8e9a30d9337 (patch) | |
tree | 3075b68379ae7c13cb9eedc53b7cf033672478a9 /widgets/compose.go | |
parent | a441e3b3a55d11e7cc9444298051ff339d1b7519 (diff) |
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.
Diffstat (limited to 'widgets/compose.go')
-rw-r--r-- | widgets/compose.go | 21 |
1 files changed, 17 insertions, 4 deletions
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() } |