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 support for a prompt / placeholder text when area is empty #256

Closed
alt-grr opened this issue Feb 17, 2016 · 21 comments · Fixed by #899
Closed

Add support for a prompt / placeholder text when area is empty #256

alt-grr opened this issue Feb 17, 2016 · 21 comments · Fixed by #899

Comments

@alt-grr
Copy link

alt-grr commented Feb 17, 2016

This would be a nice feature. Standard TextArea allows to set it.

@TomasMikula
Copy link
Member

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 StyledTextArea yourself. It seems to me that you already can. You can register mouse listeners, text length listeners, and clear the undo-manager's history. That should be all that you need.

@alt-grr
Copy link
Author

alt-grr commented Feb 18, 2016

I personally don't think that very common feature of displaying placeholder is "unnecessary overhead". Implementing it by manipulating of setText() is possible, but you must account for many corner cases of accidental use of placeholder text as legitimate user input.

Another workaround could be using dynamically-created transparent background image with text on it. Or maybe using StackPane somehow.

@JordanMartinez
Copy link
Contributor

Another workaround could be using dynamically-created transparent background image with text on it. Or maybe using StackPane somehow.

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)
});

@alt-grr
Copy link
Author

alt-grr commented Feb 19, 2016

Something like this?

Hmm, I think it's actually very close 😃
But Text must be behind StyledTextArea, because with this implementation you could set focus on it. I will try to post here some more complete example in the future.

@JordanMartinez
Copy link
Contributor

with this implementation you could set focus on it

Good point.
However, if it is behind the StyledTextArea, will it even appear in a StackPane? StyledTextArea's background is white, so wouldn't that whiteness be displayed over the Text? If one reconfigured the pickNode code, it might get around that issue.

Now, if you use something other than StackPane, I guess you wouldn't have the above issue.

@ghost
Copy link

ghost commented Feb 19, 2016

Why not have it as a popup, placed at index 0? Richtext supports popup.
On Feb 19, 2016 10:20 AM, "JordanMartinez" [email protected] wrote:

with this implementation you could set focus on it

Good point.
However, if it is behind the StyledTextArea, will it even appear in a
StackPane? StyledTextArea's background is white, so wouldn't that
whiteness be displayed over the Text? If one reconfigured the pickNode
code, it might get around that issue.

Now, if you use something other than StackPane, I guess you wouldn't have
the above issue.


Reply to this email directly or view it on GitHub
#256 (comment)
.

@JordanMartinez
Copy link
Contributor

Hmm.... that's not a bad idea.

@ghost
Copy link

ghost commented Feb 19, 2016

Something like:
Iisten to text change property, if length is 0, set popup window and
show-will be at zero index. Else, remove.
On Feb 19, 2016 10:28 AM, "JordanMartinez" [email protected] wrote:

Hmm.... that's not a bad idea.


Reply to this email directly or view it on GitHub
#256 (comment)
.

@alt-grr
Copy link
Author

alt-grr commented Feb 19, 2016

That's terrible idea IMO, this has even worse problems with focus.

However, if it is behind the StyledTextArea, will it even appear in a StackPane? StyledTextArea's background is white, so wouldn't that whiteness be displayed over the Text?

Why not set it to transparent color then? I read that's a common use case for StackPane, to layering multiple controls into one.

@ghost
Copy link

ghost commented Feb 19, 2016

Oops. Sorry for proposing a "terrible" idea!

@JordanMartinez
Copy link
Contributor

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?

Why not set it to transparent color then? I read that's a common use case for StackPane, to layering multiple controls into one.

Oh. Ok! I haven't needed to do stuff like that yet, so I didn't know that 😄

@alt-grr
Copy link
Author

alt-grr commented Feb 19, 2016

@melkhaldi
Huh? Don't be sorry, it's just my opinion that trying to solve this in that way would be unreliable. 😉

@JordanMartinez
Copy link
Contributor

@TomasMikula

It seems to me that you already can. You can register mouse listeners, text length listeners, and clear the undo-manager's history. That should be all that you need.

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.

@TomasMikula
Copy link
Member

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.

@alt-grr
Copy link
Author

alt-grr commented Feb 21, 2016

Resolved using this code: https://gist.github.com/kuc/d827edf158bb3cc31ef0 😊

@alt-grr alt-grr closed this as completed Feb 21, 2016
@alt-grr
Copy link
Author

alt-grr commented Nov 17, 2016

https://github.com/TomasMikula/RichTextFX/wiki/Dropped-but-Now-Desired-Features

Dropped but Now Desired Features (...) pull requests that implement them are desired:

  • Prompt.

@TomasMikula So, I if would integrate above code in RichTextFX, you will be happy to merge it?

@JordanMartinez
Copy link
Contributor

@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.

@alt-grr
Copy link
Author

alt-grr commented Nov 17, 2016

@JordanMartinez OK, so I could think about good implementation of prompt/placeholder in a free time 🙂
Code posted above works, but has some limitations (e.g. no wordwrapping of placeholder)

@JordanMartinez
Copy link
Contributor

@kuc Probably, but I'm also not Tomas 😄

@alt-grr
Copy link
Author

alt-grr commented Nov 17, 2016

@JordanMartinez I know 😉

@JordanMartinez
Copy link
Contributor

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.

@JordanMartinez JordanMartinez changed the title Prompt/placeholder text Add support for a prompt / placeholder text when area is empty Mar 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants