Skip to content

Commit ed63eb7

Browse files
authored
Merge pull request #2313 from ControlSystemStudio/more_impressive_button_press
Action button: Darker background when pressed
2 parents 5dface5 + f888337 commit ed63eb7

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/JFXUtil.java

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,41 +94,32 @@ public static StringBuilder appendWebRGB(final StringBuilder buf, final WidgetCo
9494

9595
/** Convert model color into CSS style string for shading tabs, buttons, etc
9696
* @param color {@link WidgetColor}
97-
* @return style string of the form "-fx-color: ... -fx-outer-border: ... -fx-inner-border: ... -fx-background: ..."
97+
* @return style string of the form "-fx-base: ..;"
9898
*/
9999
public static String shadedStyle(final WidgetColor color)
100100
{
101101
return shadedStyleCache.computeIfAbsent(color, col ->
102102
{
103103
// How to best set colors?
104-
// Content Pane can be set in API, but Tab has no usable 'set color' API.
104+
// Content Pane can be set in API, but Button and Tab have no usable 'set color' API.
105105
// TabPane has setBackground(), but in "floating" style that would be
106106
// the background behind the tabs, which is usually transparent.
107-
// modena.css of JDK8 reveals a structure of sub-items which are shaded with gradients based
108-
// on -fx-color for the inactive tabs,
109-
// -fx-outer-border and -fx-inner-border for the, well, border,
110-
// and -fx-background for the selected tab,
111-
// so re-define those.
107+
//
108+
// Adjusting the style can break when the underlying style sheet changes,
109+
// but since at least JDK8 that has been modena.css with little changes until JFX 18,
110+
// which can be found in javafx-controls-18-linux.jar as
111+
// com/sun/javafx/scene/control/skin/modena/modena.css
112+
//
113+
// Buttons use nested -fx-background-color entries
114+
// -fx-shadow-highlight-color, -fx-outer-border, -fx-inner-border, -fx-body-color
115+
// with associated ..-insets and ..-radius which are all based on -fx-base,
116+
// so redefine that to adjust the overall color.
117+
// The .button.armed state uses
118+
// -fx-pressed-base: derive(-fx-base,-6%);
119+
// which we change into a more obvious variant.
112120
final String bg = webRGB(col);
113-
return "-fx-color: derive(" + bg + ", 50%);" +
114-
"-fx-outer-border: derive(" + bg + ", -23%);" +
115-
"-fx-inner-border: linear-gradient(to bottom," +
116-
"ladder(" + bg + "," +
117-
" derive(" + bg + ",30%) 0%," +
118-
" derive(" + bg + ",20%) 40%," +
119-
" derive(" + bg + ",25%) 60%," +
120-
" derive(" + bg + ",55%) 80%," +
121-
" derive(" + bg + ",55%) 90%," +
122-
" derive(" + bg + ",75%) 100%" +
123-
")," +
124-
"ladder(" + bg + "," +
125-
" derive(" + bg + ",20%) 0%," +
126-
" derive(" + bg + ",10%) 20%," +
127-
" derive(" + bg + ",5%) 40%," +
128-
" derive(" + bg + ",-2%) 60%," +
129-
" derive(" + bg + ",-5%) 100%" +
130-
"));" +
131-
"-fx-background: " + bg + ";";
121+
return "-fx-base: " + bg + "; " +
122+
"-fx-pressed-base: derive(-fx-base,-25%);";
132123
});
133124
}
134125

@@ -217,7 +208,7 @@ public static Pos computePos(final HorizontalAlignment horiz, final VerticalAlig
217208
}
218209

219210
/**returns double[] array for given line style scaled by line_width
220-
*
211+
*
221212
* @param style - actual line style
222213
* @param line_width - actual line width
223214
* @return double[] with segment lengths

app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/ActionButtonRepresentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015-2020 Oak Ridge National Laboratory.
2+
* Copyright (c) 2015-2022 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -323,7 +323,7 @@ private void handleActions(final List<ActionInfo> actions)
323323
/** @param action Action that the user invoked */
324324
private void handleAction(ActionInfo action)
325325
{
326-
// Keyboard presses are not supressed so check if the widget is enabled
326+
// Keyboard presses are not suppressed so check if the widget is enabled
327327
if (! enabled)
328328
return;
329329

0 commit comments

Comments
 (0)