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.

I'd like a width property that is like a textbox width for alignment purposes

See original GitHub issue

I’m attempting to use troika-three-text to draw multiline text entities of CAD files. I want to give it a specific textbox width for alignment purposes.

Say the maxWidth is 100, the alignment is center, and the maximum that any line actually covers is 50. Currently, the text produced by troika-three-text is centered as if the “text box” is 50 wide, not 100 wide. Thus it is shifted to the left of it’s intended position.

It seems like this might be an easy thing to do. This line of code uses maxLineWidth which is the longest line of text (not the explicitly set maxWidth). I propose we add a width field to the options that effectively forced maxLineWidth to the given value.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bzuillsmithcommented, Sep 27, 2021

Got it, makes sense. It definitely sounds like this will work to get the position without a sync callback and bounding box. The only downside I can think of is that the position won’t reflect the original CAD anchor point anymore, but it’s probably not a big deal. Currently what I’m working on is only a viewer, though some people have been forking it to make it interactive and add features.

0reactions
lojjiccommented, Sep 27, 2021

OK, if you run into issues let me know and I’ll think how to improve it for you.

But I do think that with your original example of a “textbox” with a fixed width of 100, this should give equivalent behavior without having to measure the text bounds:

const textBoxWidth = 100
text.maxWidth = textBoxWidth
text.anchorX = 'center'
text.position.x = xPosFromCAD + textBoxWidth / 2

You can just think of anchorX as what horizontal position in the text you want to remain stable. If you’re center-aligning text in a fixed-width box, you want that point to be the text’s center. And then you just position that anchor point at the fixed-width box’s centerpoint.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS Box Alignment - CSS: Cascading Style Sheets | MDN
In this example using Grid Layout, there is extra space in the grid container after laying out the fixed width tracks on the...
Read more >
C38: Using CSS width, max-width and flexbox to fit labels and ...
Define the width and max-width property for labels and inputs so they enlarge or shrink in the available space and respond to zoom...
Read more >
c# - Bootstrap textbox width and alignment changes when ...
When I minimize the window the textbox appears on top of other controls and width of the textbox changes too. I tried below...
Read more >
How to Align Labels Next to Inputs - W3docs
Let's see an example, where we also add placeholder, id and name attributes on inputs and for attribute on labels. As a result,...
Read more >
CSS · Bootstrap
Use .container for a responsive fixed width container. ... Predefined grid classes like .row and .col-xs-4 are available for quickly making grid layouts....
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