all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Clément Pit-Claudel" <cpitclaudel@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: SVG/PNG images in toolbars?
Date: Sat, 18 Nov 2017 21:31:30 -0500	[thread overview]
Message-ID: <e710ed6f-9866-050a-6ffc-762481edd5c5@gmail.com> (raw)
In-Reply-To: <831sm6jj79.fsf@gnu.org>

On 2017-10-14 03:13, Eli Zaretskii wrote:
>> From: Clément Pit-Claudel <cpitclaudel@gmail.com>
>> Date: Sat, 14 Oct 2017 04:15:15 +0200
>>
>> Question: could we extend tool-bar--image-expression to return a form including references to SVGs and PNGs? I'd be happy to provide a patch.
> 
> Please show the patch.

Something along these lines, roughly:

diff --git a/lisp/tool-bar.el b/lisp/tool-bar.el
index ee01a69..4bc7354 100644
--- a/lisp/tool-bar.el
+++ b/lisp/tool-bar.el
@@ -152,13 +152,17 @@ tool-bar--image-expression
 	 (pbm-spec (append (list :type 'pbm :file
                                  (concat icon ".pbm")) colors))
 	 (xbm-spec (append (list :type 'xbm :file
-                                 (concat icon ".xbm")) colors)))
+                                 (concat icon ".xbm")) colors))
+         (png-spec (append (list :type 'png :file
+                                 (concat icon ".png")) colors))
+         (svg-spec (append (list :type 'svg :file
+                                 (concat icon ".svg")) colors)))
     `(find-image (cond ((not (display-color-p))
 			',(list pbm-spec xbm-spec xpm-lo-spec xpm-spec))
 		       ((< (display-color-cells) 256)
 			',(list xpm-lo-spec xpm-spec pbm-spec xbm-spec))
 		       (t
-			',(list xpm-spec pbm-spec xbm-spec))))))
+			',(list svg-spec png-spec xpm-spec pbm-spec xbm-spec))))))
 
 ;;;###autoload
 (defun tool-bar-local-item (icon def key map &rest props)


> Though I admit I don't really understand the
> purpose of such a patch: you can already provide an image spec for a
> tool-bar button when you write the corresponding define-key
> expression, and you can secify any images you like in that spec.
> tool-bar--image-expression is for constructing tool-bar items from
> menus, AFAIR.

Yes, exactly. Sorry I was unclear.
Let me try to explain better :)

I already have a menu for my major mode, and I'm making a toolbar for it. tool-bar-local-item-from-menu is super convenient for that:

(defvar mymode-tool-bar-map
  (let ((map (make-sparse-keymap)))
    (tool-bar-local-item-from-menu 'mymode-copy "mymode-copy" map mymode-map)
    (tool-bar-local-item-from-menu 'mymode-paste "mymode-paste" map mymode-map)
    (define-key-after map [mymode-sep] '(menu-item "--"))
    (tool-bar-local-item-from-menu 'mymode-reload "mymode-reload" map mymode-map)
    …))

… except this code only works if my icons (mymode-copy, mymode-paste, mymode-reload etc.) are in XPM, PBM, or XBM format.  That's because tool-bar-local-item-from-menu calls tool-bar--image-expression to build the image spec of the new toolbar item, and unfortunately the resulting spec only references XPM, PBM, and XBM files (this is documented in tool-bar-add-item):

> ICON is the base name of a file containing the image to use.  The
> function will first try to use low-color/ICON.xpm if `display-color-cells'
> is less or equal to 256, then ICON.xpm, then ICON.pbm, and finally
> ICON.xbm, using `find-image'
Now suppose I want to use PNG or SVG images in my toolbar.  I can either rebind tool-bar--image-expression to return an image spec including PNGs and SVGs, or duplicate tool-bar-item-from-menu and replace the call to tool-bar--image-expression in the copy, or post-process the keymap after calling tool-bar-item-from-menu.

Neither of these are great, right?

(I'm not super happy with the patch either; maybe it'd be better to introduce a variant of tool-bar-local-item-from-menu that takes an image expression instead of a string for the icon, and use that to implement tool-bar-local-item-from-menu; or maybe it would be better to make a dynamic variable that specifies which image formats to use; or maybe something else?).

Thanks for your time!
Clément.



      reply	other threads:[~2017-11-19  2:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-13 15:07 SVG/PNG images in toolbars? Clément Pit-Claudel
2017-10-13 16:11 ` Eli Zaretskii
2017-10-13 22:49   ` Clément Pit-Claudel
2017-10-14  6:51     ` Eli Zaretskii
2017-10-14  2:15 ` Clément Pit-Claudel
2017-10-14  7:13   ` Eli Zaretskii
2017-11-19  2:31     ` Clément Pit-Claudel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e710ed6f-9866-050a-6ffc-762481edd5c5@gmail.com \
    --to=cpitclaudel@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.