emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SVG/PNG images in toolbars?


From: Clément Pit-Claudel
Subject: Re: SVG/PNG images in toolbars?
Date: Sat, 18 Nov 2017 21:31:30 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

On 2017-10-14 03:13, Eli Zaretskii wrote:
>> From: Clément Pit-Claudel <address@hidden>
>> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]