#Adding Widgets to Screen

21 messages · Page 1 of 1 (latest)

novel fiber
#

Hi, I'm trying to add a DirectionalLayoutWidget to my Screen using addDrawableChild() inside init(), but I'm getting a weird error.
The code is:

test.add(new TextWidget(Text.of("test 1"), MinecraftClient.getInstance().textRenderer));
test.add(new TextWidget(Text.of("test 2"), MinecraftClient.getInstance().textRenderer));
addDrawableChild(test);```
The error I get is: 
```Required type: T
Provided: DirectionalLayoutWidget
reason: no instance(s) of type variable(s) exist so that DirectionalLayoutWidget conforms to Element```
What should I do to fix this issue?
shrewd gorge
#

what mc version?

#

oh nvm that doesn't

#

DirectionalLayoutWidget doesn't meet the constraints imposed in addDrawableChild

dim hazel
#

you dont use layouts like that

shrewd gorge
#

yeah what these layout widgets do is position the elements within them. you then need to manually render those elements

dim hazel
#

test.forEachChild(this::addDrawableChild);

shrewd gorge
#

exactly this ^

dim hazel
#
  • initTabNavigation override
#

that yarn name is so bad 🙂

novel fiber
#

Well that is not really intuitive now is it.

#

but then how should I use the Widget for them to be side by side? kinda tought this is what it would do..

dim hazel
#

do you have override for that initTabNavigation?

novel fiber
#

can't say I do

dim hazel
#

you have to call that method too (after that forEachChild line)

shrewd gorge
#

hmm i don't do that though, things work well for me.

novel fiber
shrewd gorge
#

also call test.refreshPositions before forEach line

dim hazel
novel fiber
#

Well I don't need to overide initTabNavigation if it will only call refreshPositions do I?

shrewd gorge
#

try and see ~ i don't override it Clueless