Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static IDrawable of(IDrawable... drawables) {
* @param y y position
* @param width draw width
* @param height draw height
* @param widgetTheme current theme
*/
@SideOnly(Side.CLIENT)
void draw(GuiContext context, int x, int y, int width, int height, WidgetTheme widgetTheme);
Expand Down Expand Up @@ -66,7 +67,7 @@ default void drawAtZero(GuiContext context, int width, int height) {
* @param context gui context
* @param width draw width
* @param height draw height
* @param widgetTheme
* @param widgetTheme current theme
*/
@SideOnly(Side.CLIENT)
default void drawAtZero(GuiContext context, int width, int height, WidgetTheme widgetTheme) {
Expand All @@ -79,18 +80,19 @@ default void drawAtZero(GuiContext context, int width, int height, WidgetTheme w
@SideOnly(Side.CLIENT)
@Deprecated
default void draw(GuiContext context, Area area) {
draw(context, area.x, area.y, area.width, area.height, WidgetTheme.getDefault());
draw(context, area, WidgetTheme.getDefault());
}

/**
* Draws this drawable in a given area.
*
* @param context current context to draw with
* @param area draw area
* @param widgetTheme current theme
*/
@SideOnly(Side.CLIENT)
default void draw(GuiContext context, Area area, WidgetTheme widgetTheme) {
draw(context, area.x, area.y, area.width, area.height, widgetTheme);
draw(context, area.x + area.getPadding().left, area.y + area.getPadding().top, area.paddedWidth(), area.paddedHeight(), widgetTheme);
}

/**
Expand All @@ -99,18 +101,19 @@ default void draw(GuiContext context, Area area, WidgetTheme widgetTheme) {
@Deprecated
@SideOnly(Side.CLIENT)
default void drawAtZero(GuiContext context, Area area) {
draw(context, 0, 0, area.width, area.height, WidgetTheme.getDefault());
drawAtZero(context, area, WidgetTheme.getDefault());
}

/**
* Draws this drawable at the current (0|0) with the given area's size.
*
* @param context gui context
* @param area draw area
* @param widgetTheme current theme
*/
@SideOnly(Side.CLIENT)
default void drawAtZero(GuiContext context, Area area, WidgetTheme widgetTheme) {
draw(context, 0, 0, area.width, area.height, widgetTheme);
draw(context, 0, 0, area.paddedWidth(), area.paddedHeight(), widgetTheme);
}

/**
Expand Down Expand Up @@ -175,5 +178,15 @@ public DrawableWidget(IDrawable drawable) {
public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
this.drawable.drawAtZero(context, getArea(), widgetTheme);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof IDrawable drawable)
return this.drawable == drawable;
else if (obj instanceof DrawableWidget drawableWidget)
return this.drawable == drawableWidget.drawable;

return false;
}
}
}
5 changes: 2 additions & 3 deletions src/main/java/com/cleanroommc/modularui/widget/Widget.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void dispose() {
public void drawBackground(ModularGuiContext context, WidgetTheme widgetTheme) {
IDrawable bg = getCurrentBackground(context.getTheme(), widgetTheme);
if (bg != null) {
bg.drawAtZero(context, getArea(), widgetTheme);
bg.drawAtZero(context, getArea().width, getArea().height, widgetTheme);
}
}

Expand All @@ -158,8 +158,7 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {}
public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) {
IDrawable bg = getCurrentOverlay(context.getTheme(), widgetTheme);
if (bg != null) {
Box padding = getArea().getPadding();
bg.draw(context, padding.left, padding.top, getArea().width - padding.horizontal(), getArea().height - padding.vertical(), widgetTheme);
bg.drawAtZero(context, getArea(), widgetTheme);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,18 @@ public int requestedWidth() {
return this.width + this.margin.horizontal();
}

public int paddedWidth() {
return this.width - this.padding.horizontal();
}

public int requestedHeight() {
return this.height + this.margin.vertical();
}

public int paddedHeight() {
return this.height - this.padding.vertical();
}

public int requestedSize(GuiAxis axis) {
return axis.isHorizontal() ? requestedWidth() : requestedHeight();
}
Expand Down