Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlatLaf: change accent color in Options dialog (Appearance > FlatLaf) #5795

Merged
merged 1 commit into from Apr 14, 2023

Conversation

DevCharly
Copy link
Member

Since changing accent color in FlatLaf custom properties does not work as expected for Cupertino themes (see issue #5461),
I've added a combobox to the options dialog to allow setting accent color in UI. FlatLaf API is used to enable accent color so that it works correctly in Cupertino themes.

grafik

There are some predefined accent colors, which work good for light and dark themes. These are the same colors that macOS (and FlatLaf Demo app) uses. There is also a "Custom" item in the combobox that allows to set any color.

grafik

The colors are defined in FlatLaf.properties (key nb.accentColors.predefined).

@DevCharly DevCharly added the UI User Interface label Apr 8, 2023
@DevCharly DevCharly added this to the NB18 milestone Apr 8, 2023
@DevCharly DevCharly linked an issue Apr 8, 2023 that may be closed by this pull request
@DevCharly
Copy link
Member Author

BTW we can of course use other predefined accent colors. Maybe some from the Windows 11 accent colors. Suggestions are welcome.

grafik

To try various accent colors I recommend using FlatLaf Theme Editor because it has live preview and a color picker: To do so, create/open an empty directory in theme editor, create two properties files, one for light and one for dark, and add following:

@accentColor = #FF453A

Theme Editor preview now looks like this:

grafik

Select "Focused" checkbox to show all preview components in focused state.

Copy link
Member

@neilcsmith-net neilcsmith-net left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do a UI for exactly this after doing the initial properties file support. Generally in favour.

Isn't the fact that the accent color in the properties files is ignored in the Cupertino themes a bug in FlatLaf?

Ideally we'd find a way to store the setting in the properties file, rather than Preferences. I initially wanted to find a way to have 2-way editing (UI and text) for that. And load/save support (eg. share NetBeans themes). The file is deliberately read from the system config filesystem too, eg. so that platform developers can provide an alternative non-empty implementation via the layer.

Copy link
Contributor

@eirikbakke eirikbakke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! How does this setting interact with other ways of manipulating FlatLAF properties, such as the "Edit custom properties" button, or changing platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/FlatLightLaf.properties/FlatDarkLaf.properties? If the color is left at "default", is the behavior the same as before?

Code formatting: Tabs in the patch should be replaced by four spaces as in the rest of the file.

(In the future it would be cool if the entire FlatLAF Theme Editor could just be exposed from a button in the Options dialog.)

@DevCharly
Copy link
Member Author

How does this setting interact with other ways of manipulating FlatLAF properties, such as the "Edit custom properties" button, or changing platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/FlatLightLaf.properties/FlatDarkLaf.properties?

The accent color is stored in NB preferences store and overrides @accentColor.
Function systemColor(accent) is used in properties files to get this color into FlatLaf UI defaults.
See PR JFormDesigner/FlatLaf#607

If the color is left at "default", is the behavior the same as before?

Yes.

Copy link
Contributor

@eirikbakke eirikbakke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the latest version of the patch and it works, including the following cases:

  • Selecting the default accent color after previously having one of the other presets selected
  • Overriding with the "Edit custom properties" button. If the accent color is set here, it overrides the setting from the combo box, which makes sense given the label over the button. Removing the accent color from the properties file makes the combo box choice work again.
  • Custom accent color from color chooser works.

One small hiccup:

  • Picking a different accent color and switching to Cupertino Light works except: The user now gets two "Restart IDE" notifications, and if they restart from the one that was triggered by the accent color change, they won't have the chance to get the effect of "Switch to matching editor colors profile."

Not sure it's worth doing something about the latter case, though, unless it's trivial to fix...

@DevCharly
Copy link
Member Author

The user now gets two "Restart IDE" notifications, ...

I think it is difficult to avoid the two notifications because they are implemented in different modules.

However I've changed the priority of the "accent color" notification from HIGH to NORMAL.
There are still two notifications, but now always the "look and feel" notification is show at the status bar.

@eirikbakke
Copy link
Contributor

@DevCharly Great, that probably improves usability for this corner case. Thanks!

@DevCharly
Copy link
Member Author

Isn't the fact that the accent color in the properties files is ignored in the Cupertino themes a bug in FlatLaf?

The @accentColor variable is indeed not used for all accent colors in Cupertino/macOS themes.

But wouldn't say it is a bug. It's more a design decision to use systemColor(accent) (see PR JFormDesigner/FlatLaf#607) as common way to get accent color (e.g. from operating system or from app preferences).

But I must confess that I have not considered the NetBeans use case...
Probably will rework Cupertino themes...

Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

played with it a bit and it worked great. (code looks good too)

please merge when ready to reduce PR backlog before freeze.

@mbien mbien merged commit cfda31b into apache:master Apr 14, 2023
34 checks passed
@DevCharly DevCharly deleted the flatlaf-accent-color branch April 14, 2023 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UI User Interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Minor inconsistencies with FlatLaf look and feels
4 participants