From f13757042e3699628fa0a6859a9661da97bdf9a9 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Fri, 7 Mar 2014 18:01:10 +0400 Subject: [PATCH] introduce layout params --- src/dlangui/widgets/styles.d | 50 ++++++++++++++++++++++++++++++++++++ src/dlangui/widgets/widget.d | 14 ++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/dlangui/widgets/styles.d b/src/dlangui/widgets/styles.d index 1c5df7cd..b8a2b86e 100644 --- a/src/dlangui/widgets/styles.d +++ b/src/dlangui/widgets/styles.d @@ -16,6 +16,10 @@ immutable ubyte FONT_STYLE_ITALIC = 0x01; /// use as widget.layout() param to avoid applying of parent size immutable int SIZE_UNSPECIFIED = int.max; +immutable int FILL_PARENT = int.max - 1; +immutable int WRAP_CONTENT = int.max - 2; +immutable int WEIGHT_UNSPECIFIED = -1; + enum Align : ubyte { Unspecified = ALIGN_UNSPECIFIED, Left = 1, @@ -51,6 +55,9 @@ class Style { protected int _maxWidth = SIZE_UNSPECIFIED; protected int _minHeight = SIZE_UNSPECIFIED; protected int _maxHeight = SIZE_UNSPECIFIED; + protected int _layoutWidth = SIZE_UNSPECIFIED; + protected int _layoutHeight = SIZE_UNSPECIFIED; + protected int _layoutWeight = WEIGHT_UNSPECIFIED; protected Style[] _substates; protected Style[] _children; @@ -253,6 +260,46 @@ class Style { } + /// layout width parameter + @property uint layoutWidth() const { + if (_layoutWidth != SIZE_UNSPECIFIED) + return _layoutWidth; + else + return parentStyle.layoutWidth; + } + + /// layout height parameter + @property uint layoutHeight() const { + if (_layoutHeight != SIZE_UNSPECIFIED) + return _layoutHeight; + else + return parentStyle.layoutHeight; + } + + /// layout weight parameter + @property uint layoutWeight() const { + if (_layoutWeight != WEIGHT_UNSPECIFIED) + return _layoutWeight; + else + return parentStyle.layoutWeight; + } + + /// set layout height + @property Style layoutHeight(int value) { + _layoutHeight = value; + return this; + } + /// set layout width + @property Style layoutWidth(int value) { + _layoutWidth = value; + return this; + } + /// set layout weight + @property Style layoutWeight(int value) { + _layoutWeight = value; + return this; + } + //=================================================== // alignment @@ -387,6 +434,9 @@ class Theme : Style { _fontFamily = FontFamily.SansSerif; _minHeight = 0; _minWidth = 0; + _layoutWidth = WRAP_CONTENT; + _layoutHeight = WRAP_CONTENT; + _layoutWeight = 1; } /// create wrapper style which will have currentTheme.get(id) as parent instead of fixed parent - to modify some base style properties in widget diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index 1893c306..a07f09f5 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -162,6 +162,20 @@ class Widget { /// set max height constraint (0 for no constraint) @property Widget minHeight(int value) { ownStyle.minHeight = value; return this; } + /// returns layout width options (WRAP_CONTENT, FILL_PARENT, or some constant value) + @property int layoutWidth() { return style.layoutWidth; } + /// returns layout height options (WRAP_CONTENT, FILL_PARENT, or some constant value) + @property int layoutHeight() { return style.layoutHeight; } + /// returns layout weight (while resizing to fill parent, widget will be resized proportionally to this value) + @property int layoutWeight() { return style.layoutWeight; } + + /// sets layout width options (WRAP_CONTENT, FILL_PARENT, or some constant value) + @property Widget layoutWidth(int value) { ownStyle.layoutWidth = value; return this; } + /// sets layout height options (WRAP_CONTENT, FILL_PARENT, or some constant value) + @property Widget layoutHeight(int value) { ownStyle.layoutHeight = value; return this; } + /// sets layout weight (while resizing to fill parent, widget will be resized proportionally to this value) + @property Widget layoutWeight(int value) { ownStyle.layoutWeight = value; return this; } + /// returns widget visibility (Visible, Invisible, Gone) @property Visibility visibility() { return _visibility; } /// sets widget visibility (Visible, Invisible, Gone)