Skip to content

Commit 71c0767

Browse files
committed
minor fixes, improvements & javadoc
1 parent 7ff6bff commit 71c0767

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed

src/main/java/com/cleanroommc/modularui/api/widget/IWidget.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ default boolean hasChildren() {
168168
ModularPanel getPanel();
169169

170170
/**
171-
* Returns if this element is enabled. Disabled elements are not drawn and can not be interacted with.
171+
* Returns if this element is enabled. Disabled elements are not drawn and can not be interacted with. If this is disabled, the children
172+
* will be considered disabled to without actually being disabled.
172173
*
173174
* @return if this element is enabled
174175
*/
@@ -177,6 +178,11 @@ default boolean hasChildren() {
177178

178179
void setEnabled(boolean enabled);
179180

181+
/**
182+
* Checks if all ancestors are enabled. Only then this widget is visible and interactable.
183+
*
184+
* @return if all ancestors are enabled.
185+
*/
180186
default boolean areAncestorsEnabled() {
181187
IWidget parent = this;
182188
do {
@@ -186,14 +192,32 @@ default boolean areAncestorsEnabled() {
186192
return true;
187193
}
188194

195+
/**
196+
* If this widget can be seen on the screen even partly. If this returns false it will be culled. This is visually only!
197+
*
198+
* @param stack viewport stack
199+
* @return false if this widget can not be seen currently and should not be drawn
200+
*/
189201
default boolean canBeSeen(IViewportStack stack) {
190202
return Stencil.isInsideScissorArea(getArea(), stack);
191203
}
192204

205+
/**
206+
* Determines if this widget can have any hover interaction. Interactions with mouse or keyboard like clicks ignore this.
207+
* This is useful, when you have a widget which changes its background when hovered or has a tooltip and some decoration child. Normally
208+
* you can click through the child, but while you hover it the widget will not show its tooltip etc. To change that return false here.
209+
*
210+
* @return if this widget can have any hover interaction
211+
*/
193212
default boolean canHover() {
194213
return true;
195214
}
196215

216+
/**
217+
* Determines if widgets below this can receive a click callback. This is only called when this widget didn't consume the click.
218+
*
219+
* @return if widgets below this should be able to receive a click
220+
*/
197221
default boolean canClickThrough() {
198222
return true;
199223
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,8 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager syncManager, UI
164164
.background(GuiTextures.MC_BACKGROUND)
165165
.excludeAreaInJei()
166166
.stencilTransform((r, expanded) -> {
167-
if (expanded) {
168-
r.width -= 5;
169-
r.height -= 5;
170-
}
167+
r.width = Math.max(20, r.width - 5);
168+
r.height = Math.max(20, r.height - 5);
171169
})
172170
.animationDuration(500)
173171
.interpolation(Interpolation.BOUNCE_OUT)
@@ -445,8 +443,8 @@ public ModularPanel openSecondWindow(PanelSyncManager syncManager, IPanelHandler
445443
.setDraggable(true)
446444
.size(100, 100);
447445
SlotGroup slotGroup = new SlotGroup("small_inv", 2);
448-
IntSyncValue timeSync = new IntSyncValue(() -> (int)java.lang.System.currentTimeMillis());
449-
syncManager.syncValue(123456,timeSync);
446+
IntSyncValue timeSync = new IntSyncValue(() -> (int) java.lang.System.currentTimeMillis());
447+
syncManager.syncValue(123456, timeSync);
450448
syncManager.registerSlotGroup(slotGroup);
451449
AtomicInteger number = new AtomicInteger(0);
452450
syncManager.syncValue("int_value", new IntSyncValue(number::get, number::set));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ public Flex getFlex() {
618618
*/
619619
@Override
620620
public Flex flex() {
621-
return this.flex;
621+
return getFlex();
622622
}
623623

624624
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public int ey() {
106106
}
107107

108108
public void ey(int ey) {
109-
this.y = ey - this.width;
109+
this.y = ey - this.height;
110110
}
111111

112112
public int mx() {

src/main/java/com/cleanroommc/modularui/widgets/layout/Flow.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.cleanroommc.modularui.widget.ParentWidget;
88
import com.cleanroommc.modularui.widget.sizer.Box;
99

10+
import java.util.function.IntFunction;
11+
1012
public class Flow extends ParentWidget<Flow> implements ILayoutWidget, IExpander {
1113

1214
public static Flow row() {
@@ -176,6 +178,20 @@ public void onChildChangeEnabled(IWidget child, boolean enabled) {
176178
}
177179
}
178180

181+
public Flow children(Iterable<IWidget> widgets) {
182+
for (IWidget widget : widgets) {
183+
child(widget);
184+
}
185+
return getThis();
186+
}
187+
188+
public Flow children(int amount, IntFunction<IWidget> widgetCreator) {
189+
for (int i = 0; i < amount; i++) {
190+
child(widgetCreator.apply(i));
191+
}
192+
return getThis();
193+
}
194+
179195
public Flow crossAxisAlignment(Alignment.CrossAxis caa) {
180196
this.caa = caa;
181197
return this;

0 commit comments

Comments
 (0)