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

Add blinking effect #1252

Open
PavelTurk opened this issue Nov 11, 2024 · 0 comments
Open

Add blinking effect #1252

PavelTurk opened this issue Nov 11, 2024 · 0 comments

Comments

@PavelTurk
Copy link
Contributor

PavelTurk commented Nov 11, 2024

In JavaFX 23 CSS transition was added. At the same time CSS animation issue was closed since animated transitions in CSS were added (see comments). So, I think we can state than CSS animation won't be implemented in the next 99 years.

This is an example of blinking affect in TextFlow using transitions:

public class JavaFxTest10 extends Application {

    public static final String CSS = "data:text/css," +
        """
        .myText{
           -fx-font-size:20px;
           -fx-opacity: 1;
        }

        .myText:blink{
            -fx-opacity: 0;
        }
        """;

    private static final String TEXT = "Some text.";

    @Override
    public void start(Stage primaryStage) {
        var blink = PseudoClass.getPseudoClass("blink");
        var text = new Text(TEXT);
        text.setStyle("transition-property: -fx-opacity;transition-duration: 0.5s;");
        text.getStyleClass().add("myText");
        text.addEventHandler(TransitionEvent.END,
                event -> text.pseudoClassStateChanged(blink, !text.getPseudoClassStates().contains(blink)));

        var textFlow = new TextFlow(text);
        VBox root = new VBox(textFlow);
        Scene scene = new Scene(root, 400, 200);
        scene.getStylesheets().add(CSS);

        primaryStage.setScene(scene);
        primaryStage.setOnShown(e -> text.pseudoClassStateChanged(blink, true));
        primaryStage.show();

    }

    public static void main(String[] args) {
        launch(args);
    }
}

And result:
Peek 2024-11-11 12-51

And I suggest to add blinking affect to RichTextFX. As I understand RichTextFX internally creates distinct nodes for text of different style classes (StyleClassedTextArea) and different styles (InlineCssTextArea). If so, we can add CSS declaration like -rtfx-blink-rate: <duration>ms; and If RichTextFX detects this declaration in style or style class then it will add TransitionEvent.END event handler to this node as in the example with TextFlow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant