B4J Question Wrap Text without Breaking the Words

xulihang

Active Member
Licensed User
Longtime User
I am using TextFlow as a text engine to render text into images. I am having a problem that if I enable text wrapping and its width is not enough, it will break words. I wonder if there is a way to avoid breaking the words.

wrapped.jpg


If this is not possible, then I may have to create my own text engine.

BCTextEngine seems a good alternative as well.
 

xulihang

Active Member
Licensed User
Longtime User
My test project.
 

Attachments

  • TextWrap.zip
    2.8 KB · Views: 33
Upvote 0

xulihang

Active Member
Licensed User
Longtime User
I think there is a workaround. I can measure the longest word's length and make it as the minimum width for the TextFlow.

B4X:
Dim c As B4XCanvas
c.Initialize(MainForm.RootPane)
Dim minWidth As Int = Ceil(c.MeasureText("together ",fx.DefaultFont(15)).Width)
 
Last edited:
Upvote 0

xulihang

Active Member
Licensed User
Longtime User
1715063403663.png


Controls like TextArea also have this problem.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
What behaviour would you prefer? I cannot think of an alternative that would not, in some circumstances, bring equal disadvantages.
 
Upvote 0

xulihang

Active Member
Licensed User
Longtime User
What behaviour would you prefer? I cannot think of an alternative that would not, in some circumstances, bring equal disadvantages.
TextArea having this behavior is fine.

But in my case, I need to use TextFlow to render text for manga translation and it is not good to break the words.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Okay - I can understand that you have a problem, but I felt that you were being too hard on the view designer. I think that it is reasonable to expect the view designer to optimise for 99% of the usage cases and allow us to sort out our own special cases when they occur, as you have done. I can see situations where a different solution might be preferred.
 
Upvote 0
Top