Skip to content

Commit d0457d8

Browse files
committed
fix expanded in some scenarios
1 parent e19c18f commit d0457d8

4 files changed

Lines changed: 32 additions & 17 deletions

File tree

src/main/java/com/cleanroommc/modularui/test/GLTestGui.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.cleanroommc.modularui.api.drawable.IDrawable;
44
import com.cleanroommc.modularui.api.drawable.IKey;
5-
import com.cleanroommc.modularui.drawable.GuiDraw;
65
import com.cleanroommc.modularui.drawable.GuiTextures;
76
import com.cleanroommc.modularui.drawable.Rectangle;
87
import com.cleanroommc.modularui.screen.CustomModularScreen;
@@ -45,27 +44,35 @@ public class GLTestGui extends CustomModularScreen {
4544
public @NotNull ModularPanel buildUI(ModularGuiContext context) {
4645
this.ro1 = new RenderObject();
4746
this.ro2 = new RenderObject();
47+
this.ro1.type = Type.ITEM;
48+
this.ro1.lighting = Lighting.GUI_ITEM;
49+
this.ro1.texture = true;
4850
return new ModularPanel("gl_test")
4951
.size(250)
5052
.padding(7)
5153
.child(Flow.column()
54+
.debugName("main col")
5255
.child(Flow.row()
56+
.debugName("config row")
5357
.fullWidth()
5458
.coverChildrenHeight()
5559
.child(buildRenderObjectConfig(this.ro1)
56-
.marginRight(2))
60+
.debugName("config left col"))
5761
.child(new Rectangle().setColor(Color.TEXT_COLOR_DARK).asWidget()
62+
.debugName("separator")
5863
.width(1)
64+
.margin(2, 0)
5965
.fullHeight())
6066
.child(buildRenderObjectConfig(this.ro2)
61-
.marginLeft(2)))
62-
.child(createPreview().expanded()));
67+
.debugName("config right col")))
68+
.child(createPreview().expanded().fullWidth().debugName("preview")));
6369

6470
}
6571

6672
private Flow buildRenderObjectConfig(RenderObject ro) {
6773
return Flow.column()
68-
.widthRel(0.5f)
74+
//.widthRel(0.5f)
75+
.expanded()
6976
.coverChildrenHeight()
7077
.child(new CycleButtonWidget()
7178
.value(new EnumValue.Dynamic<>(Type.class, () -> ro.type, val -> ro.type = val))
@@ -159,21 +166,24 @@ public void draw(GuiContext context, int x, int y, int width, int height, Widget
159166
GlStateManager.pushMatrix();
160167
GlStateManager.translate(0, 0, zLevel);
161168
if (depth) GlStateManager.enableDepth();
169+
else GlStateManager.disableDepth();
162170
if (blend) GlStateManager.enableBlend();
171+
else GlStateManager.disableBlend();
163172
if (texture) GlStateManager.enableTexture2D();
173+
else GlStateManager.disableTexture2D();
164174
lighting.enable.run();
165175
type.render.draw(context, x, y, width, height, widgetTheme);
166176
lighting.disable.run();
167-
if (texture) GlStateManager.disableTexture2D();
168-
if (blend) GlStateManager.disableBlend();
169-
if (depth) GlStateManager.disableDepth();
177+
GlStateManager.disableTexture2D();
178+
GlStateManager.disableBlend();
179+
GlStateManager.disableDepth();
170180
GlStateManager.popMatrix();
171181
}
172182
}
173183

174184
private enum Type {
175-
NONE((ctx, x, y, w, h, wt) -> {}),
176-
TEXTURE((ctx, x, y, w, h, wt) -> GuiDraw.drawTexture(x, y, w, h, 0f, 0f, 1f, 1f)),
185+
NONE(IDrawable.EMPTY),
186+
TEXTURE(GuiTextures.MUI_LOGO),
177187
ITEM(GLTestGui::drawItem),
178188
COLOR(GLTestGui::drawColor);
179189

@@ -183,7 +193,7 @@ private enum Type {
183193
}
184194

185195
private enum Lighting {
186-
NONE(() -> {}, () -> {}),
196+
NONE(GlStateManager::disableLighting, GlStateManager::disableLighting),
187197
NORMAL(GlStateManager::enableLighting, GlStateManager::disableLighting),
188198
STANDARD(RenderHelper::enableStandardItemLighting, RenderHelper::disableStandardItemLighting),
189199
GUI_ITEM(RenderHelper::enableGUIStandardItemLighting, RenderHelper::disableStandardItemLighting);

src/main/java/com/cleanroommc/modularui/widget/WidgetTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ private static boolean resizeWidget(IWidget widget, boolean init, boolean onOpen
310310
if (widget.hasChildren()) {
311311
anotherResize = new ArrayList<>();
312312
for (IWidget child : widget.getChildren()) {
313-
if (init && expandAxis != null) child.flex().checkExpanded(expandAxis);
313+
if (init) child.flex().checkExpanded(expandAxis);
314314
if (!resizeWidget(child, init, onOpen)) {
315315
anotherResize.add(child);
316316
}

src/main/java/com/cleanroommc/modularui/widget/sizer/DimensionSizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public void applyMarginAndPaddingToPos(IGuiElement parent, Area area, Area relat
309309
}
310310

311311
private int calcSize(Unit s, Box padding, int parentSize, boolean parentSizeCalculated) {
312-
if (this.coverChildren) return 18; // placeholder value
312+
if (this.coverChildren || this.expanded) return 18; // placeholder value, size is calculated externally
313313
float val = s.getValue();
314314
if (s.isRelative()) {
315315
if (!parentSizeCalculated) return (int) val;

src/main/java/com/cleanroommc/modularui/widget/sizer/Flex.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import net.minecraft.inventory.Slot;
1414

1515
import org.jetbrains.annotations.ApiStatus;
16+
import org.jetbrains.annotations.Nullable;
1617

1718
import java.util.List;
1819
import java.util.function.DoubleSupplier;
@@ -326,9 +327,13 @@ public boolean hasFixedSize() {
326327
}
327328

328329
@ApiStatus.Internal
329-
public void checkExpanded(GuiAxis axis) {
330-
if (axis.isHorizontal()) this.x.setExpanded(this.expanded);
331-
else this.y.setExpanded(this.expanded);
330+
public void checkExpanded(@Nullable GuiAxis axis) {
331+
this.x.setExpanded(false);
332+
this.y.setExpanded(false);
333+
if (this.expanded && axis != null) {
334+
if (axis.isHorizontal()) this.x.setExpanded(true);
335+
else this.y.setExpanded(true);
336+
}
332337
}
333338

334339
@Override
@@ -549,4 +554,4 @@ private Unit getWidth() {
549554
private Unit getHeight() {
550555
return this.y.getSize(this.parent);
551556
}
552-
}
557+
}

0 commit comments

Comments
 (0)