Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizing fixes #31

Merged
merged 6 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.widget.sizer;
package com.cleanroommc.modularui.api;

public enum GuiAxis {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.cleanroommc.modularui.widget.sizer;
package com.cleanroommc.modularui.api.layout;

import com.cleanroommc.modularui.api.GuiAxis;
import com.cleanroommc.modularui.api.widget.IGuiElement;
import com.cleanroommc.modularui.widget.sizer.Area;

/**
* An interface that handles resizing of widgets.
*/
public interface IResizeable {

void initResizing();
Expand Down Expand Up @@ -60,4 +65,21 @@ default void setWidthResized(boolean v) {
default void setHeightResized(boolean v) {
setResized(isXCalculated(), isYCalculated(), isWidthCalculated(), v);
}

default void setResized(boolean b) {
setResized(b, b, b, b);
}

void setXMarginPaddingApplied(boolean b);

void setYMarginPaddingApplied(boolean b);

default void setMarginPaddingApplied(boolean b) {
setXMarginPaddingApplied(b);
setYMarginPaddingApplied(b);
}

boolean isXMarginPaddingApplied();

boolean isYMarginPaddingApplied();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.cleanroommc.modularui.api.widget;

import com.cleanroommc.modularui.api.ITheme;
import com.cleanroommc.modularui.api.layout.IResizeable;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.screen.viewport.GuiContext;
import com.cleanroommc.modularui.widget.sizer.Area;
import com.cleanroommc.modularui.widget.sizer.IResizeable;
import org.jetbrains.annotations.ApiStatus;

/**
* Base interface for gui elements. For example widgets.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.cleanroommc.modularui.api.widget;

import com.cleanroommc.modularui.api.ITheme;
import com.cleanroommc.modularui.api.layout.IResizeable;
import com.cleanroommc.modularui.api.layout.IViewportStack;
import com.cleanroommc.modularui.drawable.Stencil;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.viewport.GuiContext;
import com.cleanroommc.modularui.theme.WidgetTheme;
import com.cleanroommc.modularui.widget.sizer.Area;
import com.cleanroommc.modularui.widget.sizer.Flex;
import com.cleanroommc.modularui.widget.sizer.IResizeable;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cleanroommc.modularui.drawable;

import com.cleanroommc.modularui.ModularUI;
import com.cleanroommc.modularui.widget.sizer.GuiAxis;
import com.cleanroommc.modularui.api.GuiAxis;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.util.ResourceLocation;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.cleanroommc.modularui.drawable;

import com.cleanroommc.modularui.widget.sizer.GuiAxis;
import com.cleanroommc.modularui.api.GuiAxis;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void drawDebugScreen() {
}
GlStateManager.popMatrix();
locatedHovered.unapplyMatrix(context);
GuiDraw.drawText("Pos: " + area.x + ", " + area.y, 5, lineY, 1, color, false);
GuiDraw.drawText("Pos: " + area.x + ", " + area.y + " Rel: " + area.rx + ", " + area.ry, 5, lineY, 1, color, false);
lineY -= 11;
GuiDraw.drawText("Size: " + area.width + ", " + area.height, 5, lineY, 1, color, false);
lineY -= 11;
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/com/cleanroommc/modularui/screen/ModularPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.cleanroommc.modularui.utils.Alignment;
import com.cleanroommc.modularui.utils.Animator;
import com.cleanroommc.modularui.utils.Interpolation;
import com.cleanroommc.modularui.utils.ObjectList;
import com.cleanroommc.modularui.widget.ParentWidget;
import com.cleanroommc.modularui.widget.sizer.Area;
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
Expand All @@ -25,9 +26,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;

Expand All @@ -53,8 +51,8 @@ public static ModularPanel defaultPanel(@NotNull String name, int width, int hei
@NotNull
private final String name;
private ModularScreen screen;
private final LinkedList<LocatedWidget> hovering = new LinkedList<>();
private final List<Interactable> acceptedInteractions = new ArrayList<>();
private final ObjectList<LocatedWidget> hovering = ObjectList.create();
private final ObjectList<Interactable> acceptedInteractions = ObjectList.create();
private boolean isMouseButtonHeld = false, isKeyHeld = false;
@Nullable
private LocatedWidget lastPressed;
Expand Down Expand Up @@ -157,7 +155,7 @@ public void add(IWidget widget, TransformationMatrix transformationMatrix) {

@Override
public IWidget peek() {
return isEmpty() ? null : ModularPanel.this.hovering.peekFirst().getElement();
return isEmpty() ? null : ModularPanel.this.hovering.getFirst().getElement();
}

@Override
Expand Down Expand Up @@ -511,7 +509,7 @@ public ModularScreen getScreen() {
}

@NotNull
public LinkedList<LocatedWidget> getHovering() {
public ObjectList<LocatedWidget> getHovering() {
return this.hovering;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.screen.viewport.LocatedWidget;
import com.cleanroommc.modularui.utils.ObjectList;
import com.cleanroommc.modularui.utils.ReverseIterable;
import com.cleanroommc.modularui.widget.WidgetTree;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnmodifiableView;

import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class WindowManager {

Expand All @@ -21,7 +25,7 @@ public class WindowManager {
/**
* List of all open panels from top to bottom.
*/
private final LinkedList<ModularPanel> panels = new LinkedList<>();
private final ObjectList<ModularPanel> panels = ObjectList.create();
private final List<ModularPanel> panelsView = Collections.unmodifiableList(this.panels);
private final ReverseIterable<ModularPanel> reversePanels = new ReverseIterable<>(this.panelsView);
private final List<ModularPanel> queueOpenPanels = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.cleanroommc.modularui.screen.viewport;

import com.cleanroommc.modularui.ModularUI;
import com.cleanroommc.modularui.api.GuiAxis;
import com.cleanroommc.modularui.api.ITheme;
import com.cleanroommc.modularui.api.layout.IViewport;
import com.cleanroommc.modularui.api.widget.*;
import com.cleanroommc.modularui.core.mixin.GuiContainerAccessor;
import com.cleanroommc.modularui.screen.*;
import com.cleanroommc.modularui.widget.sizer.GuiAxis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import org.jetbrains.annotations.ApiStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cleanroommc.modularui.holoui.HoloScreenEntity;
import com.cleanroommc.modularui.holoui.HoloUI;
import com.cleanroommc.modularui.manager.GuiManager;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Items;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
Expand All @@ -13,10 +14,11 @@ public class EventHandler {
public static void onItemUse(PlayerInteractEvent.RightClickItem event) {
if (event.getEntityPlayer().getEntityWorld().isRemote && event.getItemStack().getItem() == Items.DIAMOND) {
//GuiManager.openClientUI(Minecraft.getMinecraft().player, new TestGui());
HoloUI.builder()
/*HoloUI.builder()
.inFrontOf(Minecraft.getMinecraft().player, 5, false)
.screenScale(0.5f)
.open(new TestGui());
.open(new TestGui());*/
GuiManager.openClientUI(Minecraft.getMinecraft().player, new ResizerTest());
}
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/cleanroommc/modularui/test/ResizerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.cleanroommc.modularui.test;

import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.screen.viewport.GuiContext;
import com.cleanroommc.modularui.widget.ParentWidget;
import com.cleanroommc.modularui.widgets.ButtonWidget;
import org.jetbrains.annotations.NotNull;

public class ResizerTest extends ModularScreen {

@Override
public @NotNull ModularPanel buildUI(GuiContext context) {
return ModularPanel.defaultPanel("main")
.coverChildrenWidth()
.height(40)
.child(new ParentWidget<>()
.coverChildren()
.padding(5)
.child(IKey.str("A decently sized string!").asWidget().debugName("label"))
.child(new ButtonWidget<>()
.size(10)
.top(5)
.right(5)
.debugName("button")));
}
}
16 changes: 9 additions & 7 deletions src/main/java/com/cleanroommc/modularui/test/TestTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ModularPanel buildUI(GuiCreationContext guiCreationContext, GuiSyncManage
panel.flex() // returns object which is responsible for sizing
.size(176, 220) // set a static size for the main panel
.align(Alignment.Center); // center the panel in the screen
panel.bindPlayerInventory()
panel
.child(new Row()
.debugName("Tab row")
.coverChildren()
Expand All @@ -90,12 +90,12 @@ public ModularPanel buildUI(GuiCreationContext guiCreationContext, GuiSyncManage
.addPage(new ParentWidget<>()
.debugName("page 1 parent")
.sizeRel(1f, 1f)
.child(SlotGroupWidget.playerInventory())
.padding(7)
.child(new Row()
.debugName("buttons, slots and more tests")
.height(137)
.coverChildrenWidth()
.padding(7)
//.padding(7)
.child(new Column()
.debugName("buttons and slots test")
.coverChildren()
Expand Down Expand Up @@ -169,9 +169,10 @@ public ModularPanel buildUI(GuiCreationContext guiCreationContext, GuiSyncManage
)))
.addPage(new Column()
.debugName("Slots test page")
//.coverChildren()
.coverChildren()
.padding(7)
.child(SlotGroupWidget.playerInventory())
.alignX(0.5f)
//.child(SlotGroupWidget.playerInventory().left(0))
.child(SlotGroupWidget.builder()
.matrix("III", "III", "III")
.key('I', index -> {
Expand Down Expand Up @@ -209,7 +210,7 @@ public ModularPanel buildUI(GuiCreationContext guiCreationContext, GuiSyncManage
.debugName("page 3 parent")
.sizeRel(1f, 1f)
.padding(7)
.child(SlotGroupWidget.playerInventory())
//.child(SlotGroupWidget.playerInventory())
.child(new SliderWidget()
.widthRel(1f).height(16)
.top(7)
Expand Down Expand Up @@ -271,7 +272,8 @@ public ModularPanel buildUI(GuiCreationContext guiCreationContext, GuiSyncManage
.texture(GuiTextures.CHECK_BOX)
.size(14, 14))
.child(IKey.lang("bogosort.gui.enabled").asWidget()
.height(14))))));
.height(14))))))
.bindPlayerInventory();
/*panel.child(new ButtonWidget<>()
.flex(flex -> flex.size(60, 20)
.top(7)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/cleanroommc/modularui/utils/MathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public static int gridRows(int count, int size, int width) {
}

public static int min(int... values) {
if (values == null || values.length == 0) throw new IllegalArgumentException();
if (values.length == 1) return values[0];
if (values.length == 2) return Math.min(values[0], values[1]);
int min = Integer.MAX_VALUE;
for (int i : values) {
if (i < min) {
Expand All @@ -54,6 +57,9 @@ public static int min(int... values) {
}

public static int max(int... values) {
if (values == null || values.length == 0) throw new IllegalArgumentException();
if (values.length == 1) return values[0];
if (values.length == 2) return Math.max(values[0], values[1]);
int max = Integer.MIN_VALUE;
for (int i : values) {
if (i > max) {
Expand Down
Loading