Skip to content

Commit

Permalink
Increase visual distinction for disabled state
Browse files Browse the repository at this point in the history
Depending on the palette, PhantomStyle might not always provide enough
visual hints for disabled states. This commit tries to add some
additional visual distinction. This commit changes two things: it
decreases the outline contrast on disabled widgets, and removes the
specular shading on disabled widgets.

For the outline contrast, the Swatchy code which derives the outline
color from the window color is changed to use a smaller contrast value
when the QPalette's current color group is Disabled.

Many clickable widgets, like push buttons, have an inner ring of
highlighting which is called specular in the PhantomStyle code. This
commit changes the colors used for these specular highlights to be the
same as the colors that are underneath the highlights when the
QPalette's current color group is Disabled, thus making the specular not
visible. This means the painting operations for the specular roundrects
and rectangles are still occurring. It would be more efficient to have
code paths which don't draw the specular at all when a widget is
disabled, but this would require adding a number of additional code
paths in PhantomStyle in the widget drawing code, and I don't think
that's worth it at the moment.

It's probably worth revisiting if the Inactive state is ever changed to
also not show the specular, because redraws on multiple widgets might
occur when focusing and defocusing a window, and saving a few roundrect
draws would be worth it, even though it would add more code.
  • Loading branch information
cancel committed May 24, 2021
1 parent 6e9580b commit 309c97a
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/phantom/phantomstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ using PhSwatchCache = QVarLengthArray<PhCacheEntry, Num_ColorCacheEntries>;
Q_NEVER_INLINE void PhSwatch::loadFromQPalette(const QPalette& pal) {
using namespace SwatchColors;
namespace Dc = DeriveColors;
const bool isEnabled = pal.currentColorGroup() != QPalette::Disabled;
QColor colors[Num_SwatchColors];
colors[S_none] = QColor();

Expand All @@ -366,26 +367,37 @@ Q_NEVER_INLINE void PhSwatch::loadFromQPalette(const QPalette& pal) {
colors[S_highlightedText] = pal.color(QPalette::HighlightedText);
colors[S_scrollbarGutter] = Dc::gutterColorOf(pal);

colors[S_window_outline] = Dc::adjustLightness(colors[S_window], -0.1);
colors[S_window_specular] = Dc::specularOf(colors[S_window]);
// There's a chance that some widgets won't redraw when changing to and from
// the disabled state, causing the outline color in the frame buffer to be
// out of sync with what it should be. If we notice this problem, we can get
// rid of conditional color branching and try to do it some other way.
colors[S_window_outline] =
Dc::adjustLightness(colors[S_window], isEnabled ? -0.1 : -0.07);
colors[S_window_specular] =
isEnabled ? Dc::specularOf(colors[S_window]) : colors[S_window];
colors[S_window_divider] = Dc::dividerColor(colors[S_window]);
colors[S_window_lighter] = Dc::lightShadeOf(colors[S_window]);
colors[S_window_darker] = Dc::darkShadeOf(colors[S_window]);
colors[S_button_specular] = Dc::specularOf(colors[S_button]);
colors[S_button_specular] =
isEnabled ? Dc::specularOf(colors[S_button]) : colors[S_button];
colors[S_button_pressed] = Dc::pressedOf(colors[S_button]);
colors[S_button_pressed_specular] = Dc::specularOf(colors[S_button_pressed]);
colors[S_button_pressed_specular] =
isEnabled ? Dc::specularOf(colors[S_button_pressed])
: colors[S_button_pressed];
colors[S_base_shadow] = Dc::overhangShadowOf(colors[S_base]);
colors[S_base_divider] = Dc::dividerColor(colors[S_base]);
colors[S_windowText_disabled] =
pal.color(QPalette::Disabled, QPalette::WindowText);
colors[S_highlight_outline] = Dc::adjustLightness(colors[S_highlight], -0.05);
colors[S_highlight_specular] = Dc::specularOf(colors[S_highlight]);
colors[S_highlight_specular] =
isEnabled ? Dc::specularOf(colors[S_highlight]) : colors[S_highlight];
colors[S_progressBar_outline] = Dc::progressBarOutlineColorOf(pal);
colors[S_inactiveTabYesFrame] =
Dc::inactiveTabFillColorOf(colors[S_tabFrame]);
colors[S_inactiveTabNoFrame] = Dc::inactiveTabFillColorOf(colors[S_window]);
colors[S_inactiveTabYesFrame_specular] =
Dc::specularOf(colors[S_inactiveTabYesFrame]);
isEnabled ? Dc::specularOf(colors[S_inactiveTabYesFrame])
: colors[S_inactiveTabYesFrame];
colors[S_inactiveTabNoFrame_specular] =
Dc::specularOf(colors[S_inactiveTabNoFrame]);
colors[S_indicator_current] = Dc::indicatorColorOf(pal, QPalette::Current);
Expand Down

0 comments on commit 309c97a

Please sign in to comment.