-
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
How to set padding for text from borders of editable area? #255
Comments
Per this CSS tutorial, shouldn't you write something like this: .styled-text-area .navigator {
-fx-padding: 5px;
} or perhaps this: .styled-text-area > .navigator {
-fx-padding: 5px;
} |
Nope, I inspected CSS classes and styles using ScenicView - CSS from my first comment correctly set padding to |
Are you adding the style sheet to the Scene? |
What about this per the styled-text-area.css file .styled-text-area .paragraph-box .paragraph-text {
-fx-padding: 5px;
} |
|
The right CSS to use would be .styled-text-area {
-fx-padding: 5px;
} Not sure why you are trying to access Navigator or ParagraphBox. But it doesn't work anyway. Workaround: Wrap the area in some Pane and set padding on that. Fix: In virtualFlow.resize(getWidth(), getHeight()); to Insets ins = getInsets();
virtualFlow.resizeRelocate(ins.getLeft(), ins.getTop(), getWidth() - ins.getLeft() - ins.getRight(), getHeight() - ins.getTop() - ins.getBottom()); Comment: It is super easy to forget to account for some kind of JavaFX quirk, such as padding (insets). In |
Thank you for your reply. I tried setting padding on I will try using your proposed fix tomorrow. |
Good point! This fits well with my comment about breaking things apart. Turns out in the master branch @JordanMartinez already took scrollbars out of StyledTextArea, and into a wrapper node VirtualizedScrollPane. This way, if you add padding to StyledTextArea, the padding stays inside the scrollbars. |
Yeah, we really need to release version 0.7 .... @kuc I'm sorry for not reading your comments more carefully. Also, CSS is something with which I'm not well versed. Glad Tomas could help you out though! |
I tried described fix on version from master branch, after wrapping Also, SNAPSHOT version of
😞 |
I just tested the snapshot version of SCTA and those issues did not arise. Also, what do you mean by |
That's weird. I only updated library version and this all problems showed up...
I'm talking about removed |
Ah! Ok. Since so many other developers needed access to the skin to further modify things, we decided to change how that works. |
Thus, |
My guess is that the top and bottom inset should only be factored into the Edit: made code account for possibility where top and bottom are both visible Insets ins = getInsets();
ObservableList<Cell<Paragraph<PS, S>>> cells = virtualFlow.visibleCells();
boolean topVisible = cells.contains(virtualFlow.getCell(0));
boolean bottomVisible = cells.contains(
// since no way to know what the last cell index is in virtualFlow
// just use the number of paragraphs
virtualFlow.getCell(getParagraphs().size() - 1)
);
double y, height;
if (topVisible) {
y = ins.getTop();
height = bottomVisible
? getHeight() - ins.getTop() - ins.getBottom()
: getHeight() - ins.getTop();
} else {
y = 0;
height = bottomVisible
? getHeight() - ins.getBottom()
: getHeight();
}
virtualFlow.resizeRelocate(
ins.getLeft(),
y,
getWidth() - ins.getLeft() - ins.getRight(),
height
); |
I really only needed But after removing Seems that implementation of these methods were part of |
Yeah, that does present a problem.... I'm not sure if this will still be supported underneath this new design structure as this is a base off of which others can build. I'll let @TomasMikula answer that. In case it won't be, there is the focusFX library |
Per Tomas' comment in #234:
I don't think it will be supported. |
I found a way how to reproduce this bug: #257 |
@JordanMartinez I tested your code and currently it changes nothing in comparison to @TomasMikula proposed fix 😞 |
Really? I wonder why.... |
Even in JavaFX, these are private API, so you were not supposed to call them in the first place. Btw, some sort of public focus traversal API has a good chance to be added in JavaFX 9 (see JDK-8091673). I haven't really looked at it, but hopefully it will be something that we can then support. |
Using private API, you can override the Tab to do area.impl_traverse(com.sun.javafx.scene.traversal.Direction.NEXT); Taken from BehaviorBase. Addendum: This will stop working in JavaFX 9, but then again, there should be a public API by then. |
BTW: I find out that cell is marked as "invisible" only when it's 100% displayed offscreen.
Ok, I can live without this... Next/previus focus targets could be always hardcoded.
I don't know, but I think that I just found the best possible solution. @TomasMikula @JordanMartinez Do you think that this would be much work to add that two CSS classes? Because I don't know RichTextFX codebase well, so maybe you could fix that more quickly than me. |
Gotcha...
If we implemented that idea, it'd probably be better to have an |
I don't think so, how would you style the last paragraph with this? |
@kuc It could be implemented, and you would be able to get the desired visual output, but I don't think that it is "the best possible solution". It will make the padding a property of a paragraph, while logically it is a property of the whole document (so should be handled by some node containing containing the whole document). I think it should be handled by the Still, the solution you propose might be a faster way to get the desired result. |
I mean "best possible solution" = "works as excepted without any quirks (maybe....)" 😉 You are right, but because whole document is virtualized, some "obvious" things can be not easy to implement in straightforward way. |
Oh, right. I forgot about that 😄 |
OK, there you go. There are now pseudo classes .styled-text-area .paragraph-box:first-paragraph .paragraph-text {
-fx-padding: 10 0 0 0;
}
.styled-text-area .paragraph-box:last-paragraph .paragraph-text {
-fx-padding: 0 0 10 0;
} |
Wow, thank you so much! 😃 BTW, seems that with different paragraphs heights, virtual scroll pane does not allow to fully scroll up/down using arrow keys - but this a minor issue, and probably fixable by adding some listener somewhere. Because list of workarounds is somewhat complete, I think that I can close this issue. |
The intended behavior of |
Both styles should be used. But if there is some conflict, as is the case in the padding example I gave, then the latter will take precedence. If JavaFX supported ... .paragraph-box:first-paragraph:last-paragraph ... {
...
} to be more explicit about what you want in the case when there is only one paragraph, and since this is a more specific selector than the others, it will take precedence. |
This explains it all. Moreover, I just tested
Yes, they are both correctly set on node. But in your stylesheet example they have the same priority, so last recently defined style will be used.
Thanks for suggestion, I am aware of this :) |
I tried this
but it not worked 😕
The text was updated successfully, but these errors were encountered: