mirror of https://github.com/buggins/dlangui.git
scrollbar control, part 1
This commit is contained in:
parent
304073e5ff
commit
fbc30ab5c8
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 |
|
@ -53,8 +53,9 @@ class ImageWidget : Widget {
|
||||||
protected string _drawableId;
|
protected string _drawableId;
|
||||||
protected DrawableRef _drawable;
|
protected DrawableRef _drawable;
|
||||||
|
|
||||||
this(string ID = null) {
|
this(string ID = null, string drawableId = null) {
|
||||||
super(ID);
|
super(ID);
|
||||||
|
_drawableId = drawableId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get drawable image id
|
/// 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 {
|
class Button : Widget {
|
||||||
protected dstring _text;
|
protected dstring _text;
|
||||||
override @property dstring text() { return _text; }
|
override @property dstring text() { return _text; }
|
||||||
|
@ -118,6 +127,7 @@ class Button : Widget {
|
||||||
super(ID);
|
super(ID);
|
||||||
styleId = "BUTTON";
|
styleId = "BUTTON";
|
||||||
}
|
}
|
||||||
|
|
||||||
override void measure(int parentWidth, int parentHeight) {
|
override void measure(int parentWidth, int parentHeight) {
|
||||||
FontRef font = font();
|
FontRef font = font();
|
||||||
Point sz = font.textSize(text);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,11 +2,6 @@ module dlangui.widgets.layouts;
|
||||||
|
|
||||||
import dlangui.widgets.widget;
|
import dlangui.widgets.widget;
|
||||||
|
|
||||||
enum Orientation : ubyte {
|
|
||||||
Vertical,
|
|
||||||
Horizontal
|
|
||||||
}
|
|
||||||
|
|
||||||
/// helper for layouts
|
/// helper for layouts
|
||||||
struct LayoutItem {
|
struct LayoutItem {
|
||||||
Widget _widget;
|
Widget _widget;
|
||||||
|
|
|
@ -26,6 +26,11 @@ enum Visibility : ubyte {
|
||||||
Gone
|
Gone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Orientation : ubyte {
|
||||||
|
Vertical,
|
||||||
|
Horizontal
|
||||||
|
}
|
||||||
|
|
||||||
class Widget {
|
class Widget {
|
||||||
/// widget id
|
/// widget id
|
||||||
protected string _id;
|
protected string _id;
|
||||||
|
@ -480,7 +485,7 @@ class Widget {
|
||||||
/// returns parent widget, null for top level widget
|
/// returns parent widget, null for top level widget
|
||||||
@property Widget parent() { return _parent; }
|
@property Widget parent() { return _parent; }
|
||||||
/// sets parent for widget
|
/// 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)
|
/// returns window (if widget or its parent is attached to window)
|
||||||
@property Window window() {
|
@property Window window() {
|
||||||
Widget p = this;
|
Widget p = this;
|
||||||
|
@ -558,7 +563,7 @@ class WidgetGroup : Widget {
|
||||||
/// returns child by index
|
/// returns child by index
|
||||||
override Widget child(int index) { return _children.get(index); }
|
override Widget child(int index) { return _children.get(index); }
|
||||||
/// adds child, returns added item
|
/// 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
|
/// removes child, returns added item
|
||||||
override Widget removeChild(int index) { return _children.remove(index); }
|
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
|
/// returns index of widget in child list, -1 if passed widget is not a child of this widget
|
||||||
|
|
Loading…
Reference in New Issue