From 87d31a3d94a26c733e3efda9dd2f60688332bc5a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 9 Feb 2025 09:00:40 -0600 Subject: [PATCH] stub in code to page large windows --- eventBindingsStdout.go | 8 +++++++ structs.go | 4 +++- treeDraw.go | 54 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/eventBindingsStdout.go b/eventBindingsStdout.go index 1eed205..f48ed77 100644 --- a/eventBindingsStdout.go +++ b/eventBindingsStdout.go @@ -67,6 +67,14 @@ func stdoutArrowDown(g *gocui.Gui, v *gocui.View) error { } func stdoutPgdn(g *gocui.Gui, v *gocui.View) error { + win := findWindowUnderMouse() + if win != nil { + if win.full.Height() > 50 { + log.Info("paging through really large window pager =", win.window.pager) + win.window.pager += 10 + return nil + } + } me.stdout.pager += 10 tk := me.stdout.tk diff --git a/structs.go b/structs.go index a9d07e6..eb3905f 100644 --- a/structs.go +++ b/structs.go @@ -163,7 +163,9 @@ type window struct { order int // what level the window is on // resize bool // only set the title once collapsed bool // only show the window title bar - dense bool // true if the window is huge + dense bool // true if the window is dense + large bool // true if the window is huge + pager int // allows the user to page through the window } type colorT struct { diff --git a/treeDraw.go b/treeDraw.go index e9f9d20..c2d8864 100644 --- a/treeDraw.go +++ b/treeDraw.go @@ -41,6 +41,41 @@ func (tk *guiWidget) doNotDraw() bool { return false } +// page widgets in the window +func (tk *guiWidget) pageWidget() *rectType { + r := new(rectType) + + var check bool + switch tk.node.WidgetType { + case widget.Button: + check = true + case widget.Label: + check = true + default: + } + if !check { + return nil + } + win := tk.findParentWindow() + if win == nil { + // don't draw anything if you can't find the parent window + return nil + } + + r.w0 = tk.gocuiSize.w0 + r.h0 = tk.gocuiSize.h0 + r.w1 = tk.gocuiSize.w1 + r.h1 = tk.gocuiSize.h1 + + // r.h0 = tk.gocuiSize.h0 - win.gocuiSize.h0 + + if r.h0 > 20 { + return r + } + + return r +} + // display's the text of the widget in gocui // deletes the old view if it exists and recreates it func (tk *guiWidget) drawView() { @@ -70,9 +105,23 @@ func (tk *guiWidget) drawView() { c := tk.gocuiSize.w1 d := tk.gocuiSize.h1 + if r := tk.pageWidget(); r == nil { + // if nil, draw whatever it is anyway + } else { + if r.Width() == 0 && r.Height() == 0 { + // don't draw empty stuff + return + } + a = r.w0 + b = r.h0 + c = r.w1 + d = r.h1 + } + if tk.node.WidgetType == widget.Window || tk.node.WidgetType == widget.Flag { - if tk.gocuiSize.Height() > 30 { - tk.gocuiSize.h1 = tk.gocuiSize.h0 + 30 + if tk.gocuiSize.Height() > 40 { + tk.window.large = true + tk.gocuiSize.h1 = tk.gocuiSize.h0 + 40 d = tk.gocuiSize.h1 } } @@ -98,7 +147,6 @@ func (tk *guiWidget) drawView() { b = tk.gocuiSize.h0 c = tk.gocuiSize.w1 d = tk.gocuiSize.h1 - } tk.v, err = me.baseGui.SetView(tk.cuiName, a, b, c, d, 0)