Theme font, and implemented input
This commit is contained in:
@@ -10,6 +10,7 @@ public class Theme {
|
|||||||
public static Property<Integer> BG_RADIUS = Property.integer(10);
|
public static Property<Integer> BG_RADIUS = Property.integer(10);
|
||||||
public static Property<Integer> WIDGET_RADIUS = Property.integer(10);
|
public static Property<Integer> WIDGET_RADIUS = Property.integer(10);
|
||||||
public static Property<Integer> PADDING = Property.integer(15);
|
public static Property<Integer> PADDING = Property.integer(15);
|
||||||
|
public static Property<Integer> FONT = Property.font(1);
|
||||||
|
|
||||||
public static void init(ConfigManager parent) {
|
public static void init(ConfigManager parent) {
|
||||||
ConfigManager config = new ConfigManager(parent, "UI Style");
|
ConfigManager config = new ConfigManager(parent, "UI Style");
|
||||||
@@ -21,5 +22,6 @@ public class Theme {
|
|||||||
config.property("Accent Foreground", ACCENT_FG);
|
config.property("Accent Foreground", ACCENT_FG);
|
||||||
config.property("Background Radius", BG_RADIUS);
|
config.property("Background Radius", BG_RADIUS);
|
||||||
config.property("Widget Radius", WIDGET_RADIUS);
|
config.property("Widget Radius", WIDGET_RADIUS);
|
||||||
|
config.property("Font", WIDGET_RADIUS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,20 @@ package org.saturnclient.ui2.components.inputs;
|
|||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import org.saturnclient.saturnclient.config.Property;
|
import org.saturnclient.saturnclient.config.Theme;
|
||||||
import org.saturnclient.saturnclient.config.ThemeManager;
|
|
||||||
import org.saturnclient.ui2.Element;
|
import org.saturnclient.ui2.Element;
|
||||||
import org.saturnclient.ui2.ElementContext;
|
import org.saturnclient.ui2.ElementContext;
|
||||||
import org.saturnclient.ui2.RenderScope;
|
import org.saturnclient.ui2.RenderScope;
|
||||||
import org.saturnclient.ui2.resources.Fonts;
|
import org.saturnclient.ui2.resources.Fonts;
|
||||||
|
|
||||||
public abstract class Input extends Element {
|
public abstract class Input extends Element {
|
||||||
private static ThemeManager theme = new ThemeManager("Input");
|
|
||||||
private static Property<Integer> font = theme.property("font", Property.font(1));
|
|
||||||
|
|
||||||
String text = "";
|
String text = "";
|
||||||
public int cursorPosition = 0;
|
public int cursorPosition = 0;
|
||||||
|
|
||||||
public abstract void checkReset();
|
public abstract void checkReset();
|
||||||
|
|
||||||
public abstract void backspace();
|
public abstract void backspace();
|
||||||
|
|
||||||
public boolean validateBackspace() {
|
public boolean validateBackspace() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -71,11 +70,12 @@ public abstract class Input extends Element {
|
|||||||
int scrollOffset = getScrollOffset();
|
int scrollOffset = getScrollOffset();
|
||||||
String visibleText = getVisibleText(scrollOffset);
|
String visibleText = getVisibleText(scrollOffset);
|
||||||
int textColor = focused ? 0xFFFFFF : 0xAAAAAA;
|
int textColor = focused ? 0xFFFFFF : 0xAAAAAA;
|
||||||
renderScope.drawText(0.6f, visibleText, 4, 4, font.value, textColor);
|
renderScope.drawText(0.6f, visibleText, 4, 4, Theme.FONT.value, textColor);
|
||||||
|
|
||||||
if (focused) {
|
if (focused) {
|
||||||
int cursorX = 4 +
|
int cursorX = 4 +
|
||||||
(int) (Fonts.getWidth(visibleText.substring(0, cursorPosition - scrollOffset), font.value) * 0.6f);
|
(int) (Fonts.getWidth(visibleText.substring(0, cursorPosition - scrollOffset), Theme.FONT.value)
|
||||||
|
* 0.6f);
|
||||||
|
|
||||||
renderScope.drawRect(cursorX, 2, 1, height - 4, 0xFFFFFFFF);
|
renderScope.drawRect(cursorX, 2, 1, height - 4, 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ public abstract class Input extends Element {
|
|||||||
int maxWidth = width - 4; // Available width for text
|
int maxWidth = width - 4; // Available width for text
|
||||||
while (offset < cursorPosition) { // Ensure cursor remains visible
|
while (offset < cursorPosition) { // Ensure cursor remains visible
|
||||||
String visibleText = text.substring(offset, cursorPosition);
|
String visibleText = text.substring(offset, cursorPosition);
|
||||||
if (Fonts.getWidth(visibleText, font.value) > maxWidth) {
|
if (Fonts.getWidth(visibleText, Theme.FONT.value) > maxWidth) {
|
||||||
offset++;
|
offset++;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@@ -104,7 +104,7 @@ public abstract class Input extends Element {
|
|||||||
|
|
||||||
// Ensure text does not overflow past the available width
|
// Ensure text does not overflow past the available width
|
||||||
for (int i = 1; i <= visibleText.length(); i++) {
|
for (int i = 1; i <= visibleText.length(); i++) {
|
||||||
if (Fonts.getWidth(visibleText.substring(0, i), font.value) > width - 4) {
|
if (Fonts.getWidth(visibleText.substring(0, i), Theme.FONT.value) > width - 4) {
|
||||||
return visibleText.substring(0, i - 1); // Trim overflow
|
return visibleText.substring(0, i - 1); // Trim overflow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user