[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Highlighting text next to button
From: |
Stephen Berman |
Subject: |
Re: Highlighting text next to button |
Date: |
Mon, 01 Jul 2024 00:11:27 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
On Sun, 30 Jun 2024 21:52:12 +0000 Heime <heimeborgia@protonmail.com> wrote:
> On Sunday, June 30th, 2024 at 8:00 PM, Heime <heimeborgia@protonmail.com>
> wrote:
>
>> I have the function monde that displays some buttons with associated text
>> describing what the button does.
>>
>> I would like to highlight the description text corresponding to the button
>> that was pressed, with NORM being the default when calling the function.
>> What can I do ?
>>
>> (defun spaz (w)
>> "Make a string of width W made of spaces."
>> (make-string w ?\s))
>>
>> (defun mondu ()
>>
>> (interactive)
>>
>> (with-current-buffer (get-buffer-create "Mondu")
>>
>> (insert " MAIN PANEL DU \n\n")
>>
>> (insert " ")
>> (insert-button "[-]" 'action 'mondu-outbd)
>> (insert " OUTBD ")
>>
>> (insert-button "[-]" 'action 'mondu-norm)
>> (insert " NORM ")
>>
>> ;;------------------------------------------------------------
>>
>> (insert-button "[-]" 'action 'mondu-inbd-eng-pri)
>> (insert " INBD ENG PRI \n")
>>
>> (insert (spaz 24))
>> (insert-button "[-]" 'action 'mondu-inbd-pfd)
>> (insert " INBD PFD \n")
>>
>> (insert (spaz 24))
>> (insert-button "[-]" 'action 'mondu-inbd-hfd)
>> (insert " INBD HFD \n") )
>>
>> (pop-to-buffer "Mondu") )
>
> Have made the following. But I also have to activate the text that is printed
> to the help buffer when pressing the button.
>
>
> (defun mondu-color-text (text color)
> "Color TEXT in the specified COLOR in the Mondu buffer."
>
> (with-current-buffer "Mondu"
> (save-excursion
> (goto-char (point-min))
> (when (search-forward text nil t)
> (let ((start (match-beginning 0))
> (end (match-end 0)))
> (add-text-properties start end `(face (:foreground ,color))))))))
>
>
> (defun mondu ()
> "Set up the Mondu buffer with buttons and text."
>
> (interactive)
>
> (with-current-buffer (get-buffer-create "Mondu")
>
> (erase-buffer) ;; Clear the buffer to avoid repeated content on multiple
> invocations
>
> (insert " MAIN PANEL DU \n\n")
>
> (insert " ")
> (insert-button "[-]"
> 'action (lambda (_) (mondu-color-text " OUTBD " "red")))
> (insert " OUTBD ")
>
> (insert-button "[-]"
> 'action (lambda (_) (mondu-color-text " NORM " "red")))
> (montejura-insert-colorat " NORM " "red")
>
> (insert-button "[-]"
> 'action (lambda (_) (mondu-color-text " INBD ENG PRI " "red")))
> (insert " INBD ENG PRI \n")
>
> (insert (espz 24))
> (insert-button "[-]"
> 'action (lambda (_) (mondu-color-text " INBD PFD " "red")))
> (insert " INBD PFD \n")
>
> (insert (espz 24))
> (insert-button "[-]"
> 'action (lambda (_) (mondu-color-text " INBD HFD " "red")))
> (insert " INBD HFD \n"))
>
> (pop-to-buffer "Mondu"))
Perhaps this (based on the first version):
(defun mondu ()
(interactive)
(with-current-buffer (get-buffer-create "Mondu")
(let ((make-desc (lambda (&optional description)
(insert (propertize (or description " NORM ")
'face '( :weight bold
:slant italic
:background "lightgray"))))))
(insert " MAIN PANEL DU \n\n")
(insert " ")
(insert-button "[-]" 'action 'mondu-outbd)
(funcall make-desc " OUTBD ")
(insert-button "[-]" 'action 'mondu-norm)
(funcall make-desc)
;;------------------------------------------------------------
(insert-button "[-]" 'action 'mondu-inbd-eng-pri)
(funcall make-desc " INBD ENG PRI \n")
(insert (spaz 24))
(insert-button "[-]" 'action 'mondu-inbd-pfd)
(funcall make-desc " INBD PFD \n")
(insert (spaz 24))
(insert-button "[-]" 'action 'mondu-inbd-hfd)
(funcall make-desc" INBD HFD \n")))
(pop-to-buffer "Mondu"))
Steve Berman