mirror of https://github.com/buggins/dlangui.git
styles for states
This commit is contained in:
parent
08a95002c1
commit
5fd93700a0
|
@ -43,7 +43,7 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
LinearLayout layout = new LinearLayout();
|
LinearLayout layout = new LinearLayout();
|
||||||
layout.addChild((new TextWidget()).textColor(0x00802000).text("Text widget 0"));
|
layout.addChild((new TextWidget()).textColor(0x00802000).text("Text widget 0"));
|
||||||
layout.addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget"));
|
layout.addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget"));
|
||||||
layout.addChild((new Button()).textColor(0x40FF4000).text("Button1"));
|
layout.addChild((new Button()).text("Button1")); //.textColor(0x40FF4000)
|
||||||
layout.addChild((new Button()).textColor(0x000000FF).text("Button2"));
|
layout.addChild((new Button()).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)));
|
||||||
|
|
|
@ -370,6 +370,10 @@ class Win32Window : Window {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void requestUpdate() {
|
||||||
|
InvalidateRect(_hwnd, null, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
bool onMouse(uint message, ushort flags, short x, short y) {
|
bool onMouse(uint message, ushort flags, short x, short y) {
|
||||||
Log.d("Win32 Mouse Message ", message, " flags=", flags, " x=", x, " y=", y);
|
Log.d("Win32 Mouse Message ", message, " flags=", flags, " x=", x, " y=", y);
|
||||||
MouseButton button = MouseButton.None;
|
MouseButton button = MouseButton.None;
|
||||||
|
@ -422,7 +426,10 @@ class Win32Window : Window {
|
||||||
event.lbutton = _lbutton;
|
event.lbutton = _lbutton;
|
||||||
event.rbutton = _rbutton;
|
event.rbutton = _rbutton;
|
||||||
event.mbutton = _mbutton;
|
event.mbutton = _mbutton;
|
||||||
return dispatchMouseEvent(event);
|
bool res = dispatchMouseEvent(event);
|
||||||
|
if (res)
|
||||||
|
requestUpdate();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,20 +30,6 @@ class TextWidget : Widget {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
override bool onMouseEvent(MouseEvent event) {
|
|
||||||
if (event.action == MouseAction.ButtonDown && event.button == MouseButton.Left) {
|
|
||||||
setState(State.Pressed);
|
|
||||||
Log.d("Button state: ", state);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (event.action == MouseAction.ButtonUp && event.button == MouseButton.Left) {
|
|
||||||
resetState(State.Pressed);
|
|
||||||
Log.d("Button state: ", state);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
override void onDraw(DrawBuf buf) {
|
override void onDraw(DrawBuf buf) {
|
||||||
if (visibility != Visibility.Visible)
|
if (visibility != Visibility.Visible)
|
||||||
return;
|
return;
|
||||||
|
@ -147,4 +133,19 @@ class Button : Widget {
|
||||||
applyAlign(rc, sz);
|
applyAlign(rc, sz);
|
||||||
font.drawText(buf, rc.left, rc.top, text, textColor);
|
font.drawText(buf, rc.left, rc.top, text, textColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override bool onMouseEvent(MouseEvent event) {
|
||||||
|
if (event.action == MouseAction.ButtonDown && event.button == MouseButton.Left) {
|
||||||
|
setState(State.Pressed);
|
||||||
|
Log.d("Button state: ", state);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (event.action == MouseAction.ButtonUp && event.button == MouseButton.Left) {
|
||||||
|
resetState(State.Pressed);
|
||||||
|
Log.d("Button state: ", state);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -402,7 +402,8 @@ class Style {
|
||||||
|
|
||||||
/// create state substyle for this style
|
/// create state substyle for this style
|
||||||
Style createState(uint stateMask = 0, uint stateValue = 0) {
|
Style createState(uint stateMask = 0, uint stateValue = 0) {
|
||||||
Style child = createSubstyle(id);
|
assert(stateMask != 0);
|
||||||
|
Style child = createSubstyle(null);
|
||||||
child._stateMask = stateMask;
|
child._stateMask = stateMask;
|
||||||
child._stateValue = stateValue;
|
child._stateValue = stateValue;
|
||||||
child._backgroundColor = COLOR_UNSPECIFIED;
|
child._backgroundColor = COLOR_UNSPECIFIED;
|
||||||
|
@ -414,6 +415,7 @@ class Style {
|
||||||
const(Style) forState(uint state) const {
|
const(Style) forState(uint state) const {
|
||||||
if (state == 0)
|
if (state == 0)
|
||||||
return this;
|
return this;
|
||||||
|
Log.d("forState ", state, " styleId=", _id, " substates=", _substates.length);
|
||||||
if (id is null && parentStyle !is null && _substates.length == 0)
|
if (id is null && parentStyle !is null && _substates.length == 0)
|
||||||
return parentStyle.forState(state);
|
return parentStyle.forState(state);
|
||||||
foreach(item; _substates) {
|
foreach(item; _substates) {
|
||||||
|
@ -502,4 +504,6 @@ static this() {
|
||||||
_currentTheme = new Theme("default");
|
_currentTheme = new Theme("default");
|
||||||
Style button = _currentTheme.createSubstyle("BUTTON").backgroundImageId("btn_default_normal").alignment(Align.Center);
|
Style button = _currentTheme.createSubstyle("BUTTON").backgroundImageId("btn_default_normal").alignment(Align.Center);
|
||||||
Style text = _currentTheme.createSubstyle("TEXT").margins(Rect(3,3,3,3)).padding(Rect(3,3,3,3));
|
Style text = _currentTheme.createSubstyle("TEXT").margins(Rect(3,3,3,3)).padding(Rect(3,3,3,3));
|
||||||
|
button.createState(State.Pressed, State.Pressed).backgroundImageId("btn_default_pressed");
|
||||||
|
button.createState(State.Focused, State.Focused).backgroundImageId("btn_default_selected");
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,13 +68,13 @@ class Widget {
|
||||||
const (Style) stateStyle = normalStyle.forState(stateFlags);
|
const (Style) stateStyle = normalStyle.forState(stateFlags);
|
||||||
if (stateStyle !is normalStyle)
|
if (stateStyle !is normalStyle)
|
||||||
return stateStyle; // found style for state in current style
|
return stateStyle; // found style for state in current style
|
||||||
// lookup state style in parent (one level max)
|
//// lookup state style in parent (one level max)
|
||||||
const (Style) parentStyle = normalStyle.parentStyle;
|
//const (Style) parentStyle = normalStyle.parentStyle;
|
||||||
if (parentStyle is normalStyle)
|
//if (parentStyle is normalStyle)
|
||||||
return normalStyle; // no parent
|
// return normalStyle; // no parent
|
||||||
const (Style) parentStateStyle = parentStyle.forState(stateFlags);
|
//const (Style) parentStateStyle = parentStyle.forState(stateFlags);
|
||||||
if (parentStateStyle !is parentStyle)
|
//if (parentStateStyle !is parentStyle)
|
||||||
return parentStateStyle; // found style for state in parent
|
// return parentStateStyle; // found style for state in parent
|
||||||
return normalStyle; // fallback to current style
|
return normalStyle; // fallback to current style
|
||||||
}
|
}
|
||||||
/// returns style for current widget state
|
/// returns style for current widget state
|
||||||
|
@ -327,7 +327,7 @@ class Widget {
|
||||||
return;
|
return;
|
||||||
Rect rc = _pos;
|
Rect rc = _pos;
|
||||||
applyMargins(rc);
|
applyMargins(rc);
|
||||||
DrawableRef bg = style.backgroundDrawable;
|
DrawableRef bg = stateStyle.backgroundDrawable;
|
||||||
if (!bg.isNull) {
|
if (!bg.isNull) {
|
||||||
bg.drawTo(buf, rc);
|
bg.drawTo(buf, rc);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue