mirror of https://github.com/buggins/dlangui.git
scrollbars, part 2
This commit is contained in:
parent
fbc30ab5c8
commit
6c60828690
examples/example1
src/dlangui/widgets
|
@ -68,6 +68,9 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
vlayout.addChild((new TextWidget()).text("VLayout line 2").textColor(0x40FFFF00));
|
vlayout.addChild((new TextWidget()).text("VLayout line 2").textColor(0x40FFFF00));
|
||||||
layout.addChild(vlayout);
|
layout.addChild(vlayout);
|
||||||
|
|
||||||
|
ScrollBar sb = new ScrollBar("hscroll", Orientation.Horizontal);
|
||||||
|
layout.addChild(sb.layoutHeight(WRAP_CONTENT).layoutWidth(FILL_PARENT));
|
||||||
|
|
||||||
layout.addChild((new Button("BTN2")).textColor(0x000000FF).text("Button2"));
|
layout.addChild((new Button("BTN2")).textColor(0x000000FF).text("Button2"));
|
||||||
layout.addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget"));
|
layout.addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget"));
|
||||||
layout.addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5)));
|
layout.addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5)));
|
||||||
|
|
Binary file not shown.
Before ![]() (image error) Size: 356 B After ![]() (image error) Size: 371 B ![]() ![]() |
Binary file not shown.
Before ![]() (image error) Size: 359 B After ![]() (image error) Size: 378 B ![]() ![]() |
Binary file not shown.
Before ![]() (image error) Size: 349 B After ![]() (image error) Size: 353 B ![]() ![]() |
Binary file not shown.
Before ![]() (image error) Size: 356 B After ![]() (image error) Size: 371 B ![]() ![]() |
|
@ -116,6 +116,7 @@ class ImageButton : ImageWidget {
|
||||||
this(string ID = null, string drawableId = null) {
|
this(string ID = null, string drawableId = null) {
|
||||||
super(ID);
|
super(ID);
|
||||||
styleId = "BUTTON";
|
styleId = "BUTTON";
|
||||||
|
_drawableId = drawableId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +154,7 @@ class Button : Widget {
|
||||||
class ScrollBar : WidgetGroup {
|
class ScrollBar : WidgetGroup {
|
||||||
protected ImageButton _btnBack;
|
protected ImageButton _btnBack;
|
||||||
protected ImageButton _btnForward;
|
protected ImageButton _btnForward;
|
||||||
|
protected int _btnSize;
|
||||||
|
|
||||||
protected Orientation _orientation = Orientation.Vertical;
|
protected Orientation _orientation = Orientation.Vertical;
|
||||||
/// returns scrollbar orientation (Vertical, Horizontal)
|
/// returns scrollbar orientation (Vertical, Horizontal)
|
||||||
|
@ -168,24 +170,76 @@ class ScrollBar : WidgetGroup {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
this(string ID = null, Orientation orientation = Orientation.Vertical) {
|
this(string ID = null, Orientation orient = Orientation.Vertical) {
|
||||||
super(ID);
|
super(ID);
|
||||||
styleId = "BUTTON";
|
styleId = "BUTTON";
|
||||||
_orientation = orientation;
|
_orientation = orient;
|
||||||
_btnBack = new ImageButton("BACK", _orientation == Orientation.Vertical ? "scrollbar_btn_up" : "scrollbar_btn_left");
|
_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");
|
_btnForward = new ImageButton("FORWARD", _orientation == Orientation.Vertical ? "scrollbar_btn_down" : "scrollbar_btn_right");
|
||||||
|
addChild(_btnBack);
|
||||||
|
addChild(_btnForward);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void measure(int parentWidth, int parentHeight) {
|
override void measure(int parentWidth, int parentHeight) {
|
||||||
Point sz;
|
Point sz;
|
||||||
_btnBack.measure(parentWidth, parentHeight);
|
_btnBack.measure(parentWidth, parentHeight);
|
||||||
_btnForward.measure(parentWidth, parentHeight);
|
_btnForward.measure(parentWidth, parentHeight);
|
||||||
|
_btnSize = _btnBack.measuredWidth;
|
||||||
|
if (_btnSize < _btnBack.measuredHeight)
|
||||||
|
_btnSize = _btnBack.measuredHeight;
|
||||||
|
if (_btnSize < 16)
|
||||||
|
_btnSize = 16;
|
||||||
if (_orientation == Orientation.Vertical) {
|
if (_orientation == Orientation.Vertical) {
|
||||||
// vertical
|
// vertical
|
||||||
|
sz.x = _btnSize;
|
||||||
|
sz.y = _btnSize * 5; // min height
|
||||||
} else {
|
} else {
|
||||||
// horizontal
|
// horizontal
|
||||||
|
sz.y = _btnSize;
|
||||||
|
sz.x = _btnSize * 5; // min height
|
||||||
}
|
}
|
||||||
measuredContent(parentWidth, parentHeight, sz.x, sz.y);
|
measuredContent(parentWidth, parentHeight, sz.x, sz.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override void layout(Rect rc) {
|
||||||
|
applyMargins(rc);
|
||||||
|
applyPadding(rc);
|
||||||
|
Rect r;
|
||||||
|
if (_orientation == Orientation.Vertical) {
|
||||||
|
// vertical
|
||||||
|
int backbtnpos = rc.top + _btnSize;
|
||||||
|
int fwdbtnpos = rc.bottom - _btnSize;
|
||||||
|
r = rc;
|
||||||
|
r.bottom = backbtnpos;
|
||||||
|
_btnBack.layout(r);
|
||||||
|
r = rc;
|
||||||
|
r.top = fwdbtnpos;
|
||||||
|
_btnForward.layout(r);
|
||||||
|
} else {
|
||||||
|
// horizontal
|
||||||
|
int backbtnpos = rc.left + _btnSize;
|
||||||
|
int fwdbtnpos = rc.right - _btnSize;
|
||||||
|
r = rc;
|
||||||
|
r.right = backbtnpos;
|
||||||
|
_btnBack.layout(r);
|
||||||
|
r = rc;
|
||||||
|
r.left = fwdbtnpos;
|
||||||
|
_btnForward.layout(r);
|
||||||
|
}
|
||||||
|
_pos = rc;
|
||||||
|
_needLayout = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Draw widget at its position to buffer
|
||||||
|
override void onDraw(DrawBuf buf) {
|
||||||
|
if (visibility != Visibility.Visible)
|
||||||
|
return;
|
||||||
|
super.onDraw(buf);
|
||||||
|
Rect rc = _pos;
|
||||||
|
applyMargins(rc);
|
||||||
|
applyPadding(rc);
|
||||||
|
ClipRectSaver(buf, rc);
|
||||||
|
_btnForward.onDraw(buf);
|
||||||
|
_btnBack.onDraw(buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue