fix issue with widget own styles; Docked windows, part 2

This commit is contained in:
Vadim Lopatin 2015-01-16 10:50:44 +03:00
parent 94c494a690
commit 462dcb2eb7
5 changed files with 151 additions and 15 deletions

View File

@ -224,21 +224,26 @@
layoutWeight="0"
/>
<style id="DOCK_HOST"
backgroundColor="#303080"
backgroundColor="#293955"
layoutWidth="FILL_PARENT"
layoutHeight="FILL_PARENT"
padding="4,4,4,4"
padding="2,2,2,2"
/>
<style id="DOCK_HOST_BODY"
layoutWidth="FILL_PARENT"
layoutHeight="FILL_PARENT"
padding="1,1,1,1"
margins="4,4,4,4"
/>
<style id="DOCK_WINDOW"
backgroundColor="#D0D0FF"
backgroundColor="#8E9BBC"
layoutWidth="FILL_PARENT"
layoutHeight="FILL_PARENT"
padding="1,1,1,1"
margins="4,4,4,4"
/>
<style id="DOCK_WINDOW_CAPTION"
backgroundColor="#202060"
backgroundColor="#4d6082"
layoutWidth="FILL_PARENT"
layoutHeight="WRAP_CONTENT"
padding="1,1,1,1"
@ -247,7 +252,7 @@
textColor="#FFFFFF"
layoutWidth="FILL_PARENT"
layoutHeight="WRAP_CONTENT"
padding="2,2,2,2"
padding="3,3,3,3"
align="Left|VCenter"
/>
<style id="DOCK_WINDOW_BODY"

View File

@ -4,16 +4,119 @@ import dlangui.widgets.layouts;
import dlangui.widgets.controls;
class DockHost : WidgetGroupDefaultDrawing {
protected int _topSpace;
protected int _bottomSpace;
protected int _rightSpace;
protected int _leftSpace;
protected Widget _bodyWidget;
@property Widget bodyWidget() { return _bodyWidget; }
@property void bodyWidget(Widget widget) {
_children.replace(_bodyWidget, widget);
_children.replace(widget, _bodyWidget);
_bodyWidget = widget;
_bodyWidget.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
}
void addDockedWindow(DockWindow dockWin) {
addChild(dockWin);
}
this() {
super("DOCK_HOST");
styleId = STYLE_DOCK_HOST;
}
protected DockWindow[] getDockedWindowList(DockAlignment alignType) {
DockWindow[] list;
for (int i = 0; i < _children.count; i++) {
DockWindow item = cast(DockWindow)_children.get(i);
if (!item)
continue; // not a docked window
if(item.dockAlignment == alignType && item.visibility == Visibility.Visible) {
list ~= item;
}
}
return list;
}
protected void layoutDocked(DockWindow[] list, Rect rc, Orientation orient) {
int len = cast(int)list.length;
for (int i = 0; i < len; i++) {
Rect itemRc = rc;
if (len > 1) {
if (orient == Orientation.Vertical) {
itemRc.top = rc.top + rc.height * i / len;
if (i != len - 1)
itemRc.bottom = rc.top + rc.height * (i + 1) / len;
else
itemRc.bottom = rc.bottom;
} else {
itemRc.left = rc.left + rc.width * i / len;
if (i != len - 1)
itemRc.right = rc.left + rc.width * (i + 1) / len;
else
itemRc.right = rc.right;
}
}
list[i].layout(itemRc);
}
}
/// Set widget rectangle to specified value and layout widget contents. (Step 2 of two phase layout).
override void layout(Rect rc) {
_needLayout = false;
if (visibility == Visibility.Gone) {
return;
}
_pos = rc;
applyMargins(rc);
applyPadding(rc);
DockWindow[] top = getDockedWindowList(DockAlignment.Top);
DockWindow[] left = getDockedWindowList(DockAlignment.Left);
DockWindow[] right = getDockedWindowList(DockAlignment.Right);
DockWindow[] bottom = getDockedWindowList(DockAlignment.Bottom);
_topSpace = top.length ? rc.height / 5 : 0;
_bottomSpace = bottom.length ? rc.height / 5 : 0;
_rightSpace = right.length ? rc.width / 5 : 0;
_leftSpace = left.length ? rc.width / 5 : 0;
if (_bodyWidget)
_bodyWidget.layout(Rect(rc.left + _leftSpace, rc.top + _topSpace, rc.right - _rightSpace, rc.bottom - _bottomSpace));
layoutDocked(top, Rect(rc.left + _leftSpace, rc.top, rc.right - _rightSpace, rc.top + _topSpace), Orientation.Horizontal);
layoutDocked(bottom, Rect(rc.left + _leftSpace, rc.bottom - _bottomSpace, rc.right - _rightSpace, rc.bottom), Orientation.Horizontal);
layoutDocked(left, Rect(rc.left, rc.top, rc.left + _leftSpace, rc.bottom), Orientation.Vertical);
layoutDocked(right, Rect(rc.right - _rightSpace, rc.top, rc.right, rc.bottom), Orientation.Vertical);
}
/// Measure widget according to desired width and height constraints. (Step 1 of two phase layout).
override void measure(int parentWidth, int parentHeight) {
Rect m = margins;
Rect p = padding;
// calc size constraints for children
int pwidth = parentWidth;
int pheight = parentHeight;
if (parentWidth != SIZE_UNSPECIFIED)
pwidth -= m.left + m.right + p.left + p.right;
if (parentHeight != SIZE_UNSPECIFIED)
pheight -= m.top + m.bottom + p.top + p.bottom;
// measure children
Point sz;
Point bodySize;
if (_bodyWidget) {
_bodyWidget.measure(pwidth, pheight);
bodySize.x = _bodyWidget.measuredWidth;
bodySize.y = _bodyWidget.measuredHeight;
}
for (int i = 0; i < _children.count; i++) {
Widget item = _children.get(i);
// TODO: fix
if (item.visibility != Visibility.Gone) {
item.measure(pwidth, pheight);
if (sz.x < item.measuredWidth)
sz.x = item.measuredWidth;
if (sz.y < item.measuredHeight)
sz.y = item.measuredHeight;
}
}
measuredContent(parentWidth, parentHeight, sz.x, sz.y);
}
}
@ -29,17 +132,29 @@ class DockWindow : VerticalLayout {
protected Widget _bodyWidget;
@property Widget bodyWidget() { return _bodyWidget; }
@property void bodyWidget(Widget widget) {
_children.replace(_bodyWidget, widget);
_children.replace(widget, _bodyWidget);
_bodyWidget = widget;
_bodyWidget.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
requestLayout();
}
protected DockAlignment _dockAlignment;
@property DockAlignment dockAlignment() { return _dockAlignment; }
@property DockWindow dockAlignment(DockAlignment a) {
if (_dockAlignment != a) {
_dockAlignment = a;
requestLayout();
}
return this;
}
protected HorizontalLayout _captionLayout;
protected TextWidget _caption;
protected ImageButton _closeButton;
this(string ID) {
super(ID);
_dockAlignment = DockAlignment.Right;
init();
}
protected bool onCloseButtonClick(Widget source) {
@ -53,11 +168,6 @@ class DockWindow : VerticalLayout {
_captionLayout.layoutWidth(FILL_PARENT).layoutHeight(WRAP_CONTENT);
_captionLayout.styleId = STYLE_DOCK_WINDOW_CAPTION;
uint bcolor = _captionLayout.backgroundColor;
Log.d("caption layout back color=", bcolor);
//_captionLayout.backgroundColor = 0x204060;
_caption = new TextWidget("DOCK_WINDOW_CAPTION");
_caption.styleId = STYLE_DOCK_WINDOW_CAPTION_LABEL;
@ -72,8 +182,6 @@ class DockWindow : VerticalLayout {
_bodyWidget = createBodyWidget();
_bodyWidget.styleId = STYLE_DOCK_WINDOW_BODY;
//_bodyWidget.backgroundColor = 0xFFFFFF;
//_bodyWidget.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
addChild(_captionLayout);
addChild(_bodyWidget);

View File

@ -173,6 +173,7 @@ class ScrollWidgetBase : WidgetGroup, OnScrollHandler {
override void onDraw(DrawBuf buf) {
if (visibility != Visibility.Visible)
return;
super.onDraw(buf);
Rect rc = _pos;
applyMargins(rc);
{

View File

@ -119,6 +119,10 @@ immutable string STYLE_COMBO_BOX_BODY = "COMBO_BOX_BODY";
/// standard style id for app frame status line
immutable string STYLE_STATUS_LINE = "STATUS_LINE";
/// standard style id for dock host
immutable string STYLE_DOCK_HOST = "DOCK_HOST";
/// standard style id for dock host body
immutable string STYLE_DOCK_HOST_BODY = "DOCK_HOST_BODY";
/// standard style id for dock window caption
immutable string STYLE_DOCK_WINDOW_CAPTION = "DOCK_WINDOW_CAPTION";
/// standard style id for dock window
@ -273,6 +277,19 @@ class Style {
return currentTheme;
}
@property string parentStyleId() {
return _parentId;
}
@property Style parentStyleId(string id) {
_parentId = id;
if (_parentStyle)
if (currentTheme) {
_parentStyle = currentTheme.get(_parentId);
}
return this;
}
@property ref DrawableRef backgroundDrawable() const {
if (!(cast(Style)this)._backgroundDrawable.isNull)
return (cast(Style)this)._backgroundDrawable;

View File

@ -307,7 +307,12 @@ class Widget {
/// returns widget style id, null if not set
@property string styleId() const { return _styleId; }
/// set widget style id
@property Widget styleId(string id) { _styleId = id; return this; }
@property Widget styleId(string id) {
_styleId = id;
if (_ownStyle)
_ownStyle.parentStyleId = id;
return this;
}
/// get margins (between widget bounds and its background)
@property Rect margins() const { return style.margins; }
/// set margins for widget - override one from style