Skip to content

Commit

Permalink
[ui] allow specifying percentage of remaining space a given SpacerCom…
Browse files Browse the repository at this point in the history
…ponent should expand into
  • Loading branch information
gliscowo committed Jan 15, 2024
1 parent eaf33c2 commit 4fd6ff5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions owo-ui.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@
<xs:complexContent>
<xs:extension base="componentType">
<xs:group ref="componentProps"/>
<xs:attribute name="percent" type="xs:unsignedInt"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
Expand Down
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 @@ -146,8 +146,12 @@ public static SmallCheckboxComponent smallCheckbox(Text label) {
return new SmallCheckboxComponent(label);
}

public static SpacerComponent spacer(int percent) {
return new SpacerComponent(percent);
}

public static SpacerComponent spacer() {
return new SpacerComponent();
return spacer(100);
}

// -------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import io.wispforest.owo.ui.base.BaseComponent;
import io.wispforest.owo.ui.core.OwoUIDrawContext;
import io.wispforest.owo.ui.core.Sizing;
import io.wispforest.owo.ui.parsing.UIParsing;
import org.w3c.dom.Element;

public class SpacerComponent extends BaseComponent {

protected SpacerComponent() {
this.sizing(Sizing.expand());
protected SpacerComponent(int percent) {
this.sizing(Sizing.expand(percent));
}

@Override
public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) {}

public static SpacerComponent parse(Element element) {
if (!element.hasAttribute("percent")) return Components.spacer();
return Components.spacer(UIParsing.parseUnsignedInt(element.getAttributeNode("percent")));
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/wispforest/owo/ui/parsing/UIParsing.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ protected static int parseInt(Node node, boolean allowNegative) {
registerFactory("color-picker", element -> new ColorPickerComponent());
registerFactory("slim-slider", SlimSliderComponent::parse);
registerFactory("small-checkbox", element -> new SmallCheckboxComponent());
registerFactory("spacer", element -> Components.spacer());
registerFactory("spacer", SpacerComponent::parse);
}

}

0 comments on commit 4fd6ff5

Please sign in to comment.