From 00e908e2ae1b851ef1b88f351bf0551bdd76c6fe Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Mon, 8 Aug 2022 22:04:02 +0200 Subject: [PATCH] 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 Acked-by: Robin Jarry --- widgets/aerc.go | 9 ++++++++- widgets/dialog.go | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 widgets/dialog.go diff --git a/widgets/aerc.go b/widgets/aerc.go index 2383973..1e2a4cd 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -187,7 +187,14 @@ 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 { - aerc.dialog.Draw(ctx.Subcontext(4, h/2-2, w-8, 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)) + } } } } diff --git a/widgets/dialog.go b/widgets/dialog.go new file mode 100644 index 0000000..1af4456 --- /dev/null +++ b/widgets/dialog.go @@ -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} +}