aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAlexander Haas <alexanderhaas@live.de>2022-10-13 08:08:50 +0200
committerGitHub <noreply@github.com>2022-10-13 09:08:50 +0300
commit9ddc57b0db03fa7afabf23bb7ee490a5c84af393 (patch)
treea1d6de5fb502b92aecacee0150b78d3272f040e1 /src/main
parentf8c0715d2572fb4a74d308b5ad21d0868180fecb (diff)
downloadLibGui-9ddc57b0db03fa7afabf23bb7ee490a5c84af393.tar.gz
LibGui-9ddc57b0db03fa7afabf23bb7ee490a5c84af393.tar.bz2
LibGui-9ddc57b0db03fa7afabf23bb7ee490a5c84af393.zip
IconInsets for WButton Icon (#175)
* added iconInsets for WButton * fixed some pull request comments * minor code cleanup * more code cleanup * changed intelliJ config to be able to save lines with whitespace * Update src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java Co-authored-by: Juuz <6596629+Juuxel@users.noreply.github.com> Co-authored-by: Juuz <6596629+Juuxel@users.noreply.github.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
index 533e436..78874b6 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
@@ -22,10 +22,17 @@ import org.jetbrains.annotations.Nullable;
public class WButton extends WWidget {
private static final Identifier DARK_WIDGETS_LOCATION = new Identifier("libgui", "textures/widget/dark_widgets.png");
+ private static final int BUTTON_HEIGHT = 20;
+ private static final int ICON_SPACING = 2;
- private Text label;
+ @Nullable private Text label;
protected int color = WLabel.DEFAULT_TEXT_COLOR;
protected int darkmodeColor = WLabel.DEFAULT_TEXT_COLOR;
+ /**
+ * The size (width/height) of this button's icon in pixels.
+ * @since 6.4.0
+ */
+ protected int iconSize = 16;
private boolean enabled = true;
protected HorizontalAlignment alignment = HorizontalAlignment.CENTER;
@@ -45,7 +52,7 @@ public class WButton extends WWidget {
* @param icon the icon
* @since 2.2.0
*/
- public WButton(Icon icon) {
+ public WButton(@Nullable Icon icon) {
this.icon = icon;
}
@@ -54,7 +61,7 @@ public class WButton extends WWidget {
*
* @param label the label
*/
- public WButton(Text label) {
+ public WButton(@Nullable Text label) {
this.label = label;
}
@@ -65,7 +72,7 @@ public class WButton extends WWidget {
* @param label the label
* @since 2.2.0
*/
- public WButton(Icon icon, Text label) {
+ public WButton(@Nullable Icon icon, @Nullable Text label) {
this.icon = icon;
this.label = label;
}
@@ -106,7 +113,7 @@ public class WButton extends WWidget {
ScreenDrawing.texturedRect(matrices, x+(getWidth()/2), y, getWidth()/2, 20, texture, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF);
if (icon != null) {
- icon.paint(matrices, x + 1, y + 1, 16);
+ icon.paint(matrices, x+ICON_SPACING, y+(BUTTON_HEIGHT-iconSize)/2, iconSize);
}
if (label!=null) {
@@ -117,14 +124,14 @@ public class WButton extends WWidget {
color = 0xFFFFA0;
}*/
- int xOffset = (icon != null && alignment == HorizontalAlignment.LEFT) ? 18 : 0;
+ int xOffset = (icon != null && alignment == HorizontalAlignment.LEFT) ? ICON_SPACING+iconSize+ICON_SPACING : 0;
ScreenDrawing.drawStringWithShadow(matrices, label.asOrderedText(), alignment, x + xOffset, y + ((20 - 8) / 2), width, color); //LibGuiClient.config.darkMode ? darkmodeColor : color);
}
}
@Override
public void setSize(int x, int y) {
- super.setSize(x, 20);
+ super.setSize(x, BUTTON_HEIGHT);
}
@Environment(EnvType.CLIENT)
@@ -181,7 +188,7 @@ public class WButton extends WWidget {
return this;
}
- public Text getLabel() {
+ public @Nullable Text getLabel() {
return label;
}
@@ -200,6 +207,28 @@ public class WButton extends WWidget {
}
/**
+ * Gets the current height / width of the icon.
+ *
+ * @return the current height / width of the icon
+ * @since 6.4.0
+ */
+ public int getIconSize() {
+ return iconSize;
+ }
+
+ /**
+ * Sets the new size of the icon.
+ *
+ * @param iconSize the new height and width of the icon
+ * @return this button
+ * @since 6.4.0
+ */
+ public WButton setIconSize(int iconSize) {
+ this.iconSize = iconSize;
+ return this;
+ }
+
+ /**
* Gets the icon of this button.
*
* @return the icon