diff --git a/examples/tetris/src/gui.d b/examples/tetris/src/gui.d index 9bdd5113..d83e4724 100644 --- a/examples/tetris/src/gui.d +++ b/examples/tetris/src/gui.d @@ -493,12 +493,14 @@ class StatusWidget : VerticalLayout { private TextWidget _rowsDestroyed; private TextWidget _score; private CupWidget _cup; + private TextWidget[] _labels; void setCup(CupWidget cup) { _cup = cup; } TextWidget createTextWidget(dstring str, uint color) { TextWidget res = new TextWidget(null, str); - res.layoutWidth(FILL_PARENT).alignment(Align.Center).fontSize(25).textColor(color); + res.layoutWidth(FILL_PARENT).alignment(Align.Center).fontSize(18.pointsToPixels).textColor(color); + _labels ~= res; return res; } @@ -507,10 +509,12 @@ class StatusWidget : VerticalLayout { res.colCount = 3; foreach(const Action a; CUP_ACTIONS) { ImageButton btn = new ImageButton(a); + btn.padding = 5.pointsToPixels; btn.focusable = false; res.addChild(btn); } - res.layoutWidth(WRAP_CONTENT).layoutHeight(WRAP_CONTENT).margins(Rect(10, 10, 10, 10)).alignment(Align.Center); + res.alignment = Align.Center; + res.layoutWidth(WRAP_CONTENT).layoutHeight(WRAP_CONTENT).margins(Rect(10.pointsToPixels, 10.pointsToPixels, 10.pointsToPixels, 10.pointsToPixels)).alignment(Align.Center); return res; } @@ -541,12 +545,27 @@ class StatusWidget : VerticalLayout { addChild(createTextWidget("Score:"d, 0x800000)); addChild((_score = createTextWidget(""d, 0x800000))); addChild(new VSpacer()); - addChild(createControls()); + HorizontalLayout h = new HorizontalLayout(); + h.layoutWidth = FILL_PARENT; + h.layoutHeight = FILL_PARENT; + h.addChild(new HSpacer()); + h.addChild(createControls()); + h.addChild(new HSpacer()); + addChild(h); addChild(new VSpacer()); - layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).layoutWeight(2).padding(Rect(10, 10, 10, 10)); + layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).layoutWeight(2).padding(Rect(5.pointsToPixels, 5.pointsToPixels, 5.pointsToPixels, 5.pointsToPixels)); } + /// Measure widget according to desired width and height constraints. (Step 1 of two phase layout). + override void measure(int parentWidth, int parentHeight) { + int minw = min(parentWidth, parentHeight); + foreach(lbl; _labels) { + lbl.fontSize = minw / 20; + } + super.measure(parentWidth, parentHeight); + } + void setLevel(int level) { _level.text = toUTF32(to!string(level)); } @@ -574,6 +593,8 @@ class CupPage : HorizontalLayout { _status = new StatusWidget(); _cup = new CupWidget(_status); _status.setCup(_cup); + _cup.layoutWidth = 50.makePercentSize; + _status.layoutWidth = 50.makePercentSize; addChild(_cup); addChild(_status); } diff --git a/examples/tetris/src/tetris.d b/examples/tetris/src/tetris.d index d3f38f2f..9d99f327 100644 --- a/examples/tetris/src/tetris.d +++ b/examples/tetris/src/tetris.d @@ -33,6 +33,8 @@ extern (C) int UIAppMain(string[] args) { // load theme from file "theme_default.xml" Platform.instance.uiTheme = "theme_default"; + //SCREEN_DPI = 150; + // create window Window window = Platform.instance.createWindow("DLangUI: Tetris game example"d, null, WindowFlag.Modal, 600, 400); diff --git a/examples/tetris/views/res/hdpi_arrow-down.png b/examples/tetris/views/res/hdpi_arrow-down.png new file mode 100644 index 00000000..51f357af Binary files /dev/null and b/examples/tetris/views/res/hdpi_arrow-down.png differ diff --git a/examples/tetris/views/res/hdpi_arrow-left.png b/examples/tetris/views/res/hdpi_arrow-left.png new file mode 100644 index 00000000..33818261 Binary files /dev/null and b/examples/tetris/views/res/hdpi_arrow-left.png differ diff --git a/examples/tetris/views/res/hdpi_arrow-right.png b/examples/tetris/views/res/hdpi_arrow-right.png new file mode 100644 index 00000000..accf5ff6 Binary files /dev/null and b/examples/tetris/views/res/hdpi_arrow-right.png differ diff --git a/examples/tetris/views/res/hdpi_levelup.png b/examples/tetris/views/res/hdpi_levelup.png new file mode 100644 index 00000000..50a2a386 Binary files /dev/null and b/examples/tetris/views/res/hdpi_levelup.png differ diff --git a/examples/tetris/views/res/hdpi_pause.png b/examples/tetris/views/res/hdpi_pause.png new file mode 100644 index 00000000..e6179722 Binary files /dev/null and b/examples/tetris/views/res/hdpi_pause.png differ diff --git a/examples/tetris/views/res/hdpi_rotate.png b/examples/tetris/views/res/hdpi_rotate.png new file mode 100644 index 00000000..30712b5e Binary files /dev/null and b/examples/tetris/views/res/hdpi_rotate.png differ diff --git a/examples/tetris/views/resources.list b/examples/tetris/views/resources.list index 03c36c37..f80322e4 100644 --- a/examples/tetris/views/resources.list +++ b/examples/tetris/views/resources.list @@ -8,3 +8,9 @@ res/popup_background.9.png res/rotate.png res/tetris_logo_big.png res/tx_fabric.jpg +res/hdpi_arrow-down.png +res/hdpi_arrow-left.png +res/hdpi_arrow-right.png +res/hdpi_levelup.png +res/hdpi_pause.png +res/hdpi_rotate.png