Nez icon indicating copy to clipboard operation
Nez copied to clipboard

UI Label not wrapping

Open Remixful opened this issue 6 years ago • 4 comments

            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);

image

Remixful avatar Jan 11 '19 17:01 Remixful

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.

prime31 avatar Jan 11 '19 23:01 prime31

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... image

And as far as I can tell, it doesn't look like it's wrapping still.

Remixful avatar Jan 12 '19 04:01 Remixful

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.

prime31 avatar Jan 12 '19 04:01 prime31

I just discovered that setting the width of the cell fixes this. t.add(lbl).width(Screen.width);

image

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.

Remixful avatar Jan 12 '19 05:01 Remixful