Mercurial > projects > dynamin
diff dynamin/gui/layout.d @ 106:acdbb30fee7e
Port to D2.
Most of the effort was dealing with immutable and const.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Mon, 17 Dec 2012 23:41:50 -0600 |
parents | 5c8c1c2e12c0 |
children |
line wrap: on
line diff
--- a/dynamin/gui/layout.d Sat Nov 24 10:21:50 2012 -0600 +++ b/dynamin/gui/layout.d Mon Dec 17 23:41:50 2012 -0600 @@ -34,7 +34,7 @@ */ enum LayoutType { - None, Table, Control, Filler, Spacer + Table, Control, Filler, Spacer } enum Elasticity { No, Semi, Yes @@ -84,7 +84,7 @@ //{{{ _elasticX() private Elasticity _elasticX() { - switch(type) { + final switch(type) { case LayoutType.Control: return control.elasticX ? Elasticity.Yes : Elasticity.No; case LayoutType.Table: @@ -108,7 +108,7 @@ //}}} //{{{ _elasticY() private Elasticity _elasticY() { - switch(type) { + final switch(type) { case LayoutType.Control: return control.elasticY ? Elasticity.Yes : Elasticity.No; case LayoutType.Table: @@ -133,7 +133,7 @@ //{{{ _bestSize() private Size _bestSize() { - switch(type) { + final switch(type) { case LayoutType.Control: return control.bestSize; case LayoutType.Table: @@ -150,7 +150,7 @@ //}}} //{{{ _baseline() private int _baseline() { - switch(type) { + final switch(type) { case LayoutType.Control: return control.baseline; case LayoutType.Table: @@ -170,7 +170,7 @@ //{{{ layout() void layout(Rect rect) { - switch(type) { + final switch(type) { case LayoutType.Control: control.location = Point(rect.x, rect.y); control.size = Size(rect.width, rect.height); @@ -379,7 +379,7 @@ * pretty sure it is a DMD bug, but I don't have time to make a testcase * for a bug that does not bother me.) This will work correctly: * ----- - * const char[] s = createLayout("V( b1 H(b2 b3) )"); + * enum char[] s = createLayout("V( b1 H(b2 b3) )"); * ----- * Because then the function is interpreted at compile time with CTFE. */ @@ -427,11 +427,11 @@ } // {{{ copied from Phobos -char[] ctfeUintToString(uint u) { +string ctfeUintToString(uint u) { char[uint.sizeof * 3] buffer = void; int ndigits; - char[] result; - char[] digits = "0123456789"; + string result; + string digits = "0123456789"; ndigits = 0; if (u < 10) @@ -446,12 +446,11 @@ ndigits++; buffer[buffer.length - ndigits] = cast(char)c; } - result = new char[ndigits]; - result[] = buffer[buffer.length - ndigits .. buffer.length]; + result = buffer[$ - ndigits .. $].idup; } return result; } -uint ctfeStringToUint(char[] s) +uint ctfeStringToUint(string s) { int length = s.length; @@ -568,28 +567,28 @@ unittest { class FakeButton : Control { - Size bestSize() { return Size(80, 30); } - bool elasticX() { return false; } - bool elasticY() { return false; } - int baseline() { return 20; } + override Size bestSize() { return Size(80, 30); } + override bool elasticX() { return false; } + override bool elasticY() { return false; } + override int baseline() { return 20; } } class FakeTextBox : Control { - Size bestSize() { return Size(100, 20); } - bool elasticX() { return true; } - bool elasticY() { return false; } - int baseline() { return 18; } + override Size bestSize() { return Size(100, 20); } + override bool elasticX() { return true; } + override bool elasticY() { return false; } + override int baseline() { return 18; } } class FakeListBox : Control { - Size bestSize() { return Size(100, 300); } - bool elasticX() { return false; } - bool elasticY() { return true; } - int baseline() { return 15; } + override Size bestSize() { return Size(100, 300); } + override bool elasticX() { return false; } + override bool elasticY() { return true; } + override int baseline() { return 15; } } class FakeLabel : Control { - Size bestSize() { return Size(70, 15); } - bool elasticX() { return false; } - bool elasticY() { return false; } - int baseline() { return 13; } + override Size bestSize() { return Size(70, 15); } + override bool elasticX() { return false; } + override bool elasticY() { return false; } + override int baseline() { return 13; } } auto button1 = new FakeButton(); auto tb1 = new FakeTextBox();