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

Styling the caret (not just colour) #397

Closed
gbmhunter opened this issue Nov 17, 2016 · 8 comments
Closed

Styling the caret (not just colour) #397

gbmhunter opened this issue Nov 17, 2016 · 8 comments

Comments

@gbmhunter
Copy link

gbmhunter commented Nov 17, 2016

When using a TextFlow node, I was able to simulate a blinking "terminal" (insert, block-shaped) style caret by adding a Text object as follows:

    caretText = new Text("█");
    caretText.setFill(Color.LIME);

    // Add an animation so the caret blinks
    FadeTransition ft = new FadeTransition(Duration.millis(200), caretText);
    ft.setFromValue(1.0);
    ft.setToValue(0.1);
    ft.setCycleCount(Timeline.INDEFINITE);
    ft.setAutoReverse(true);
    ft.play();

    textFlow.getChildren().add(caretText)

This produced the blinking caret as seen in the demo image on the page: http://mbedded-ninja.github.io/NinjaTerm/

Is there any way to get the same functionality with RichTextFX?

@alt-grr
Copy link

alt-grr commented Nov 17, 2016

Try setting -fx-stroke-width on caret in CSS.

@gbmhunter
Copy link
Author

Hmmm, that almost works, except it is little high and it collides with the last letter (most likely due to it's center being positioned at the right-most edge of the last letter).

image

@alt-grr
Copy link

alt-grr commented Nov 17, 2016

Yup, there is no checks for caret width:
https://github.com/TomasMikula/RichTextFX/blob/169967a71709c80a36db825cacd617ce9d622ee8/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java#L83

Allowing custom caret width would be a nice start. Custom caret shapes and positioning (e.g. _-shaped caret under current character for overwrite input mode) would be the best option, but that's a lot of work.

@gbmhunter
Copy link
Author

Hmmm I have had a quick look at the code, what are some good pointers to get started with adding some basic functionality around the caret?

@JordanMartinez
Copy link
Contributor

@gbmhunter Are you still interested in taking a look at this?

@gbmhunter
Copy link
Author

@JordanMartinez Sorry no not anymore. After diving into the source code for a bit I realised it would be a decent amount of work to get up to speed with the architecture and implement the changes, and opted to go for a JavaFX WebView/HTML textarea approach instead.

@PavelTurk
Copy link
Contributor

Could anyone say if it is possible to set styles for caret using StyleClassedTextArea in 2022. Same problem - I need something like terminal.

@andy-goryachev-oracle
Copy link

just a suggestion - you could use Text/TextFlow.rangeShape() to draw the "caret", or at least to determine the geometry.

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

5 participants