scrollbar control, part 1

This commit is contained in:
Vadim Lopatin 2014-03-23 14:24:10 +04:00
parent 304073e5ff
commit fbc30ab5c8
7 changed files with 59 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 B

View File

@ -53,8 +53,9 @@ class ImageWidget : Widget {
protected string _drawableId;
protected DrawableRef _drawable;
this(string ID = null) {
this(string ID = null, string drawableId = null) {
super(ID);
_drawableId = drawableId;
}
/// get drawable image id
@ -110,6 +111,14 @@ class ImageWidget : Widget {
}
}
/// button with image only
class ImageButton : ImageWidget {
this(string ID = null, string drawableId = null) {
super(ID);
styleId = "BUTTON";
}
}
class Button : Widget {
protected dstring _text;
override @property dstring text() { return _text; }
@ -118,6 +127,7 @@ class Button : Widget {
super(ID);
styleId = "BUTTON";
}
override void measure(int parentWidth, int parentHeight) {
FontRef font = font();
Point sz = font.textSize(text);
@ -138,3 +148,44 @@ class Button : Widget {
}
}
/// scroll bar - either vertical or horizontal
class ScrollBar : WidgetGroup {
protected ImageButton _btnBack;
protected ImageButton _btnForward;
protected Orientation _orientation = Orientation.Vertical;
/// returns scrollbar orientation (Vertical, Horizontal)
@property Orientation orientation() { return _orientation; }
/// sets scrollbar orientation
@property ScrollBar orientation(Orientation value) {
if (_orientation != value) {
_orientation = value;
_btnBack.drawableId = _orientation == Orientation.Vertical ? "scrollbar_btn_up" : "scrollbar_btn_left";
_btnForward.drawableId = _orientation == Orientation.Vertical ? "scrollbar_btn_down" : "scrollbar_btn_right";
requestLayout();
}
return this;
}
this(string ID = null, Orientation orientation = Orientation.Vertical) {
super(ID);
styleId = "BUTTON";
_orientation = orientation;
_btnBack = new ImageButton("BACK", _orientation == Orientation.Vertical ? "scrollbar_btn_up" : "scrollbar_btn_left");
_btnForward = new ImageButton("FORWARD", _orientation == Orientation.Vertical ? "scrollbar_btn_down" : "scrollbar_btn_right");
}
override void measure(int parentWidth, int parentHeight) {
Point sz;
_btnBack.measure(parentWidth, parentHeight);
_btnForward.measure(parentWidth, parentHeight);
if (_orientation == Orientation.Vertical) {
// vertical
} else {
// horizontal
}
measuredContent(parentWidth, parentHeight, sz.x, sz.y);
}
}

View File

@ -2,11 +2,6 @@ module dlangui.widgets.layouts;
import dlangui.widgets.widget;
enum Orientation : ubyte {
Vertical,
Horizontal
}
/// helper for layouts
struct LayoutItem {
Widget _widget;

View File

@ -26,6 +26,11 @@ enum Visibility : ubyte {
Gone
}
enum Orientation : ubyte {
Vertical,
Horizontal
}
class Widget {
/// widget id
protected string _id;
@ -480,7 +485,7 @@ class Widget {
/// returns parent widget, null for top level widget
@property Widget parent() { return _parent; }
/// sets parent for widget
@property void parent(Widget parent) { _parent = parent; }
@property Widget parent(Widget parent) { _parent = parent; return this; }
/// returns window (if widget or its parent is attached to window)
@property Window window() {
Widget p = this;
@ -558,7 +563,7 @@ class WidgetGroup : Widget {
/// returns child by index
override Widget child(int index) { return _children.get(index); }
/// adds child, returns added item
override Widget addChild(Widget item) { return _children.add(item); }
override Widget addChild(Widget item) { return _children.add(item).parent(this); }
/// removes child, returns added item
override Widget removeChild(int index) { return _children.remove(index); }
/// returns index of widget in child list, -1 if passed widget is not a child of this widget