mirror of https://github.com/buggins/dlangui.git
fix style with substyles modification - close #150
This commit is contained in:
parent
b306388fd6
commit
eb99980d5e
|
@ -13,77 +13,89 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
// create window
|
// create window
|
||||||
Window window = Platform.instance.createWindow("DlangUI example - 3D Application", null, WindowFlag.Resizable, 600, 500);
|
Window window = Platform.instance.createWindow("DlangUI example - 3D Application", null, WindowFlag.Resizable, 600, 500);
|
||||||
|
|
||||||
// create some widget to show in window
|
static if (true) {
|
||||||
//window.mainWidget = (new Button()).text("Hello, world!"d).margins(Rect(20,20,20,20));
|
VerticalLayout layout = new VerticalLayout();
|
||||||
window.mainWidget = parseML(q{
|
Button btn = new Button(null, "Button 1"d);
|
||||||
VerticalLayout {
|
btn.fontSize = 32;
|
||||||
margins: 10
|
Button btn2 = new Button(null, "Button 2"d);
|
||||||
padding: 10
|
btn2.fontSize = 32;
|
||||||
backgroundColor: "#C0E0E070" // semitransparent yellow background
|
layout.addChild(btn);
|
||||||
// red bold text with size = 150% of base style size and font face Arial
|
layout.addChild(btn2);
|
||||||
TextWidget { text: "Hello World example for DlangUI"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" }
|
window.mainWidget = layout;
|
||||||
HorizontalLayout {
|
} else {
|
||||||
layoutWidth: fill
|
|
||||||
TextWidget { text: "Text 20%"; backgroundColor:"#80FF0000"; layoutWidth: 20% }
|
|
||||||
VerticalLayout {
|
|
||||||
layoutWidth: 30%
|
|
||||||
TextWidget { text: "Text 30%"; backgroundColor:"#80FF00FF" }
|
|
||||||
TextWidget { text: "Text 30%"; backgroundColor:"#8000FFFF" }
|
|
||||||
TextWidget { text: "Text 30%"; backgroundColor:"#8000FFFF" }
|
|
||||||
}
|
|
||||||
TextWidget { text: "Text 50%"; backgroundColor:"#80FFFF00"; layoutWidth: 50% }
|
|
||||||
}
|
|
||||||
// arrange controls as form - table with two columns
|
|
||||||
TableLayout {
|
|
||||||
colCount: 2
|
|
||||||
TextWidget { text: "param 1" }
|
|
||||||
EditLine { id: edit1; text: "some text" }
|
|
||||||
TextWidget { text: "param 2" }
|
|
||||||
EditLine { id: edit2; text: "some text for param2" }
|
|
||||||
TextWidget { text: "some radio buttons" }
|
|
||||||
// arrange some radio buttons vertically
|
|
||||||
VerticalLayout {
|
|
||||||
RadioButton { id: rb1; text: "Item 1" }
|
|
||||||
RadioButton { id: rb2; text: "Item 2" }
|
|
||||||
RadioButton { id: rb3; text: "Item 3" }
|
|
||||||
}
|
|
||||||
TextWidget { text: "and checkboxes" }
|
|
||||||
// arrange some checkboxes horizontally
|
|
||||||
HorizontalLayout {
|
|
||||||
CheckBox { id: cb1; text: "checkbox 1" }
|
|
||||||
CheckBox { id: cb2; text: "checkbox 2" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HorizontalLayout {
|
|
||||||
Button { id: btnOk; text: "Ok" }
|
|
||||||
Button { id: btnCancel; text: "Cancel" }
|
|
||||||
}
|
|
||||||
CanvasWidget {
|
|
||||||
id: canvas
|
|
||||||
minWidth: 500
|
|
||||||
minHeight: 300
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
auto canvas = window.mainWidget.childById!CanvasWidget("canvas");
|
// create some widget to show in window
|
||||||
canvas.onDrawListener = delegate(CanvasWidget canvas, DrawBuf buf, Rect rc) {
|
//window.mainWidget = (new Button()).text("Hello, world!"d).margins(Rect(20,20,20,20));
|
||||||
Log.w("canvas.onDrawListener clipRect=" ~ to!string(buf.clipRect));
|
window.mainWidget = parseML(q{
|
||||||
buf.fill(0xFFFFFF);
|
VerticalLayout {
|
||||||
int x = rc.left;
|
margins: 10
|
||||||
int y = rc.top;
|
padding: 10
|
||||||
buf.fillRect(Rect(x+20, y+20, x+150, y+200), 0x80FF80);
|
backgroundColor: "#C0E0E070" // semitransparent yellow background
|
||||||
buf.fillRect(Rect(x+90, y+80, x+250, y+250), 0x80FF80FF);
|
// red bold text with size = 150% of base style size and font face Arial
|
||||||
canvas.font.drawText(buf, x + 40, y + 50, "fillRect()"d, 0xC080C0);
|
TextWidget { text: "Hello World example for DlangUI"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" }
|
||||||
buf.drawFrame(Rect(x + 400, y + 30, x + 550, y + 150), 0x204060, Rect(2,3,4,5), 0x80704020);
|
HorizontalLayout {
|
||||||
canvas.font.drawText(buf, x + 400, y + 5, "drawFrame()"d, 0x208020);
|
layoutWidth: fill
|
||||||
canvas.font.drawText(buf, x + 300, y + 100, "drawPixel()"d, 0x000080);
|
TextWidget { text: "Text 20%"; backgroundColor:"#80FF0000"; layoutWidth: 20% }
|
||||||
for (int i = 0; i < 80; i++)
|
VerticalLayout {
|
||||||
buf.drawPixel(x+300 + i * 4, y+140 + i * 3 % 100, 0xFF0000 + i * 2);
|
layoutWidth: 30%
|
||||||
canvas.font.drawText(buf, x + 200, y + 150, "drawLine()"d, 0x800020);
|
TextWidget { text: "Text 30%"; backgroundColor:"#80FF00FF" }
|
||||||
for (int i = 0; i < 40; i+=3)
|
TextWidget { text: "Text 30%"; backgroundColor:"#8000FFFF" }
|
||||||
buf.drawLine(Point(x+200 + i * 4, y+190), Point(x+150 + i * 7, y+320 + i * 2), 0x008000 + i * 5);
|
TextWidget { text: "Text 30%"; backgroundColor:"#8000FFFF" }
|
||||||
};
|
}
|
||||||
|
TextWidget { text: "Text 50%"; backgroundColor:"#80FFFF00"; layoutWidth: 50% }
|
||||||
|
}
|
||||||
|
// arrange controls as form - table with two columns
|
||||||
|
TableLayout {
|
||||||
|
colCount: 2
|
||||||
|
TextWidget { text: "param 1" }
|
||||||
|
EditLine { id: edit1; text: "some text" }
|
||||||
|
TextWidget { text: "param 2" }
|
||||||
|
EditLine { id: edit2; text: "some text for param2" }
|
||||||
|
TextWidget { text: "some radio buttons" }
|
||||||
|
// arrange some radio buttons vertically
|
||||||
|
VerticalLayout {
|
||||||
|
RadioButton { id: rb1; text: "Item 1" }
|
||||||
|
RadioButton { id: rb2; text: "Item 2" }
|
||||||
|
RadioButton { id: rb3; text: "Item 3" }
|
||||||
|
}
|
||||||
|
TextWidget { text: "and checkboxes" }
|
||||||
|
// arrange some checkboxes horizontally
|
||||||
|
HorizontalLayout {
|
||||||
|
CheckBox { id: cb1; text: "checkbox 1" }
|
||||||
|
CheckBox { id: cb2; text: "checkbox 2" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HorizontalLayout {
|
||||||
|
Button { id: btnOk; text: "Ok"; fontSize: 27px }
|
||||||
|
Button { id: btnCancel; text: "Cancel"; fontSize: 27px }
|
||||||
|
}
|
||||||
|
CanvasWidget {
|
||||||
|
id: canvas
|
||||||
|
minWidth: 500
|
||||||
|
minHeight: 300
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
auto canvas = window.mainWidget.childById!CanvasWidget("canvas");
|
||||||
|
canvas.onDrawListener = delegate(CanvasWidget canvas, DrawBuf buf, Rect rc) {
|
||||||
|
Log.w("canvas.onDrawListener clipRect=" ~ to!string(buf.clipRect));
|
||||||
|
buf.fill(0xFFFFFF);
|
||||||
|
int x = rc.left;
|
||||||
|
int y = rc.top;
|
||||||
|
buf.fillRect(Rect(x+20, y+20, x+150, y+200), 0x80FF80);
|
||||||
|
buf.fillRect(Rect(x+90, y+80, x+250, y+250), 0x80FF80FF);
|
||||||
|
canvas.font.drawText(buf, x + 40, y + 50, "fillRect()"d, 0xC080C0);
|
||||||
|
buf.drawFrame(Rect(x + 400, y + 30, x + 550, y + 150), 0x204060, Rect(2,3,4,5), 0x80704020);
|
||||||
|
canvas.font.drawText(buf, x + 400, y + 5, "drawFrame()"d, 0x208020);
|
||||||
|
canvas.font.drawText(buf, x + 300, y + 100, "drawPixel()"d, 0x000080);
|
||||||
|
for (int i = 0; i < 80; i++)
|
||||||
|
buf.drawPixel(x+300 + i * 4, y+140 + i * 3 % 100, 0xFF0000 + i * 2);
|
||||||
|
canvas.font.drawText(buf, x + 200, y + 150, "drawLine()"d, 0x800020);
|
||||||
|
for (int i = 0; i < 40; i+=3)
|
||||||
|
buf.drawLine(Point(x+200 + i * 4, y+190), Point(x+150 + i * 7, y+320 + i * 2), 0x008000 + i * 5);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Scene3d scene = new Scene3d();
|
Scene3d scene = new Scene3d();
|
||||||
Camera cam = new Camera();
|
Camera cam = new Camera();
|
||||||
|
|
|
@ -806,6 +806,40 @@ public:
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Style clone() {
|
||||||
|
Style res = new Style(_theme, null);
|
||||||
|
res._stateMask = _stateMask;
|
||||||
|
res._stateValue = _stateValue;
|
||||||
|
res._align = _align;
|
||||||
|
res._fontStyle = _fontStyle;
|
||||||
|
res._fontFamily = _fontFamily;
|
||||||
|
res._fontWeight = _fontWeight;
|
||||||
|
res._fontSize = _fontSize;
|
||||||
|
res._backgroundColor = _backgroundColor;
|
||||||
|
res._textColor = _textColor;
|
||||||
|
res._textFlags = _textFlags;
|
||||||
|
res._alpha = _alpha;
|
||||||
|
res._fontFace = _fontFace;
|
||||||
|
res._backgroundImageId = _backgroundImageId;
|
||||||
|
res._padding = _padding;
|
||||||
|
res._margins = _margins;
|
||||||
|
res._minWidth = _minWidth;
|
||||||
|
res._maxWidth = _maxWidth;
|
||||||
|
res._minHeight = _minHeight;
|
||||||
|
res._maxHeight = _maxHeight;
|
||||||
|
res._layoutWidth = _layoutWidth;
|
||||||
|
res._layoutHeight = _layoutHeight;
|
||||||
|
res._layoutWeight = _layoutWeight;
|
||||||
|
res._maxLines = _maxLines;
|
||||||
|
|
||||||
|
res._focusRectColors = _focusRectColors.dup;
|
||||||
|
|
||||||
|
res._customDrawables = _customDrawables.dup;
|
||||||
|
res._customColors = _customColors.dup;
|
||||||
|
res._customLength = _customLength.dup;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/// find exact existing state style or create new if no matched styles found
|
/// find exact existing state style or create new if no matched styles found
|
||||||
Style getOrCreateState(uint stateMask = 0, uint stateValue = 0) {
|
Style getOrCreateState(uint stateMask = 0, uint stateValue = 0) {
|
||||||
if (stateValue == State.Normal)
|
if (stateValue == State.Normal)
|
||||||
|
@ -878,6 +912,14 @@ class Theme : Style {
|
||||||
style._margins.left = SIZE_UNSPECIFIED; // inherit
|
style._margins.left = SIZE_UNSPECIFIED; // inherit
|
||||||
style._textColor = COLOR_UNSPECIFIED; // inherit
|
style._textColor = COLOR_UNSPECIFIED; // inherit
|
||||||
style._textFlags = TEXT_FLAGS_UNSPECIFIED; // inherit
|
style._textFlags = TEXT_FLAGS_UNSPECIFIED; // inherit
|
||||||
|
Style parent = get(id);
|
||||||
|
if (parent) {
|
||||||
|
foreach(item; parent._substates) {
|
||||||
|
Style substate = item.clone();
|
||||||
|
substate._parentStyle = style;
|
||||||
|
style._substates ~= substate;
|
||||||
|
}
|
||||||
|
}
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue