mirror of
https://github.com/Shiewk/Widgets.git
synced 2026-04-28 11:34:17 +02:00
Fix clock width
This commit is contained in:
@@ -2,8 +2,8 @@ package de.shiewk.widgets.widgets;
|
||||
|
||||
import de.shiewk.widgets.WidgetSettings;
|
||||
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@@ -14,8 +14,6 @@ import java.util.List;
|
||||
|
||||
public class ClockWidget extends BasicTextWidget {
|
||||
|
||||
private int width = DEFAULT_WIDTH;
|
||||
|
||||
public enum TimeOption {
|
||||
NO_TIME("none"),
|
||||
HOUR_24("24hour"),
|
||||
@@ -90,15 +88,11 @@ public class ClockWidget extends BasicTextWidget {
|
||||
WeekOption.NO_DAY_OF_WEEK,
|
||||
WeekOption::getName)
|
||||
));
|
||||
((IntSliderWidgetSetting) getSettings().optionById("width")).setMaxValue(80*5);
|
||||
}
|
||||
|
||||
private SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss aa EEEE");
|
||||
|
||||
@Override
|
||||
public int width() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickWidget() {
|
||||
renderText = Text.literal(dateFormat.format(Date.from(Instant.now())));
|
||||
@@ -134,7 +128,6 @@ public class ClockWidget extends BasicTextWidget {
|
||||
}
|
||||
}
|
||||
dateFormat = new SimpleDateFormat(datePattern);
|
||||
width = Math.max(DEFAULT_WIDTH, MinecraftClient.getInstance().textRenderer.getWidth(dateFormat.format(Date.from(Instant.now()))) + 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,8 +12,8 @@ import net.minecraft.util.math.MathHelper;
|
||||
public class IntSliderWidgetSetting extends WidgetSettingOption {
|
||||
|
||||
private int value;
|
||||
private final int minValue;
|
||||
private final int maxValue;
|
||||
private int minValue;
|
||||
private int maxValue;
|
||||
private boolean changed = false;
|
||||
private boolean clicked = false;
|
||||
|
||||
@@ -87,4 +87,12 @@ public class IntSliderWidgetSetting extends WidgetSettingOption {
|
||||
public int getHeight() {
|
||||
return 15;
|
||||
}
|
||||
|
||||
public void setMinValue(int minValue) {
|
||||
this.minValue = minValue;
|
||||
}
|
||||
|
||||
public void setMaxValue(int maxValue) {
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user