Skip to content

Commit

Permalink
confirm widget dinamic width
Browse files Browse the repository at this point in the history
  • Loading branch information
msx80 committed Aug 19, 2024
1 parent 2968226 commit 0bbff15
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ConfirmWidget extends Widget<Action> {
private Runnable onNo;

public ConfirmWidget(GameInterface g, PrintUtils p, String question, Runnable onYes, Runnable onNo) {
super(p.sys, 120 - 35, 40, 70, ITEM_HEIGHT * 2 + 1, ITEM_HEIGHT);
super(p.sys, 120 - ( Math.max(p.size(question)+4, 70) ) /2, 40, Math.max(p.size(question)+4, 70), ITEM_HEIGHT * 2 + 1, ITEM_HEIGHT);

this.question = question;
this.onYes = onYes;
Expand Down Expand Up @@ -70,7 +70,7 @@ public void drawForeground(int x, int y) {

@Override
public void drawItem(int ax, int ay, int idx, Action a) {
p.drawBtn(ax,ay+1,70,ITEM_HEIGHT-2);
p.drawBtn(ax,ay+1,w-1,ITEM_HEIGHT-2);
p.richPrint(ax + 2, ay + 4, a.label.tokens);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void init(final Sys sys) {
smallFont = new TextDrawerVariable(sys, 7, 4, 6, 2); //, 4);
bigFont = new TextDrawerVariable(sys, 8, 16, 16, 3); //, 14);

p = new PrintUtils(sys, font, bigFont, smallFont);
p = new PrintUtils(sys, font, bigFont);
log = new Log(p);

buttons = new ButtonWidget(p, BUTTONS_X, 10, 73, 86);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ public class PrintUtils {
public Sys sys;
private TextDrawer font;
private TextDrawer bigFont;
private TextDrawer smallFont;

private int clr = Colors.fromHex("504030");

public PrintUtils(Sys sys, TextDrawer font, TextDrawer bigFont, TextDrawer smallFont) {
public PrintUtils(Sys sys, TextDrawer font, TextDrawer bigFont) {
this.sys = sys;
this.font = font;
this.bigFont = bigFont;
this.smallFont = smallFont;
}

public int size(String s)
{
return font.width(s);
}

public void print(String string, int x, int y, int color, Align align) {
Expand Down

0 comments on commit 0bbff15

Please sign in to comment.