mirror of https://github.com/buggins/dlangui.git
editline development; fix padding and margins attributes support in styles}
This commit is contained in:
parent
d1a794dcb2
commit
7bce36f40d
|
@ -70,6 +70,7 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
|
|
||||||
|
|
||||||
LinearLayout hlayout = new HorizontalLayout();
|
LinearLayout hlayout = new HorizontalLayout();
|
||||||
|
hlayout.layoutWidth(FILL_PARENT);
|
||||||
//hlayout.addChild((new Button()).text("<<")); //.textColor(0x40FF4000)
|
//hlayout.addChild((new Button()).text("<<")); //.textColor(0x40FF4000)
|
||||||
hlayout.addChild((new TextWidget()).text("Several").alignment(Align.Center));
|
hlayout.addChild((new TextWidget()).text("Several").alignment(Align.Center));
|
||||||
hlayout.addChild((new ImageWidget()).drawableId("btn_radio").padding(Rect(5,5,5,5)).alignment(Align.Center));
|
hlayout.addChild((new ImageWidget()).drawableId("btn_radio").padding(Rect(5,5,5,5)).alignment(Align.Center));
|
||||||
|
@ -77,7 +78,7 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
hlayout.addChild((new ImageWidget()).drawableId("btn_check").padding(Rect(5,5,5,5)).alignment(Align.Center));
|
hlayout.addChild((new ImageWidget()).drawableId("btn_check").padding(Rect(5,5,5,5)).alignment(Align.Center));
|
||||||
hlayout.addChild((new TextWidget()).text("in horizontal layout"));
|
hlayout.addChild((new TextWidget()).text("in horizontal layout"));
|
||||||
hlayout.addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5)).alignment(Align.Center));
|
hlayout.addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5)).alignment(Align.Center));
|
||||||
hlayout.addChild((new EditLine("editline", "Some text to edit"d)));
|
hlayout.addChild((new EditLine("editline", "Some text to edit"d)).alignment(Align.Center).layoutWidth(FILL_PARENT));
|
||||||
//hlayout.addChild((new Button()).text(">>")); //.textColor(0x40FF4000)
|
//hlayout.addChild((new Button()).text(">>")); //.textColor(0x40FF4000)
|
||||||
hlayout.backgroundColor = 0x8080C0;
|
hlayout.backgroundColor = 0x8080C0;
|
||||||
layout.addChild(hlayout);
|
layout.addChild(hlayout);
|
||||||
|
|
|
@ -158,6 +158,18 @@ class EditLine : Widget {
|
||||||
measuredContent(parentWidth, parentHeight, sz.x, sz.y);
|
measuredContent(parentWidth, parentHeight, sz.x, sz.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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;
|
||||||
|
}
|
||||||
|
Point sz = Point(rc.width, measuredHeight);
|
||||||
|
applyAlign(rc, sz);
|
||||||
|
_pos = rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// draw content
|
||||||
override void onDraw(DrawBuf buf) {
|
override void onDraw(DrawBuf buf) {
|
||||||
if (visibility != Visibility.Visible)
|
if (visibility != Visibility.Visible)
|
||||||
return;
|
return;
|
||||||
|
@ -169,8 +181,8 @@ class EditLine : Widget {
|
||||||
FontRef font = font();
|
FontRef font = font();
|
||||||
dstring txt = text;
|
dstring txt = text;
|
||||||
Point sz = font.textSize(txt);
|
Point sz = font.textSize(txt);
|
||||||
applyAlign(rc, sz);
|
//applyAlign(rc, sz);
|
||||||
font.drawText(buf, rc.left, rc.top, txt, textColor);
|
font.drawText(buf, rc.left, rc.top + sz.y / 10, txt, textColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -240,14 +240,14 @@ class Style {
|
||||||
|
|
||||||
/// padding
|
/// padding
|
||||||
@property ref const(Rect) padding() const {
|
@property ref const(Rect) padding() const {
|
||||||
if (_stateValue != 0)
|
if (_stateValue != State.Enabled)
|
||||||
return parentStyle._padding;
|
return parentStyle._padding;
|
||||||
return _padding;
|
return _padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// margins
|
/// margins
|
||||||
@property ref const(Rect) margins() const {
|
@property ref const(Rect) margins() const {
|
||||||
if (_stateValue != 0)
|
if (_stateValue != State.Enabled)
|
||||||
return parentStyle._margins;
|
return parentStyle._margins;
|
||||||
return _margins;
|
return _margins;
|
||||||
}
|
}
|
||||||
|
@ -713,7 +713,7 @@ Theme createDefaultTheme() {
|
||||||
//listItem.createState(State.Selected, State.Selected).backgroundColor(0xC04040FF).textColor(0x000000);
|
//listItem.createState(State.Selected, State.Selected).backgroundColor(0xC04040FF).textColor(0x000000);
|
||||||
//listItem.createState(State.Enabled, 0).textColor(0x80000000); // half transparent text for disabled item
|
//listItem.createState(State.Enabled, 0).textColor(0x80000000); // half transparent text for disabled item
|
||||||
|
|
||||||
Style editLine = res.createSubstyle("EDIT_LINE").backgroundImageId("editbox_background").padding(Rect(4,2,4,2));
|
Style editLine = res.createSubstyle("EDIT_LINE").backgroundImageId("editbox_background").padding(Rect(5,6,5,6)).margins(Rect(2,2,2,2)).minWidth(40);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,10 +167,12 @@ class Widget {
|
||||||
}
|
}
|
||||||
/// override to handle focus changes
|
/// override to handle focus changes
|
||||||
protected void handleFocusChange(bool focused) {
|
protected void handleFocusChange(bool focused) {
|
||||||
|
invalidate();
|
||||||
onFocusChangeListener(this, checked);
|
onFocusChangeListener(this, checked);
|
||||||
}
|
}
|
||||||
/// override to handle check changes
|
/// override to handle check changes
|
||||||
protected void handleCheckChange(bool checked) {
|
protected void handleCheckChange(bool checked) {
|
||||||
|
invalidate();
|
||||||
onCheckChangeListener(this, checked);
|
onCheckChangeListener(this, checked);
|
||||||
}
|
}
|
||||||
/// set new widget state (set of flags from State enum)
|
/// set new widget state (set of flags from State enum)
|
||||||
|
@ -419,6 +421,7 @@ class Widget {
|
||||||
return null;
|
return null;
|
||||||
if (!visible)
|
if (!visible)
|
||||||
return window.focusedWidget;
|
return window.focusedWidget;
|
||||||
|
invalidate();
|
||||||
if (!canFocus) {
|
if (!canFocus) {
|
||||||
Widget w = findFocusableChild(true);
|
Widget w = findFocusableChild(true);
|
||||||
if (!w)
|
if (!w)
|
||||||
|
@ -482,7 +485,7 @@ class Widget {
|
||||||
if (canClick) {
|
if (canClick) {
|
||||||
if (event.action == MouseAction.ButtonDown && event.button == MouseButton.Left) {
|
if (event.action == MouseAction.ButtonDown && event.button == MouseButton.Left) {
|
||||||
setState(State.Pressed);
|
setState(State.Pressed);
|
||||||
if (focusable)
|
if (canFocus)
|
||||||
setFocus();
|
setFocus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -501,8 +504,9 @@ class Widget {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (focusable && event.action == MouseAction.ButtonDown && event.button == MouseButton.Left) {
|
if (canFocus && event.action == MouseAction.ButtonDown && event.button == MouseButton.Left) {
|
||||||
setFocus();
|
setFocus();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (trackHover) {
|
if (trackHover) {
|
||||||
if (event.action == MouseAction.FocusOut || event.action == MouseAction.Cancel) {
|
if (event.action == MouseAction.FocusOut || event.action == MouseAction.Cancel) {
|
||||||
|
|
Loading…
Reference in New Issue