resizers in docks - part 1

This commit is contained in:
Vadim Lopatin 2015-01-26 19:47:27 +03:00
parent 96d19be199
commit e1b13514c4
2 changed files with 59 additions and 3 deletions

View File

@ -31,6 +31,10 @@ class DockHost : WidgetGroupDefaultDrawing {
protected int _bottomSpace;
protected int _rightSpace;
protected int _leftSpace;
protected ResizerWidget _topResizer;
protected ResizerWidget _bottomResizer;
protected ResizerWidget _leftResizer;
protected ResizerWidget _rightResizer;
protected Widget _bodyWidget;
@property Widget bodyWidget() { return _bodyWidget; }
@property void bodyWidget(Widget widget) {
@ -40,13 +44,32 @@ class DockHost : WidgetGroupDefaultDrawing {
_bodyWidget.parent = this;
}
void addDockedWindow(DockWindow dockWin) {
void addDockedWindow(DockWindow dockWin, int delta) {
addChild(dockWin);
}
void onResize(ResizerWidget source) {
}
this() {
super("DOCK_HOST");
styleId = STYLE_DOCK_HOST;
_topResizer = new ResizerWidget("top_resizer", Orientation.Vertical);
_topResizer.visibility = Visibility.Gone;
_topResizer.resizeListener = &onResize;
_leftResizer = new ResizerWidget("left_resizer", Orientation.Horizontal);
_leftResizer.visibility = Visibility.Gone;
_leftResizer.resizeListener = &onResize;
_rightResizer = new ResizerWidget("right_resizer", Orientation.Horizontal);
_rightResizer.visibility = Visibility.Gone;
_rightResizer.resizeListener = &onResize;
_bottomResizer = new ResizerWidget("bottom_resizer", Orientation.Vertical);
_bottomResizer.visibility = Visibility.Gone;
_bottomResizer.resizeListener = &onResize;
addChild(_topResizer);
addChild(_leftResizer);
addChild(_rightResizer);
addChild(_bottomResizer);
}
protected DockWindow[] getDockedWindowList(DockAlignment alignType) {
@ -102,6 +125,31 @@ class DockHost : WidgetGroupDefaultDrawing {
_bottomSpace = bottom.length ? rc.height / 4 : 0;
_rightSpace = right.length ? rc.width / 4 : 0;
_leftSpace = left.length ? rc.width / 4 : 0;
int resizerWidth = 6;
if (_topSpace) {
_topResizer.visibility = Visibility.Visible;
_topResizer.layout(Rect(rc.left + _leftSpace, rc.top + _topSpace - resizerWidth, rc.right - _rightSpace, rc.top + _topSpace));
} else {
_topResizer.visibility = Visibility.Gone;
}
if (_bottomSpace) {
_bottomResizer.visibility = Visibility.Visible;
_bottomResizer.layout(Rect(rc.left + _leftSpace, rc.bottom - _bottomSpace, rc.right - _rightSpace, rc.bottom - _bottomSpace + resizerWidth));
} else {
_bottomResizer.visibility = Visibility.Gone;
}
if (_leftSpace) {
_leftResizer.visibility = Visibility.Visible;
_leftResizer.layout(Rect(rc.left + _leftSpace - resizerWidth, rc.top, rc.left + _leftSpace, rc.bottom));
} else {
_leftResizer.visibility = Visibility.Gone;
}
if (_rightSpace) {
_rightResizer.visibility = Visibility.Visible;
_rightResizer.layout(Rect(rc.right - _rightSpace, rc.top, rc.right - _rightSpace + resizerWidth, rc.bottom));
} else {
_rightResizer.visibility = Visibility.Gone;
}
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);

View File

@ -10,7 +10,7 @@ VerticalLayout - just LinearLayout with orientation=Orientation.Vertical
HorizontalLayout - just LinearLayout with orientation=Orientation.Vertical
FrameLayout - children occupy the same place, usually one one is visible at a time
TableLayout - children aligned into rows and columns
ResizerWidget - widget to resize sibling widgets
Synopsis:
@ -271,6 +271,10 @@ class LayoutItems {
}
}
interface ResizeHandler {
void onResize(ResizerWidget source, int delta);
}
/**
* Resizer control.
* Put it between other items in LinearLayout to allow resizing its siblings.
@ -282,16 +286,20 @@ class ResizerWidget : Widget {
protected Widget _nextWidget;
protected string _styleVertical;
protected string _styleHorizontal;
Signal!ResizeHandler resizeListener;
/// Orientation: Vertical to resize vertically, Horizontal - to resize horizontally
@property Orientation orientation() { return _orientation; }
/// empty parameter list constructor - for usage by factory
this() {
this(null);
}
/// create with ID parameter
this(string ID) {
this(string ID, Orientation orient = Orientation.Vertical) {
super(ID);
_styleVertical = "RESIZER_VERTICAL";
_styleHorizontal = "RESIZER_HORIZONTAL";
_orientation = orient;
trackHover = true;
}