Skip to content

[ui] fix List CONTAINERS #198

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

Open
wants to merge 3 commits into
base: 1.20.2
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/main/java/io/wispforest/owo/ui/component/Components.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public static SmallCheckboxComponent smallCheckbox(Text label) {
// Utility
// -------

/**
* @deprecated Use {@link Containers#list(Iterable, Consumer, Function, boolean)} instead
*/
@Deprecated
public static <T, C extends Component> FlowLayout list(List<T> data, Consumer<FlowLayout> layoutConfigurator, Function<T, C> componentMaker, boolean vertical) {
var layout = vertical ? Containers.verticalFlow(Sizing.content(), Sizing.content()) : Containers.horizontalFlow(Sizing.content(), Sizing.content());
layoutConfigurator.accept(layout);
Expand All @@ -171,4 +175,4 @@ public static <T extends Component> T createWithSizing(Supplier<T> componentMake
return component;
}

}
}
18 changes: 18 additions & 0 deletions src/main/java/io/wispforest/owo/ui/container/Containers.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import io.wispforest.owo.ui.core.Sizing;
import net.minecraft.text.Text;

import java.util.function.Consumer;
import java.util.function.Function;

public final class Containers {

private Containers() {}
Expand Down Expand Up @@ -48,6 +51,21 @@ public static <C extends Component> ScrollContainer<C> horizontalScroll(Sizing h
// Utility wrappers
// ----------------

public static <T, C extends Component> FlowLayout list(Iterable<T> data, Consumer<FlowLayout> layoutConfigurator, Function<T, C> componentMaker, boolean vertical) {
var layout = vertical ? Containers.verticalFlow(Sizing.content(), Sizing.content()) : Containers.horizontalFlow(Sizing.content(), Sizing.content());
layoutConfigurator.accept(layout);

for (var value : data) {
layout.child(componentMaker.apply(value));
}

return layout;
}

public static <T, C extends Component> FlowLayout list(Iterable<T> data, Consumer<FlowLayout> layoutConfigurator, Function<T, C> componentMaker) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're gonna keep this method in, it at least needs some short javadoc to explain what it actually means for the resulting list's axis

return list(data, layoutConfigurator, componentMaker, true);
}

public static <C extends Component> DraggableContainer<C> draggable(Sizing horizontalSizing, Sizing verticalSizing, C child) {
return new DraggableContainer<>(horizontalSizing, verticalSizing, child);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
Expand Down Expand Up @@ -333,7 +332,7 @@ protected void init() {
Containers.horizontalScroll(
Sizing.fixed(26 * 7 + 8),
Sizing.content(),
Components.list(
Containers.list(
data,
flowLayout -> flowLayout.margins(Insets.bottom(10)),
integer -> Components.button(Text.literal(integer.toString()), (ButtonComponent button) -> {}).margins(Insets.horizontal(3)).horizontalSizing(Sizing.fixed(20)),
Expand Down Expand Up @@ -435,4 +434,4 @@ private String format(@Nullable Component component) {
+ "(" + component.x() + " " + component.y() + ")";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected void build(FlowLayout rootComponent) {
final var optionsScrollContainer = Containers.verticalScroll(
Sizing.fill(90),
Sizing.fill(85),
Components.list(
Containers.list(
options,
flowLayout -> {},
this::createOptionComponent,
Expand Down Expand Up @@ -77,4 +77,4 @@ private FlowLayout createOptionComponent(ConfigOption option) {

private record ConfigOption(String name, String value) {}

}
}