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

Changing the text area height depending on fixed text size #405

Closed
sherzfel opened this issue Dec 11, 2016 · 11 comments
Closed

Changing the text area height depending on fixed text size #405

sherzfel opened this issue Dec 11, 2016 · 11 comments

Comments

@sherzfel
Copy link

Hello,

I need to have an styletextarea that has an high that depends on the text, that is written in once by initialization. The text is not editable and is written once by initialization. The width is fixed und the wrapping property is set to true. How can i calculate the desired high of the styledtextarea?

Please I need urgent help, because my boss is sitting on my table.

@sherzfel sherzfel changed the title Changing the text high depending on fixed text size Changing the text area high depending on fixed text size Dec 11, 2016
@JordanMartinez
Copy link
Contributor

I don't think anyone responded to this after you posted because they probably did not understand what your question was.

What do you mean by "a styled text area that has a high that depends on the text?" What do you mean by "high?" That's the part of your question that I do not understand.

@sherzfel
Copy link
Author

sherzfel commented Dec 13, 2016

I mean the height. I mean the number of the lines multiplicated with the style. Can you understand that?

@sherzfel sherzfel changed the title Changing the text area high depending on fixed text size Changing the text area height depending on fixed text size Dec 13, 2016
@JordanMartinez
Copy link
Contributor

You seem to be asking, "How do I set the StyledTextArea's height to change based on the font size of the area, so that (as I think this is the goal you are trying to reach) any given font size always adjusts the area's height so that at least a full x number lines are always displayed where x is the number of lines desired)?"

@sherzfel
Copy link
Author

Yes, that I want to know. The StyledTextArea is not editable.

@JordanMartinez
Copy link
Contributor

What are you using for the text style class? In other words, what is the second parameter in your area?

StyledTextArea<ParagraphStyle, TextStyle> area = //

What is TextStyle in this case?

@sherzfel
Copy link
Author

sherzfel commented Dec 14, 2016

I call the following constructor:

new StyleClassedTextArea(true).

That constructor call:

public StyleClassedTextArea(boolean preserveStyle) {
this(
new SimpleEditableStyledDocument<>(
Collections.emptyList(), Collections.emptyList()
), preserveStyle);
}

@JordanMartinez
Copy link
Contributor

Ok, so you're using Collection<String> as your style object and CSS to style the area. Ideally, you'd want to create an EventStream that handles this reactively:

EventStream<Double> fontSize = // parses CSS for font size
EventStream<Double> lineSpacing = // parses CSS for line spacing
EventStream<Integer> nLines = // constructed from a Var or something else
EventStream<Tuple3<Double, Double, Integer>> lineHeight = EventStreams.combine(fontSize, lineSpacing, nLines);

lineHeight.map(tuple3 -> {
    double size = tuple3._1;
    double spacing = tuple3._2;
    int numLines = tuple3._3;

    return (size + spacing) * numLines;
}).feedTo(area.minHeightProperty());

I'm not sure how to parse the CSS manually to get the required values, but does this give you a better idea for what you need to do next?

@sherzfel
Copy link
Author

sherzfel commented Dec 21, 2016

I am using the branch with the getParagraphLinesCount method. But it doesn't work. Either the getParagraphLineCount returns the number of signs if wrap text is true or it returns 1 if wrapText is false.

@iazarny
Copy link

iazarny commented Dec 22, 2016

@sherzfel Try to

Field field = FieldUtils.getField(codeArea.getClass(), "virtualFlow", true);
VirtualFlow oldVirtualFlow = (VirtualFlow) field.get(codeArea);
flow.visibleCells().size(); // guess, this is something, that you need 

@JordanMartinez
Copy link
Contributor

#501 may help with this as you don't need to use reflection to get the size of visible cells.

@Jugen
Copy link
Collaborator

Jugen commented Nov 5, 2020

Closed via PR 944

@Jugen Jugen closed this as completed Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants