Nez
Nez copied to clipboard
UI Label not wrapping
Entity UI = new Entity("UI");
UICanvas canvas = UI.addComponent(new UICanvas());
canvas.setRenderLayer(0);
Table t = canvas.stage.addElement(new Table());
t.setFillParent(true).center();
Label lbl = new Label("Hello world Hello world Hello world Hello world Hello world Hello world Hello world ");
lbl.setFontScale(4, 4);
lbl.setWrap(true);
lbl.setAlignment(Align.center);
t.add(lbl);
addEntity(UI);
I believe what you want to do here is set an explicit width for the label. It won't wrap if it doesnt have some barrier on the beginning/end to wrap from. Try setting lbl.fillParent
or an explicit width and see if that does the trick.
I've set the width to various values, like 200 and 400 and it doesn't seem to do anything.
lbl.fillParent moves the label all the way to the bottom right and I don't know how to work with that...
And as far as I can tell, it doesn't look like it's wrapping still.
I think I see what is happening here. The label width calculation wasnt correct when wrapping was set. I pushed a small change to the wrapped-labels branch that should fix things but it needs some testing on other conditions to be certain.
I just discovered that setting the width of the cell fixes this.
t.add(lbl).width(Screen.width);
It seems like these lines may lead to the culprit: https://github.com/prime31/Nez/blob/30edddadf9ef75ca456561fee1c1a96f55ce63ad/Nez.Portable/UI/Containers/Table.cs#L992-L1000
c.elementWidth
is returning 0 even though the label's width itself is not 0.