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 @@ -92,7 +92,7 @@ protected void drawMeasuredLines(List<Line> measuredLines) {
draw(measuredLine.text, x0, y0);
y0 += (int) getFontHeight();
}
this.lastActualWidth = this.maxWidth > 0 ? Math.min(maxW, this.maxWidth) : maxW;
this.lastActualWidth = maxW;
this.lastActualHeight = measuredLines.size() * getFontHeight();
this.lastTrimmedWidth = Math.max(0, this.lastActualWidth - this.scale);
this.lastTrimmedHeight = Math.max(0, this.lastActualHeight - this.scale);
Expand Down Expand Up @@ -193,11 +193,11 @@ public List<String> wrapLine(String line) {
return this.maxWidth > 0 ? getFontRenderer().listFormattedStringToWidth(line, (int) (this.maxWidth / this.scale)) : Collections.singletonList(line);
}

public boolean wouldFit(List<String> text) {
public boolean wouldFit(List<String> text, boolean shouldCheckWidth) {
if (this.maxHeight > 0 && this.maxHeight < text.size() * getFontHeight() - this.scale) {
return false;
}
if (this.maxWidth > 0) {
if (this.maxWidth > 0 && shouldCheckWidth) {
for (String line : text) {
if (this.maxWidth < getFontRenderer().getStringWidth(line)) {
return false;
Expand Down Expand Up @@ -240,7 +240,7 @@ protected int getStartX(float lineWidth) {

protected int getStartX(float maxWidth, float lineWidth) {
if (this.alignment.x > 0 && maxWidth > 0) {
return (int) (this.x + (maxWidth * this.alignment.x) - lineWidth * this.alignment.x);
return Math.max(this.x, (int) (this.x + (maxWidth * this.alignment.x) - lineWidth * this.alignment.x));
}
return this.x;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cleanroommc/modularui/test/TestTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager syncManager, UI
.overlay(IKey.str("Button 2")))
.child(new TextFieldWidget()
.size(60, 18)
.paddingTop(1)
.setTextAlignment(Alignment.Center)
.value(SyncHandlers.string(() -> this.value, val -> this.value = val))
.margin(0, 2)
.hintText("hint"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected void setupDrawText(ModularGuiContext context, WidgetTextFieldTheme wid
this.renderer.setSimulate(false);
this.renderer.setPos(getArea().getPadding().getLeft(), getArea().getPadding().getTop());
this.renderer.setScale(this.scale);
this.renderer.setAlignment(this.textAlignment, -1, getArea().paddedHeight());
this.renderer.setAlignment(this.textAlignment, getArea().paddedWidth(), getArea().paddedHeight());
}

protected void drawText(ModularGuiContext context, WidgetTextFieldTheme widgetTheme) {
Expand Down Expand Up @@ -226,7 +226,7 @@ public void onMouseDrag(int mouseButton, long timeSinceClick) {
case Keyboard.KEY_ESCAPE:
if (ModularUIConfig.escRestoreLastText) {
this.handler.clear();
this.handler.insert(this.lastText);
this.handler.insert(this.lastText, canScrollHorizontally());
}
getContext().removeFocus();
return Result.SUCCESS;
Expand Down Expand Up @@ -267,7 +267,7 @@ public void onMouseDrag(int mouseButton, long timeSinceClick) {
this.handler.delete();
}
// paste copied text in marked text
this.handler.insert(GuiScreen.getClipboardString().replace("§", ""));
this.handler.insert(GuiScreen.getClipboardString().replace("§", ""), canScrollHorizontally());
return Result.SUCCESS;
} else if (GuiScreen.isKeyComboCtrlX(keyCode) && this.handler.hasTextMarked()) {
// copy and delete copied text
Expand All @@ -283,12 +283,16 @@ public void onMouseDrag(int mouseButton, long timeSinceClick) {
this.handler.delete();
}
// insert typed char
this.handler.insert(String.valueOf(character));
this.handler.insert(String.valueOf(character), canScrollHorizontally());
return Result.SUCCESS;
}
return Result.STOP;
}

public boolean canScrollHorizontally() {
return getScrollArea().getScrollX() != null;
}

public int getMaxLines() {
return this.handler.getMaxLines();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,15 @@ public boolean test(String text) {
return this.maxLines > 1 || ((this.pattern == null || this.pattern.matcher(text).matches()) && (this.maxCharacters < 0 || this.maxCharacters >= text.length()));
}

public void insert(String text) {
insert(Arrays.asList(text.split("\n")));
public void insert(String text, boolean hasHorizontalScrolling) {
insert(Arrays.asList(text.split("\n")), hasHorizontalScrolling);
}

public void insert(List<String> text) {
public void insert(List<String> text, boolean hasHorizontalScrolling) {
List<String> copy = new ArrayList<>(this.text);
Point point = insert(copy, text);
if (point == null || copy.size() > this.maxLines || !this.renderer.wouldFit(copy)) return;
// if we can scroll horizontally, we have virtually an infinite amount of space and don't need to check width
if (point == null || copy.size() > this.maxLines || !this.renderer.wouldFit(copy, !hasHorizontalScrolling)) return;
this.text.clear();
this.text.addAll(copy);
setCursor(point, true);
Expand Down Expand Up @@ -409,4 +410,4 @@ public GuiContext getGuiContext() {
public void setGuiContext(GuiContext guiContext) {
this.guiContext = guiContext;
}
}
}