mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.13k stars 234 forks source link

Check box and radio button icon support #573

Closed mgarin closed 4 years ago

mgarin commented 4 years ago

Right now checkbox and radio buttons (including menu items) can either display a check/radio icon or a custom icon, but not both at the same time. It would be nice to have them both.

To be more specific - changing component Icon should not remove or configure the check/radio icon anyhow, but instead add/remove a custom icon besides it.

For menu items this also means that other items in the same menu will have to be properly aligned to check/radio+custom icon width (or ignore it?).

Sciss commented 4 years ago

For reference, here is a screenshot showing metal laf with user icon along checkbox (left) and web laf (right). tooltips are shown. cbmi-with-icon-compare

mgarin commented 4 years ago

Yep. I re-checked other L&Fs today to see how they handle it in menus and it is mostly handled like in MetalLookAndFeel with a few exceptions.

I will most probably do it the same way it is done in MetalLookAndFeel - add check/radio icon in front and move icons of all other menu items forward to line up with check/radio menu item custom icons. The implementation is already in place, I'll just need to tune a few things in UI, content layout and painter.

mgarin commented 4 years ago

Ok, since I decided to fix this once and for all - I've made a different approach at rendering state icon for JCheckBoxMenuItem and JRadioButtonMenuItem to avoid JCheckBox and JRadioButton implementation affecting them anyhow.

First of all, here is the simple example state icons & custom icons:

image

Here is how it will align with other elements with state icons only:

image

And here are some normal menu items on top:

image

And here is a small niche case I've also added proper handling for:

image

This is basically the case when all state menu items do not have any custom icon while some other normal menu items are also present (with and without icons). This allows you not to have two ugly columns each of which is half-empty.

Menu will properly align even with differently-sized icons:

image

And even if you decide to go wild on the style:

image

And here is the dark example:

image

Alignments, paddings, layout and other settings can be adjusted for menu items in the style, although hopefully default layout and settings handle most cases. You can even disable aligning menu items:

image

I'll be pushing these changes shortly, just need to check everything last time.

mgarin commented 4 years ago

These changes are now available in master. Snapshot build should also be available soon.