Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: vei on December 28, 2012, 02:39:25 AM
-
Hi, sorry if this question has been asked before.
How can I make justify alignment in UILabel? Can I put it as future feature request?
Thanks a lot!
-
There is no justify alignment with UILabel, and unfortunately it's not currently on the roadmap.
-
Hi!
I´m currently in the need of having this feature too, I don´t mind implementing it myself, but I will need some advice on how to proceed and what are the suggest steps.
Thanks!
-
Maybe using different UILabels with different Pivots.
Or also using various UIAnchors, one for each Widget Group.
In my images bellow i used one UIAnchor for each Widget Group.
My technique was used to Sprites, but works pefectly to UILabels too.
-
I did it before by modifying Print function from UIFont.cs.
Basically it's similar with Align function that's applied when the alignment is not Alignment.Left.
Divide the "extra spacing" left in that particular line by the number of space character.
Then just adjust the x-position of each character's buffer "verts" accordingly with that extra spacing.
-
how can we find the extra line spacing?
It would be a big help for us to know how you did the justification of the Text :)
thank you sir
-
Hello there,
Thanks for clues, but creating text justification in UIFont seems really complicate for a non coder like me... I am so annoyed this function is not integrated in NGUI. Why isn't on the road map ? Any help would be highly useful here.
-
Because NGUI is not a word processor. It's a game UI system.
-
Well, I could cite several game that use huge amount of justified text... I could understand if there is a technical difficulty on doing this, but I am a bit surprised by this rude answer. I spent 90 € on your asset, to hear that I am using Unity as a word processor... Bad publicity.
-
But that's the thing though, if it was a frequently requested feature, I would see no reason not to add it. I've only had this question asked maybe once every 6 months, which tells me that few games need this feature. I'm a solo developer with very limited amount of time and resources, so I have to focus on higher priority tasks -- such as redoing the font system within Unity itself in order to make it work with dynamic fonts correctly. I don't intend to be rude -- merely realistic.
-
I understand better now. Thanks for your answer.
-
Hello,
Sorry for necro'ing an old thread, but I figured it'd be better than creating a new one.
I would also like to have text justification for some UILabels in my game. Texts can look pretty awful if they're a bit lengthy (like more than 2 lines) and not justified properly.
Is it still not planned to add this feature into NGUI ? If not, I completely understand, although if you have suggestions as how you think it'd be done best in your code, I'd be happy to hear them.
Thanks in advance
-
Still no plans at this time.
-
I will add my vote for needing text justification/alignment in NGUI. Working on a sim for the US Navy and as you would guess they like things to line up nicely in the text portion of the sim instructions.
Thanks!
-
Justify would be very nice. I've had to mix in another library (TextBox) just so I can do a proper opening crawl (http://en.wikipedia.org/wiki/Star_Wars_opening_crawl) in our game. I would *really* love to replace that with NGUI text instead.
-
I will add to the vote for text justification tools! That has been assumed on almost ALL text related programs for many years...just say'n...not trying to complain, but...guess I just did! ;)
-
Planned. Soon. :)
-
Yay!! :)
-
Any chance the character spacing added recently is related to justify? ;D
-
Sorry no... I haven't tackled this yet. Character spacing is just that -- spacing on every single character. Justification involves adding spaces only between certain characters, so it's basically a "post-process" on a line of text -- so it's a different task.
-
Wow. NGUI seems so feature packed... it's sort of amazing that I can't justify my text :-\
-
This would be great!
-
Bump. Maybe you could point me to the best place to implement this and I could take a crack at it?
-
Horizontal text alignment is done in a single function: NGUIText.Align. The tricky thing about justified alignment is that you'd want to modify vertices 4 at a time rather than individually, and to position them in a manner that spaces them out. The reason I haven't done this already is because Unity's TextAlignment enum doesn't have "justified" in it. Just left, center and right. My own fault for using it in the first place I suppose.
-
It looks as though you aren't using that enum in a way where it would be relatively painless to switch it out for a custom enum. It's not a field on any of the UI widgets, etc. at least, so no prefab issues with switching types.
-
+1 for text justification
I read in the thread that it is planned, and I'm eager to have it integrated, as I'll need it very soon :)
-
I created a quick hack for it. It works but haven't tested for speed with large text. It also overwrites the Left enum, but could easily add a Justify enum
UIFont.cs
public void Print
add the following
int textLength = text.Length;
// lets figure out justification here should probably do it earlier if this is too slow
int maxlineWidth = 0;
int currentLineWidth = 0;
int numberSpaces = 0;
List<int> lineWidths = new List<int>();
List<int> lineSpaces = new List<int>();
for (int i = 0; i < textLength; ++i) {
char c = text;
if (c == '\n') {
lineWidths.Add(currentLineWidth);
lineSpaces.Add(numberSpaces);
if (currentLineWidth > maxlineWidth)
maxlineWidth = currentLineWidth;
currentLineWidth = 0; numberSpaces = 0;
}
else {
if (c == ' ')
numberSpaces++;
BMGlyph glyph = mFont.GetGlyph(c);
if (glyph != null)
currentLineWidth += glyph.advance;
}
}
int lineArrayPos = 0;
int spaceExtra = 0;
if (lineWidths.Count > 0)
spaceExtra = (maxlineWidth - lineWidths[lineArrayPos]) / lineSpaces[lineArrayPos];
then inside if (c == '\n')
lineArrayPos++;
if (lineArrayPos < lineWidths.Count && lineSpaces[lineArrayPos] != 0)
spaceExtra = (maxlineWidth - lineWidths[lineArrayPos]) / lineSpaces[lineArrayPos];
else
spaceExtra = 0;
then find later down
if (c == ' ')
{
x += mSpacingX + glyph.advance + spaceExtra; // added spaceExtra at end
prev = c;
continue;
}
-
Neat! :)
-
The trick is also modifying PrintCaretAndSelection and PrintCharacterPositions, and making sure it all works with spacing, font scale adjustments, and UIRoot scale adjustments. But still, nice, thanks.
-
Hi, I became a member just so I could request justified text. I am UI artist for a game company, and my colleagues and I often wish we could justify text. It's a part of graphic design, so it is often required for layouts. Thanks!
-
Already added in 3.5.0.
-
And I forgot to say thank you. So, "Thank you, Aren." :)
-
Hi there,
I was wondering if some options could be added to the justification text feature. Right now the spacing and the justify option seem to be in some sort of competition, which in some cases gives correctly justified text and in some other cases awfully justified text, where the space between characters varies widely from a word to another. I suppose this variation is due to the justify option that stretches the words, sometimes crossing the specified spacing.
Maybe some advice to use the justify option at best ?
-
Justification will always be uneven by the nature of it, as the characters need to be aligned to pixels in order to appear crisp. For example a line of 10 characters with a label width of 50, but characters only take a total width of 44 means 6 pixels need to be added in between of characters. You can't just separate each of the 10 characters by 0.6 as that will make them blurry. Instead, only 6 of the 10 characters will gain spacing between them.