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

A bunch of QOL methods #299

Open
wants to merge 4 commits into
base: 1.21
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
17 changes: 17 additions & 0 deletions src/main/java/io/wispforest/owo/ui/component/Components.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,20 @@ public static TextAreaComponent textArea(Sizing horizontalSizing, Sizing vertica
return new TextAreaComponent(horizontalSizing, verticalSizing);
}

public static TextAreaComponent textArea(Sizing sizing) {
return textArea(sizing, sizing);
}

public static TextAreaComponent textArea(Sizing horizontalSizing, Sizing verticalSizing, String text) {
var textArea = new TextAreaComponent(horizontalSizing, verticalSizing);
textArea.setText(text);
return textArea;
}

public static TextAreaComponent textArea(Sizing sizing, String text) {
return textArea(sizing, sizing, text);
}

// ------------------
// Default Components
// ------------------
Expand Down Expand Up @@ -102,6 +110,10 @@ public static LabelComponent label(Text text) {
return new LabelComponent(text);
}

public static LabelComponent label(String string) {
return new LabelComponent(Text.literal(string));
}

public static CheckboxComponent checkbox(Text message) {
return new CheckboxComponent(message);
}
Expand Down Expand Up @@ -138,6 +150,8 @@ public static BoxComponent box(Sizing horizontalSizing, Sizing verticalSizing) {
return new BoxComponent(horizontalSizing, verticalSizing);
}

public static BoxComponent box(Sizing sizing) {return box(sizing, sizing);}

public static DropdownComponent dropdown(Sizing horizontalSizing) {
return new DropdownComponent(horizontalSizing);
}
Expand Down Expand Up @@ -183,4 +197,7 @@ public static <T extends Component> T createWithSizing(Supplier<T> componentMake
return component;
}

public static <T extends Component> T createWithSizing(Supplier<T> componentMaker, Sizing sizing) {
return createWithSizing(componentMaker, sizing, sizing);
}
}
28 changes: 28 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 @@ -16,22 +16,42 @@ public static GridLayout grid(Sizing horizontalSizing, Sizing verticalSizing, in
return new GridLayout(horizontalSizing, verticalSizing, rows, columns);
}

public static GridLayout grid(Sizing sizing, int rows, int columns) {
return grid(sizing, sizing, rows, columns);
}

public static FlowLayout verticalFlow(Sizing horizontalSizing, Sizing verticalSizing) {
return new FlowLayout(horizontalSizing, verticalSizing, FlowLayout.Algorithm.VERTICAL);
}

public static FlowLayout verticalFlow(Sizing sizing) {
return verticalFlow(sizing, sizing);
}

public static FlowLayout horizontalFlow(Sizing horizontalSizing, Sizing verticalSizing) {
return new FlowLayout(horizontalSizing, verticalSizing, FlowLayout.Algorithm.HORIZONTAL);
}

public static FlowLayout horizontalFlow(Sizing sizing) {
return horizontalFlow(sizing, sizing);
}

public static FlowLayout ltrTextFlow(Sizing horizontalSizing, Sizing verticalSizing) {
return new FlowLayout(horizontalSizing, verticalSizing, FlowLayout.Algorithm.LTR_TEXT);
}

public static FlowLayout ltrTextFlow(Sizing sizing) {
return ltrTextFlow(sizing, sizing);
}

public static StackLayout stack(Sizing horizontalSizing, Sizing verticalSizing) {
return new StackLayout(horizontalSizing, verticalSizing);
}

public static StackLayout stack(Sizing sizing) {
return stack(sizing, sizing);
}

// ------
// Scroll
// ------
Expand All @@ -52,10 +72,18 @@ public static <C extends Component> DraggableContainer<C> draggable(Sizing horiz
return new DraggableContainer<>(horizontalSizing, verticalSizing, child);
}

public static <C extends Component> DraggableContainer<C> draggable(Sizing sizing, C child) {
return draggable(sizing, sizing, child);
}

public static CollapsibleContainer collapsible(Sizing horizontalSizing, Sizing verticalSizing, Text title, boolean expanded) {
return new CollapsibleContainer(horizontalSizing, verticalSizing, title, expanded);
}

public static CollapsibleContainer collapsible(Sizing sizing, Text title, boolean expanded) {
return collapsible(sizing, sizing, title, expanded);
}

public static <C extends Component> OverlayContainer<C> overlay(C child) {
return new OverlayContainer<>(child);
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/io/wispforest/owo/ui/core/ParentComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ default ParentComponent alignment(HorizontalAlignment horizontalAlignment, Verti
return this;
}

/**
* Set this component to align its children to the center
*
* @author chyzman
*/
default ParentComponent alignCenter() {
this.alignment(HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
return this;
}

/**
* Set how this component should vertically arrange its children
*
Expand Down Expand Up @@ -80,6 +90,15 @@ default ParentComponent alignment(HorizontalAlignment horizontalAlignment, Verti
*/
ParentComponent padding(Insets padding);

/**
* Set the internal padding of this component
*
* @param padding The new padding to use
*/
default ParentComponent padding(int padding) {
return this.padding(Insets.of(padding));
}

/**
* @return The internal padding of this component
*/
Expand Down
Loading