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

Action button: Darker background when pressed #2311

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015-2020 Oak Ridge National Laboratory.
* Copyright (c) 2015-2022 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -23,6 +23,7 @@
import org.csstudio.display.builder.model.properties.OpenDisplayActionInfo;
import org.csstudio.display.builder.model.properties.RotationStep;
import org.csstudio.display.builder.model.properties.StringWidgetProperty;
import org.csstudio.display.builder.model.properties.WidgetColor;
import org.csstudio.display.builder.model.properties.WritePVActionInfo;
import org.csstudio.display.builder.model.widgets.ActionButtonWidget;
import org.csstudio.display.builder.representation.javafx.Cursors;
Expand All @@ -36,6 +37,7 @@
import org.phoebus.ui.vtype.FormatOptionHandler;

import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.geometry.Dimension2D;
import javafx.scene.Cursor;
import javafx.scene.control.Button;
Expand Down Expand Up @@ -76,7 +78,7 @@ public class ActionButtonRepresentation extends RegionBaseRepresentation<Pane, A
private final DirtyFlag dirty_actionls = new DirtyFlag();

private volatile ButtonBase base;
private volatile String background;
private volatile String background, pressed_background;
private volatile Color foreground;
private volatile String button_text;
private volatile boolean enabled = true;
Expand Down Expand Up @@ -135,6 +137,9 @@ private void checkModifiers(final MouseEvent event)
return;
}

// Indicate that button is pressed
base.setStyle(pressed_background);

// 'control' ('command' on Mac OS X)
if (event.isShortcutDown())
target_modifier = Optional.of(OpenDisplayActionInfo.Target.TAB);
Expand Down Expand Up @@ -211,7 +216,13 @@ private ButtonBase makeBaseButton()
// Monitor keys that modify the OpenDisplayActionInfo.Target.
// Use filter to capture event that's otherwise already handled.
if (! toolkit.isEditMode())
{
// Pressed button will use pressed_background, check modifiers, then invoke actions
result.addEventFilter(MouseEvent.MOUSE_PRESSED, this::checkModifiers);
// Restore normal background when released
final EventHandler<MouseEvent> restore = event -> result.setStyle(background);
result.addEventFilter(MouseEvent.MOUSE_RELEASED, restore);
}

// Need to attach TT to the specific button, not the common jfx_node Pane
TooltipSupport.attach(result, model_widget.propTooltip());
Expand Down Expand Up @@ -323,7 +334,7 @@ private void handleActions(final List<ActionInfo> actions)
/** @param action Action that the user invoked */
private void handleAction(ActionInfo action)
{
// Keyboard presses are not supressed so check if the widget is enabled
// Keyboard presses are not suppressed so check if the widget is enabled
if (! enabled)
return;

Expand Down Expand Up @@ -428,10 +439,22 @@ private void updateColors()
{
foreground = JFXUtil.convert(model_widget.propForegroundColor().getValue());
if (model_widget.propTransparent().getValue())
{
// Set most colors to transparent, including the 'arrow' used by MenuButton
background = "-fx-background: transparent; -fx-color: transparent; -fx-focus-color: rgba(3,158,211,0.1); -fx-mark-color: transparent; -fx-background-color: transparent;";
pressed_background = background;
}
else
background = JFXUtil.shadedStyle(model_widget.propBackgroundColor().getValue());
{
final WidgetColor norm = model_widget.propBackgroundColor().getValue();
// Darker color when pressed
final WidgetColor press = new WidgetColor(norm.getRed()/2,
norm.getGreen()/2,
norm.getBlue()/2,
norm.getAlpha());
background = JFXUtil.shadedStyle(norm);
pressed_background = JFXUtil.shadedStyle(press);
}
}

@Override
Expand Down