1
0
Fork 0

- [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.
This commit is contained in:
cage 2023-03-19 13:00:28 +01:00
parent d61656e0ad
commit 2982dfdeeb
5 changed files with 53 additions and 18 deletions

View File

@ -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

View File

@ -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 ()

View File

@ -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))

View File

@ -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

View File

@ -506,6 +506,8 @@
animation
x
y
maximum
minimum
error
info
window