Skip to content
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
10 changes: 10 additions & 0 deletions src/main/java/io/wispforest/owo/ui/container/FlowLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.wispforest.owo.ui.parsing.UIParsing;
import io.wispforest.owo.ui.util.MountingHelper;
import io.wispforest.owo.util.Observable;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import org.apache.commons.lang3.mutable.MutableInt;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -160,6 +162,14 @@ public void parseProperties(UIModel model, Element element, Map<String, Element>
}
}

@Override
public MutableText inspectorDescriptor() {
final var descriptor = super.inspectorDescriptor();
return this.gap() == 0 ? descriptor : descriptor.append(
Text.literal(" [" + this.gap() + "]")
);
}

public static FlowLayout parse(Element element) {
UIParsing.expectAttributes(element, "direction");

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/io/wispforest/owo/ui/core/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import io.wispforest.owo.util.EventSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -639,6 +642,20 @@ default void moveTo(int x, int y) {
this.updateY(y);
}

/**
* @return a textual representation of the component's details for use in debugging with the inspector HUD.
* Default implementation contains positioning, size and margins.
* @see OwoUIDrawContext#drawInspector(ParentComponent, double, double, boolean)
*/
default MutableText inspectorDescriptor() {
final var margins = this.margins().get();
return Text.literal(this.x() + "," + this.y() + " (" + this.width() + "," + this.height() + ")")
.append(
Text.literal(" <" + margins.top() + "," + margins.bottom() + "," + margins.left() + "," + margins.right() + ">")
.setStyle(Style.EMPTY.withColor(Formatting.YELLOW))
);
}

enum FocusSource {
/**
* The component has been clicked
Expand Down
31 changes: 14 additions & 17 deletions src/main/java/io/wispforest/owo/ui/core/OwoUIDrawContext.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package io.wispforest.owo.ui.core;

import com.google.common.base.Preconditions;
import com.mojang.blaze3d.systems.RenderSystem;
import io.wispforest.owo.client.OwoClient;
import io.wispforest.owo.mixin.ui.DrawContextInvoker;
import io.wispforest.owo.ui.event.WindowResizeCallback;
import io.wispforest.owo.ui.util.NinePatchTexture;
import io.wispforest.owo.ui.util.ScissorStack;
import io.wispforest.owo.util.pond.OwoTessellatorExtension;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
Expand Down Expand Up @@ -318,31 +314,32 @@ public void drawInspector(ParentComponent root, double mouseX, double mouseY, bo

int inspectorX = child.x() + 1;
int inspectorY = child.y() + child.height() + child.margins().get().bottom() + 1;
int inspectorHeight = textRenderer.fontHeight * 2 + 4;

final var message = Text.literal(child.getClass().getSimpleName())
.append(child.id() == null ? "\n" : " '" + child.id() + "'\n")
.append(child.inspectorDescriptor());
final var wrappedMessage = textRenderer.wrapLines(message, client.getWindow().getScaledWidth() + 4);
int inspectorWidth = wrappedMessage.stream().mapToInt(textRenderer::getWidth).max().orElse(30);
int inspectorHeight = textRenderer.fontHeight * wrappedMessage.size() + 4;

if (inspectorY > client.getWindow().getScaledHeight() - inspectorHeight) {
inspectorY -= child.fullSize().height() + inspectorHeight + 1;
if (inspectorY < 0) inspectorY = 1;
if (child instanceof ParentComponent parentComponent) {
inspectorX += parentComponent.padding().get().left();
inspectorY += parentComponent.padding().get().top();
}
}
if (inspectorY < 0) inspectorY = 1;

final var nameText = Text.of(child.getClass().getSimpleName() + (child.id() != null ? " '" + child.id() + "'" : ""));
final var descriptor = Text.literal(child.x() + "," + child.y() + " (" + child.width() + "," + child.height() + ")"
+ " <" + margins.top() + "," + margins.bottom() + "," + margins.left() + "," + margins.right() + "> ");
if (child instanceof ParentComponent parentComponent) {
var padding = parentComponent.padding().get();
descriptor.append(" >" + padding.top() + "," + padding.bottom() + "," + padding.left() + "," + padding.right() + "<");
if (inspectorX > client.getWindow().getScaledWidth() - inspectorWidth) {
inspectorX = client.getWindow().getScaledWidth() - inspectorWidth - 2;
}
if (inspectorX < 0) inspectorX = 1;

int width = Math.max(textRenderer.getWidth(nameText), textRenderer.getWidth(descriptor));
this.fill(renderLayer, inspectorX, inspectorY, inspectorX + width + 3, inspectorY + inspectorHeight, 0xA7000000);
this.drawRectOutline(renderLayer, inspectorX, inspectorY, width + 3, inspectorHeight, 0xA7000000);
this.fill(renderLayer, inspectorX, inspectorY, inspectorX + inspectorWidth + 3, inspectorY + inspectorHeight, 0xA7000000);
this.drawRectOutline(renderLayer, inspectorX, inspectorY, inspectorWidth + 3, inspectorHeight, 0xA7000000);

this.drawText(textRenderer, nameText, inspectorX + 2, inspectorY + 2, 0xFFFFFF, false);
this.drawText(textRenderer, descriptor, inspectorX + 2, inspectorY + textRenderer.fontHeight + 2, 0xFFFFFF, false);
this.drawWrappedText(textRenderer, message, inspectorX + 2, inspectorY + 2, inspectorWidth, 0xFFFFFF, false);
}
}
}
Expand Down
13 changes: 13 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 @@ -3,6 +3,10 @@
import io.wispforest.owo.ui.parsing.IncompatibleUIModelException;
import io.wispforest.owo.ui.parsing.UIModel;
import io.wispforest.owo.ui.parsing.UIParsing;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -213,6 +217,15 @@ default void parseProperties(UIModel model, Element element, Map<String, Element
UIParsing.apply(children, "allow-overflow", UIParsing::parseBool, this::allowOverflow);
}

@Override
default MutableText inspectorDescriptor() {
final var padding = this.padding().get();
return Component.super.inspectorDescriptor().append(
Text.literal(" >" + padding.top() + "," + padding.bottom() + "," + padding.left() + "," + padding.right() + "<")
.setStyle(Style.EMPTY.withColor(Formatting.AQUA))
);
}

/**
* Recursively find the child with the given id in the
* hierarchy below this component
Expand Down