diff options
author | Koni Marti <koni.marti@gmail.com> | 2024-01-28 02:08:26 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-01-29 22:46:08 +0100 |
commit | 5719041eb9b846c7d056952e9e14295c65a8b81a (patch) | |
tree | bb8972453befd91fdb7b615456c74509ef82868c | |
parent | 37b05d7e73b11610f2979abdbe821366e55ee651 (diff) | |
download | aerc-5719041eb9b846c7d056952e9e14295c65a8b81a.tar.gz |
app: define two dialog constructors
Define two new constructor functions for the popup dialog.
DefaultDialog() creates a dialog that spans half of the screen, whereas
the LargeDialog() covers three-quarter of the screen.
If a dialog widget has more specific size requirements, custom window
position and window height functions can be used with NewDialog().
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r-- | app/dialog.go | 28 | ||||
-rw-r--r-- | commands/compose/attach.go | 10 | ||||
-rw-r--r-- | commands/help.go | 4 | ||||
-rw-r--r-- | commands/menu.go | 10 | ||||
-rw-r--r-- | commands/patch/list.go | 10 | ||||
-rw-r--r-- | commands/patch/rebase.go | 10 |
6 files changed, 33 insertions, 39 deletions
diff --git a/app/dialog.go b/app/dialog.go index 8ec6405a..3ed8b469 100644 --- a/app/dialog.go +++ b/app/dialog.go @@ -22,3 +22,31 @@ func (d *dialog) ContextHeight() (func(int) int, func(int) int) { func NewDialog(d ui.DrawableInteractive, y func(int) int, h func(int) int) Dialog { return &dialog{DrawableInteractive: d, y: y, h: h} } + +// DefaultDialog creates a dialog window spanning half of the screen +func DefaultDialog(d ui.DrawableInteractive) Dialog { + return NewDialog(d, + // vertical starting position in lines from the top + func(h int) int { + return h / 4 + }, + // dialog height from the starting line + func(h int) int { + return h / 2 + }, + ) +} + +// LargeDialog creates a dialog window spanning three quarter of the screen +func LargeDialog(d ui.DrawableInteractive) Dialog { + return NewDialog(d, + // vertical starting position in lines from the top + func(h int) int { + return h / 8 + }, + // dialog height from the starting line + func(h int) int { + return 3 * h / 4 + }, + ) +} diff --git a/commands/compose/attach.go b/commands/compose/attach.go index cb59eb5f..fa9590c9 100644 --- a/commands/compose/attach.go +++ b/commands/compose/attach.go @@ -177,16 +177,8 @@ func (a Attach) openMenu() error { } } - app.AddDialog(app.NewDialog( + app.AddDialog(app.LargeDialog( ui.NewBox(t, "File Picker", "", app.SelectedAccountUiConfig()), - // start pos on screen - func(h int) int { - return h / 8 - }, - // dialog height - func(h int) int { - return h - 2*h/8 - }, )) return nil diff --git a/commands/help.go b/commands/help.go index 3d71e5b3..079b2fd5 100644 --- a/commands/help.go +++ b/commands/help.go @@ -59,7 +59,7 @@ func (h *Help) ParseTopic(arg string) error { func (h Help) Execute(args []string) error { if h.Topic == "aerc-keys" { - app.AddDialog(app.NewDialog( + app.AddDialog(app.DefaultDialog( app.NewListBox( "Bindings: Press <Esc> or <Enter> to close. "+ "Start typing to filter bindings.", @@ -69,8 +69,6 @@ func (h Help) Execute(args []string) error { app.CloseDialog() }, ), - func(h int) int { return h / 4 }, - func(h int) int { return h / 2 }, )) return nil } diff --git a/commands/menu.go b/commands/menu.go index 953c6b45..908a354c 100644 --- a/commands/menu.go +++ b/commands/menu.go @@ -131,16 +131,8 @@ func (m Menu) Execute([]string) error { title := " :" + strings.TrimLeft(m.Xargs, ": \t") + " ... " - app.AddDialog(app.NewDialog( + app.AddDialog(app.DefaultDialog( ui.NewBox(term, title, "", app.SelectedAccountUiConfig()), - // start pos on screen - func(h int) int { - return h / 4 - }, - // dialog height - func(h int) int { - return h / 2 - }, )) } diff --git a/commands/patch/list.go b/commands/patch/list.go index 73461f2e..ee2850c3 100644 --- a/commands/patch/list.go +++ b/commands/patch/list.go @@ -88,18 +88,10 @@ func (l List) Execute(args []string) error { ) } - app.AddDialog(app.NewDialog( + app.AddDialog(app.LargeDialog( ui.NewBox(viewer, "Patch Management", "", app.SelectedAccountUiConfig(), ), - // start pos on screen - func(h int) int { - return h / 8 - }, - // dialog height - func(h int) int { - return h - 2*h/8 - }, )) return nil diff --git a/commands/patch/rebase.go b/commands/patch/rebase.go index 6ef43299..65aa580a 100644 --- a/commands/patch/rebase.go +++ b/commands/patch/rebase.go @@ -117,18 +117,10 @@ func (r Rebase) Execute(args []string) error { return err } - app.AddDialog(app.NewDialog( + app.AddDialog(app.LargeDialog( ui.NewBox(viewer, fmt.Sprintf("Patch Rebase on %-6.6s", baseID), "", app.SelectedAccountUiConfig(), ), - // start pos on screen - func(h int) int { - return h / 8 - }, - // dialog height - func(h int) int { - return h - 2*h/8 - }, )) return nil |