PopupMenu with Icons ?

I want to add a small representation of the files presented in a PopupMenu.

I have a Template folder with color variations of (nearly one) a Directory icon (Windows 10) and I want to place an icon of it at the left of the image file name, so the user will have an idea of the color (vs a simple appreciation liek Oink).

Is it possible to add that in a PopupMenu (seems no to me) ?

XPlatform, of course.

I’ve made a third check with Xojo and found that maybe BevelButton can make the trick. Do you think so ?

No. That’s among my Top Five Xojo regrets. All my Popups ups just have text (sigh).

We old-timers all know that one of the Core Principles of REAL/Xojo is to use standard OS controls. That’s for the most part a good thing. The problem is when you run into “common things” that you see in other programs, or things that lend to saying “why not?” that aren’t in the standard OS control feature set.

In other other, more DIY development environments, they can subclass INTO the OS control themselves and add features, which is how most non-Xojo programs achieve icons on popupmenus. Within Xojo, you can subclass what Xojo gives you, but you can’t change the very thing of what it is. Kind of like getting a car and being able to paint it, put on bumper stickers, etc. but not being able to alter the engine or change the suspension.

Since don’t want Xojo to be more complicated on it’s face, I"m glad it’s that way. However, it WOULD be nice if Xojo allowed some customization, if possible - and it should be possible. The tradeoff would be possible incompatibility with future OS’s, and that isn’t something we want.

To address the question directly - the solution is to make your own popup menu based on a Canvas. Again, the problem is that YOU have to accommodate new styles and looks and behaviors of OS’s, not only based on the OS itself but also the theme/skin the user has. Well, you don’t HAVE TO, but it sure looks cheesy when your popupmenus don’t look like all the other ones in the system.

I’ve made my own PopupMenu that goes into my Listbox subclass, so I can have PopupMenus in my Listboxes. But I make the same compromise that I just mentioned (sigh).

Lastly, in conclusion, if you study all types of non-Xojo apps, you’ll see how much they subclass the basic feature set.

Nice answer Garth, I love reading it.

Nota: it was an idea that comes to mind (from where ? Don’t ask 'cause I do not know) when I was fooling around with that PopupMenu.

No, I do not saw that (PopupMenu with icons) elsewhere. Now, we can add icons to the MenuItems, so why not in PopupMenus…

Thanks a lot.

This may help. It is how you insert icons into a ContextualMenu. By placing it immediately underneath a popumenu without elements, you can have icons :

[code] dim base as new MenuItem

dim un as new menuitem
un.Icon = calendar
un.Text = “Calendar”
base.append(un)

dim deux as new menuitem
deux.Icon = camera_delete
deux.Text = “Camera”
base.append(deux)

dim trois as new menuitem
trois.Icon = card_chip_gold
trois.Text = “Calendar”
base.append(trois)

dim m as menuitem = base.PopUp(PopupMenu1.Left, PopupMenu1.Top + 80)

if m <> nil then msgbox m.text
[/code]

Thank you Michel, I will try this after lunch.

Although I have not tried it, you may also be able to use emoji.

Thanks Greg.

In a couple of app I insert icons and texts in popup menus using macOSlib.

[selfPromote “Do you have the Retina Kit 3.0?”]

There’s code in the demo app for doing this and a bunch of other things.

I add icons to my popups very simply by inserting UTF8 glyphs into the text. There’s hundreds of glyphs to choose from. Hopefully you can find ones that work for you.

How about sharing some code to do this?

Sure.

const padlock= &u1F512 popupmenu1.addrow "Lock " + padlock

Thanks Richard,

Works well.
Thanks again.

Lennox

The making it look appropriate to the OS is why I mostly stopped doing my own controls using a canvas …

I have tried using RectControl.DrawInto, but that is not quite flexible enough (and used to be quite buggy - have not tried recently)

I wonder If Xojo could provide XPlatform methods to just DRAW OS controls in various states (selected, unselect, Pushed, with an without focus)… That way when we want a custom control we would only have to worry about making it do what we want rather than making it look OS appropriate…

If had that, it would be trivial to make popup menus with icons or be hierarchical etc, etc.

  • Karen

I did this for a while, until I discovered that different OS versions not only had different graphics; but also they don’t all have the same symbols. 99% of the time it’s older OS versions missing characters from newer versions, but I did run into one case where a character had been removed.

Press ctrl-cmd-space to get the picker.

Oh and make sure you use the system font! Older OS versions allowed you to use different fonts; but newer ones don’t.

I don’t know about Windows, but the macOS considers the menu of a PopupMenu to be a menu, so the same declares that set a NSImage to a menu (on the menu bar or contextual) can be used to customise a PopupMenu.

[quote=306524:@Karen Atkocius]
I wonder If Xojo could provide XPlatform methods to just DRAW OS controls in various states (selected, unselect, Pushed, with an without focus)… [/quote]
We do
DrawInto

How do you think we make the IDE draw them right ?

[quote=306540:@Norman Palardy]We do
DrawInto
How do you think we make the IDE draw them right ?[/quote]

I mentioned DrawInto…

It was pretty wonky for a number of controls last time I tried to use it (some years ago now) to draw my own … AND you and have to have a control on a window to use Drawinto, which made it awkward!

Also I needed to draw controls in various states, but to get that look in a "real"control to use DrawInto, I needed to click on it with the mouse, making it impractical.

What I had in mind were graphics functions that you supply parameters to the method to draw the control in the visual states it it normally supports in each OS… Which would me more work on Xojo’s end than DrawInto I think.

That is not something I except Xojo inc to do with everything it has on it’s plate, but it would be nice to have for when we need to do our own controls to match what apps using other tools can do as mentioned above…

  • karen

You CAN already do 99.9% of this with sufficient diligence for desktop controls using drawinto
Its how we get the images of the controls for the IDE’s layout editor
Really
The layout editor in the IDE is just a giant picture composed using images we get from drawinto :slight_smile:

You cant do it for the Window frame itself - ask apple about that one - as they have an API for doing it but its in a private framework

The thing with Emoji is that the look and feel might change over time. Also, on each platform the Emoji looks different. It would be better to be able to create a PNG to have more control over the look and feel of an icon