v3.3.0: various layout tweaks for long translations:

- text in wndOptions buttons can now render on 2 lines if needed
- stat slot text can now better dynamically resize
- setting checkbox text can now resize dynamically
This commit is contained in:
Evan Debenham
2025-10-31 13:20:24 -04:00
parent ee9aaac89b
commit 8e47b27507
6 changed files with 57 additions and 24 deletions
@@ -47,6 +47,17 @@ public class CheckBox extends RedButton {
icon.x = x + width - margin - icon.width; icon.x = x + width - margin - icon.width;
icon.y = y + margin; icon.y = y + margin;
PixelScene.align(icon); PixelScene.align(icon);
int size = 9;
while (width > 0 && text.right() > icon.x){
size--;
remove(text);
text = PixelScene.renderTextBlock(text.text, size);
margin = (height - text.height()) / 2;
text.setPos( x + margin, y + margin);
PixelScene.align(text);
add(text);
}
} }
public boolean checked() { public boolean checked() {
@@ -144,7 +144,7 @@ public abstract class OptionSlider extends Component {
@Override @Override
protected void layout() { protected void layout() {
if (title.width() > 0.7f*width){ if (title.width() > 0.6f*width){
String titleText = title.text; String titleText = title.text;
remove(title); remove(title);
title = PixelScene.renderTextBlock(6); title = PixelScene.renderTextBlock(6);
@@ -161,15 +161,22 @@ public class WndGameInProgress extends Window {
} }
private void statSlot( String label, String value ) { private void statSlot( String label, String value ) {
RenderedTextBlock txt = PixelScene.renderTextBlock( label, 8 );
txt.setPos(0, pos);
add( txt );
int size = 8; int size = 8;
if (value.length() >= 14) size -=2; RenderedTextBlock txt;
if (value.length() >= 18) size -=1; do {
txt = PixelScene.renderTextBlock( value, size ); txt = PixelScene.renderTextBlock( label, size );
size--;
} while (txt.width() >= WIDTH * 0.55f);
txt.setPos(0, pos + (6 - txt.height())/2);
PixelScene.align(txt);
add( txt );
size = 8;
do {
txt = PixelScene.renderTextBlock( value, size );
size--;
} while (txt.width() >= WIDTH * 0.45f);
txt.setPos(WIDTH * 0.55f, pos + (6 - txt.height())/2); txt.setPos(WIDTH * 0.55f, pos + (6 - txt.height())/2);
PixelScene.align(txt); PixelScene.align(txt);
add( txt ); add( txt );
@@ -214,16 +214,23 @@ public class WndHero extends WndTabbed {
} }
private void statSlot( String label, String value ) { private void statSlot( String label, String value ) {
RenderedTextBlock txt = PixelScene.renderTextBlock( label, 8 );
txt.setPos(0, pos);
add( txt );
int size = 8; int size = 8;
if (value.length() >= 14) size -=2; RenderedTextBlock txt;
if (value.length() >= 18) size -=1; do {
txt = PixelScene.renderTextBlock( value, size ); txt = PixelScene.renderTextBlock( label, size );
txt.setPos(WIDTH * 0.55f, pos); size--;
} while (txt.width() >= WIDTH * 0.55f);
txt.setPos(0, pos + (6 - txt.height())/2);
PixelScene.align(txt);
add( txt );
size = 8;
do {
txt = PixelScene.renderTextBlock( value, size );
size--;
} while (txt.width() >= WIDTH * 0.45f);
txt.setPos(WIDTH * 0.55f, pos + (6 - txt.height())/2);
PixelScene.align(txt); PixelScene.align(txt);
add( txt ); add( txt );
@@ -93,6 +93,7 @@ public class WndOptions extends Window {
} }
}; };
if (hasIcon(i)) btn.icon(getIcon(i)); if (hasIcon(i)) btn.icon(getIcon(i));
btn.multiline = true;
btn.enable(enabled(i)); btn.enable(enabled(i));
add( btn ); add( btn );
@@ -297,16 +297,23 @@ public class WndRanking extends WndTabbed {
} }
private float statSlot( Group parent, String label, String value, float pos ) { private float statSlot( Group parent, String label, String value, float pos ) {
RenderedTextBlock txt = PixelScene.renderTextBlock( label, 7 );
txt.setPos(0, pos);
parent.add( txt );
int size = 7; int size = 7;
if (value.length() >= 14) size -=1; RenderedTextBlock txt;
if (value.length() >= 18) size -=1; do {
txt = PixelScene.renderTextBlock( value, size ); txt = PixelScene.renderTextBlock( label, size );
txt.setPos(WIDTH * 0.55f, pos); size--;
} while (txt.width() >= WIDTH * 0.55f);
txt.setPos(0, pos + (6 - txt.height())/2);
PixelScene.align(txt);
parent.add( txt );
size = 7;
do {
txt = PixelScene.renderTextBlock( value, size );
size--;
} while (txt.width() >= WIDTH * 0.45f);
txt.setPos(WIDTH * 0.55f, pos + (6 - txt.height())/2);
PixelScene.align(txt); PixelScene.align(txt);
parent.add( txt ); parent.add( txt );