update WMeteorTextBox

This commit is contained in:
Cloudburst
2021-06-24 08:30:24 +02:00
parent 4e59d8b028
commit c136fa0f7b
2 changed files with 18 additions and 8 deletions

View File

@@ -100,6 +100,7 @@ public class MeteorRoundedGuiTheme extends GuiTheme {
public final Setting<SettingColor> textColor = color(sgTextColors, "text", "Color of text.", new SettingColor(255, 255, 255)); public final Setting<SettingColor> textColor = color(sgTextColors, "text", "Color of text.", new SettingColor(255, 255, 255));
public final Setting<SettingColor> textSecondaryColor = color(sgTextColors, "text-secondary-text", "Color of secondary text.", new SettingColor(150, 150, 150)); public final Setting<SettingColor> textSecondaryColor = color(sgTextColors, "text-secondary-text", "Color of secondary text.", new SettingColor(150, 150, 150));
public final Setting<SettingColor> textHighlightColor = color(sgTextColors, "text-highlight", "Color of text highlighting.", new SettingColor(45, 125, 245, 100));
public final Setting<SettingColor> titleTextColor = color(sgTextColors, "title-text", "Color of title text.", new SettingColor(255, 255, 255)); public final Setting<SettingColor> titleTextColor = color(sgTextColors, "title-text", "Color of title text.", new SettingColor(255, 255, 255));
public final Setting<SettingColor> loggedInColor = color(sgTextColors, "logged-in-text", "Color of logged in account name.", new SettingColor(45, 225, 45)); public final Setting<SettingColor> loggedInColor = color(sgTextColors, "logged-in-text", "Color of logged in account name.", new SettingColor(45, 225, 45));

View File

@@ -39,28 +39,37 @@ public class WMeteorTextBox extends WTextBox implements MeteorWidget {
} }
renderBackground(renderer, this, false, false); renderBackground(renderer, this, false, false);
renderTextAndCursor(renderer, delta);
}
private void renderTextAndCursor(GuiRenderer renderer, double delta) {
MeteorRoundedGuiTheme theme = theme(); MeteorRoundedGuiTheme theme = theme();
double pad = pad(); double pad = pad();
double overflowWidth = getOverflowWidthForRender(); double overflowWidth = getOverflowWidthForRender();
if (!text.isEmpty()) {
renderer.scissorStart(x + pad, y + pad, width - pad * 2, height - pad * 2); renderer.scissorStart(x + pad, y + pad, width - pad * 2, height - pad * 2);
// Text content
if (!text.isEmpty()) {
renderer.text(text, x + pad - overflowWidth, y + pad, theme.textColor.get(), false); renderer.text(text, x + pad - overflowWidth, y + pad, theme.textColor.get(), false);
renderer.scissorEnd();
} }
// Text highlighting
if (focused && (cursor != selectionStart || cursor != selectionEnd)) {
double selStart = x + pad + getTextWidth(selectionStart) - overflowWidth;
double selEnd = x + pad + getTextWidth(selectionEnd) - overflowWidth;
renderer.quad(selStart, y + pad, selEnd - selStart, theme.textHeight(), theme.textHighlightColor.get());
}
// Cursor
animProgress += delta * 10 * (focused && cursorVisible ? 1 : -1); animProgress += delta * 10 * (focused && cursorVisible ? 1 : -1);
animProgress = Utils.clamp(animProgress, 0, 1); animProgress = Utils.clamp(animProgress, 0, 1);
if ((focused && cursorVisible) || animProgress > 0) { if ((focused && cursorVisible) || animProgress > 0) {
renderer.setAlpha(animProgress); renderer.setAlpha(animProgress);
renderer.quad(x + pad + getCursorTextWidth() - overflowWidth, y + pad, theme.scale(1), theme.textHeight(), theme.textColor.get()); renderer.quad(x + pad + getTextWidth(cursor) - overflowWidth, y + pad, theme.scale(1), theme.textHeight(), theme.textColor.get());
renderer.setAlpha(1); renderer.setAlpha(1);
} }
renderer.scissorEnd();
} }
} }