From 2982dfdeeb23bf4f3d9a016c7f56cebcc61a5b6f Mon Sep 17 00:00:00 2001 From: cage Date: Sun, 19 Mar 2023 13:00:28 +0100 Subject: [PATCH] - [GUI] made the TOC's resize its width to fits the TOC items width. - [GUI] added configuration directive for TOC width limits; - [GUI] refactored TOC rendering code; - [GUI] clear TOC widget from legacy items befor rendering the new TOC. --- etc/gui.conf | 4 +- src/gui/client/client-configuration.lisp | 12 +++++- src/gui/client/main-window.lisp | 48 ++++++++++++++++-------- src/package.lisp | 5 ++- src/software-configuration.lisp | 2 + 5 files changed, 53 insertions(+), 18 deletions(-) diff --git a/etc/gui.conf b/etc/gui.conf index 4820e72..90953c7 100644 --- a/etc/gui.conf +++ b/etc/gui.conf @@ -158,7 +158,9 @@ gemini.preformatted.justification = center # width in chars -toc.width = 30 +toc.maximum.width = 80 + +toc.minimum.width = 20 toc.font = Monospace diff --git a/src/gui/client/client-configuration.lisp b/src/gui/client/client-configuration.lisp index e85161a..01a0e75 100644 --- a/src/gui/client/client-configuration.lisp +++ b/src/gui/client/client-configuration.lisp @@ -210,12 +210,22 @@ (gen-conf-justification gemini swconf:+key-preformatted-text+) -(swconf:gen-simple-access (toc-width +(swconf:gen-simple-access (toc-maximum-width + :transform-value-fn (lambda (a) + (truncate (or (num-utils:safe-parse-number a) + 20))) + :configuration-tree *client-configuration*) + swconf:+key-toc+ + swconf:+key-maximum+ + swconf:+key-width+) + +(swconf:gen-simple-access (toc-minimum-width :transform-value-fn (lambda (a) (truncate (or (num-utils:safe-parse-number a) 80))) :configuration-tree *client-configuration*) swconf:+key-toc+ + swconf:+key-minimum+ swconf:+key-width+) (defun toc-font-configuration () diff --git a/src/gui/client/main-window.lisp b/src/gui/client/main-window.lisp index 557c6ce..b3985b1 100644 --- a/src/gui/client/main-window.lisp +++ b/src/gui/client/main-window.lisp @@ -112,6 +112,22 @@ (with-notify-errors (apply #'comm:make-request method-name id args)))) +(defun render-toc (main-window iri) + (with-notify-errors + (toc-clear main-window) + (let* ((toc-max-width (gui-conf:config-toc-maximum-width)) + (toc (comm:make-request :gemini-table-of-contents + 1 + iri + toc-max-width))) + (when toc + (let ((toc-widget-width (length (getf (first toc) :text)))) + (setf (toc-char-width main-window) toc-widget-width) + (loop for ct from 0 + for toc-item in toc do + (gui:listbox-append (toc-listbox (toc-frame main-window)) + (getf toc-item :text)))))))) + (defun slurp-gemini-stream (main-window iri stream-wrapper &key (use-cache t) (process-function #'identity) @@ -139,20 +155,8 @@ (loop-fetch (+ last-lines-fetched-count next-start-fetching)))))))) (loop-fetch) - (let ((gui:*wish* gui-goodies:*gui-server*)) - (let* ((toc-widget-width (gui:cget (gui:listbox (toc-listbox (toc-frame main-window))) - :width)) - (toc-width (parse-integer toc-widget-width)) - (toc (cev:enqueue-request-and-wait-results :gemini-table-of-contents - 1 - ev:+standard-event-priority+ - iri - toc-width))) - (misc:dbg "toc ~a" toc-width) - (loop for ct from 0 - for toc-item in toc do - (gui:listbox-append (toc-listbox (toc-frame main-window)) - (getf toc-item :text))))))) + (ev:with-enqueued-process-and-unblock () + (render-toc main-window iri)))) (defun start-streaming-thread (main-window iri &key @@ -705,7 +709,7 @@ (setf toc-listbox (make-instance 'gui:scrolled-listbox :master object :name nil)) - (gui:configure (gui:listbox toc-listbox) :width (gui-conf:config-toc-width)) + (gui:configure (gui:listbox toc-listbox) :width (gui-conf:config-toc-minimum-width)) (gui:configure (gui:listbox toc-listbox) :font (gui-conf:toc-font-configuration)) (gui:grid toc-listbox 0 0 @@ -777,6 +781,20 @@ (gui:focus (nodgui.mw:autocomplete-entry-widget (iri-entry (tool-bar object)))) object)) +(defgeneric toc-char-width (object)) + +(defgeneric toc-clear (object)) + +(defmethod toc-char-width ((object main-frame)) + (gui:cget (gui:listbox (toc-listbox (toc-frame object))) + :width)) + +(defmethod toc-clear ((object main-frame)) + (gui:listbox-delete (toc-listbox (toc-frame object)))) + +(defmethod (setf toc-char-width) (new-width (object main-frame)) + (gui:configure (gui:listbox (toc-listbox (toc-frame object))) :width new-width)) + (defun print-info-message (message &key (color (gui-goodies:parse-color "black")) (bold nil)) diff --git a/src/package.lisp b/src/package.lisp index 6943ee8..1b4ed89 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -1178,6 +1178,8 @@ :+key-animation+ :+key-x+ :+key-y+ + :+key-maximum+ + :+key-minimum+ :+key-error+ :+key-info+ :+key-window+ @@ -3266,7 +3268,8 @@ :gemini-h2-justification :gemini-h3-justification :gemini-preformatted-text-justification - :config-toc-width + :config-toc-maximum-width + :config-toc-minimum-width :toc-font-configuration)) (defpackage :client-os-utils diff --git a/src/software-configuration.lisp b/src/software-configuration.lisp index ea3f378..4963a16 100644 --- a/src/software-configuration.lisp +++ b/src/software-configuration.lisp @@ -506,6 +506,8 @@ animation x y + maximum + minimum error info window