question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to vertically center text?

See original GitHub issue

First of all to the creators/contributors, thanks so much for a great library.

I have create a GenericStyledArea that incorporates both text (using the default TextExt) and custom nodes. For example, one custom node renders some math:

Screen Shot 2021-05-28 at 4 49 55 AM

Problem is they are not vertically aligned.

The rendered math is a Canvas. If it were translated up or down, this introduces possible clipping. So I think the TextExt needs to be vertically centered, possible with an additional offset as well.

However, using the translateYProperty for the TextExt would also possibly cause clipping, unless it were bound to the height of the ParagraphBox. Even if it were bound to the height of the ParagraphBox, it would also need to consider how many line-wraps there are. This is way more complicated than setting the alignmentProperty of an HBox, for example.

Also, the vertical alighment method needs to be segment by segment, and generalize to multi-line cases.

I couldn’t find any vertical alignment property and a search for “vertical alignment” here comes up empty, so maybe not thinking about this correctly or maybe I’m searching the wrong terms.

Any ideas?

Here’s a more extreme case: Screen Shot 2021-05-28 at 5 09 36 AM

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
Jugencommented, May 28, 2021

First of all: VERY NICE !!! Unfortunately I don’t have an answer off the top of my head, but here is what I suggest.

Since RichTextFX basically just uses a JavaFX TextFlow control for the layout of nodes (in your case Text & Canvas) try experimenting with a plain TextFlow to get the alignment you want (in various scenarios if need be). Once to you get that right, then you should be able to apply the same technique to RichTextFX.

If you get what you want with TextFlow but can’t seem to get the same results with RichTextFX then post your TextFlow findings here and I’ll try and help if I can.

0reactions
Jugencommented, Jul 21, 2021

@mgroth0 hope you came right with this … please reopen if not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I vertically center text with CSS? - Stack Overflow
The CSS just sizes the <div> , vertically center aligns the <span> by setting the <div> 's line-height equal to its height, and...
Read more >
CSS Layout - Horizontal & Vertical Align - W3Schools
To center both vertically and horizontally, use padding and text-align: center : I am vertically and horizontally centered.
Read more >
How to Vertically Center Text with CSS - W3Docs
How to Vertically Center Text with CSS · Use the CSS vertical-align property · Use CSS Flexbox · Use the CSS display property...
Read more >
How to vertically center text with CSS ? - GeeksforGeeks
The CSS just sizes the div, vertically center aligns the span by setting the div's line-height equal to its height, and makes the...
Read more >
vertical-align - CSS: Cascading Style Sheets - MDN Web Docs
CSS Demo: vertical-align · To vertically align an inline element's box inside its containing line box. For example, it could be used to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found