widgets: add dialog interface
Implement an interface for aerc's dialog implementation. Provide dialogs the ability to set their own height and width of their drawing context. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
9cffc45f03
commit
00e908e2ae
2 changed files with 32 additions and 1 deletions
|
@ -187,9 +187,16 @@ func (aerc *Aerc) Draw(ctx *ui.Context) {
|
|||
aerc.grid.Draw(ctx)
|
||||
if aerc.dialog != nil {
|
||||
if w, h := ctx.Width(), ctx.Height(); w > 8 && h > 4 {
|
||||
if d, ok := aerc.dialog.(Dialog); ok {
|
||||
start, height := d.ContextHeight()
|
||||
aerc.dialog.Draw(
|
||||
ctx.Subcontext(4, start(h),
|
||||
w-8, height(h)))
|
||||
} else {
|
||||
aerc.dialog.Draw(ctx.Subcontext(4, h/2-2, w-8, 4))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (aerc *Aerc) getBindings() *config.KeyBindings {
|
||||
|
|
24
widgets/dialog.go
Normal file
24
widgets/dialog.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package widgets
|
||||
|
||||
import (
|
||||
"git.sr.ht/~rjarry/aerc/lib/ui"
|
||||
)
|
||||
|
||||
type Dialog interface {
|
||||
ui.DrawableInteractive
|
||||
ContextHeight() (func(int) int, func(int) int)
|
||||
}
|
||||
|
||||
type dialog struct {
|
||||
ui.DrawableInteractive
|
||||
y func(int) int
|
||||
h func(int) int
|
||||
}
|
||||
|
||||
func (d *dialog) ContextHeight() (func(int) int, func(int) int) {
|
||||
return d.y, d.h
|
||||
}
|
||||
|
||||
func NewDialog(d ui.DrawableInteractive, y func(int) int, h func(int) int) Dialog {
|
||||
return &dialog{DrawableInteractive: d, y: y, h: h}
|
||||
}
|
Loading…
Reference in a new issue