-
Notifications
You must be signed in to change notification settings - Fork 236
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 support for a prompt / placeholder text when area is empty #256
Comments
Also, standard JavaFX controls' approach to versatility is blending in more and more features in hope they will cover most use cases. But they can never cover all use cases. Moreover, this approach poses unnecessary overhead for users that don't need this or that feature. (And I'm less concerned about memory or CPU overhead, than I am about the cognitive overhead needed to be able to use the control correctly.) My approach to versatility is breaking things apart, so that they can be recombined in different ways. I don't always do a great job of it on the first try, so please let me know if I can break something apart for you so that you can implement this feature on top of |
I personally don't think that very common feature of displaying placeholder is "unnecessary overhead". Implementing it by manipulating of Another workaround could be using dynamically-created transparent background image with text on it. Or maybe using |
Something like this? StackPane pane = new StackPane();
StyledTextArea area = // creation code;
pane.getChildren().add(area);
Text promptText = new Text(/* prompt string */);
// or perhaps setMargin would be better...
StackPane.setAlignment(promptText, Pos.TOP_LEFT);
area.lengthProperty().addListener((obs, ov, nv) -> {
if (nv == 0) {
pane.getChildren().add(promptText)
} else {
pane.getChildren().remove(promptText)
}); |
Hmm, I think it's actually very close 😃 |
Good point. Now, if you use something other than |
Why not have it as a popup, placed at index 0? Richtext supports popup.
|
Hmm.... that's not a bad idea. |
Something like:
|
That's terrible idea IMO, this has even worse problems with focus.
Why not set it to transparent color then? I read that's a common use case for StackPane, to layering multiple controls into one. |
Oops. Sorry for proposing a "terrible" idea! |
Why? It's a valid idea worth bringing up for discussion. If it happens not to work in this situation, so what?
Oh. Ok! I haven't needed to do stuff like that yet, so I didn't know that 😄 |
@melkhaldi |
Except that using the above approach would also clear out the undo history. If a user typed something, cleared it (prompt text appears), and then redid the undo, there's nothing to undo. This only becomes an issue if one types a large amount of text into the area (and has a large undo history), deletes everything, and then tries to undo (via redo) their deletion. |
I only imagined to display the prompt before the user types anything, not whenever the area becomes empty. But I agree that displaying a node with the prompt above or below the area is probably a better idea. |
Resolved using this code: https://gist.github.com/kuc/d827edf158bb3cc31ef0 😊 |
https://github.com/TomasMikula/RichTextFX/wiki/Dropped-but-Now-Desired-Features
@TomasMikula So, I if would integrate above code in RichTextFX, you will be happy to merge it? |
@kuc I rewrote that page because at least three of those features had been requested and it seemed that Tomas would be pleased if someone implemented them. So, I assumed that the prompt feature would be included as well. |
@JordanMartinez OK, so I could think about good implementation of prompt/placeholder in a free time 🙂 |
@kuc Probably, but I'm also not Tomas 😄 |
@JordanMartinez I know 😉 |
Since the other features in the "Dropped, but Now Desired Features" page already have their issues open elsewhere, I'm reopening this one so we can delete that wiki page. |
This would be a nice feature. Standard
TextArea
allows to set it.The text was updated successfully, but these errors were encountered: