mirror of https://github.com/buggins/dlangui.git
Tree Widget - support Default tree item
This commit is contained in:
parent
e9e99d6bf5
commit
48b6d474cb
|
@ -22,6 +22,17 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
backgroundColor: "#C0E0E070" // semitransparent yellow background
|
backgroundColor: "#C0E0E070" // semitransparent yellow background
|
||||||
// red bold text with size = 150% of base style size and font face Arial
|
// red bold text with size = 150% of base style size and font face Arial
|
||||||
TextWidget { text: "Hello World example for DlangUI"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" }
|
TextWidget { text: "Hello World example for DlangUI"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" }
|
||||||
|
HorizontalLayout {
|
||||||
|
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
|
// arrange controls as form - table with two columns
|
||||||
TableLayout {
|
TableLayout {
|
||||||
colCount: 2
|
colCount: 2
|
||||||
|
|
|
@ -1217,6 +1217,16 @@ FontFamily decodeFontFamily(string s) {
|
||||||
return FontFamily.SansSerif;
|
return FontFamily.SansSerif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// decode FontWeight item name to value
|
||||||
|
FontWeight decodeFontWeight(string s) {
|
||||||
|
if (s.equal("bold"))
|
||||||
|
return FontWeight.Bold;
|
||||||
|
if (s.equal("normal"))
|
||||||
|
return FontWeight.Normal;
|
||||||
|
Log.e("unknown font weight ", s);
|
||||||
|
return FontWeight.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
/// decode layout dimension (FILL_PARENT, WRAP_CONTENT, or just size)
|
/// decode layout dimension (FILL_PARENT, WRAP_CONTENT, or just size)
|
||||||
int decodeLayoutDimension(string s) {
|
int decodeLayoutDimension(string s) {
|
||||||
if (s.equal("FILL_PARENT") || s.equal("fill"))
|
if (s.equal("FILL_PARENT") || s.equal("fill"))
|
||||||
|
@ -1262,6 +1272,8 @@ bool loadStyleAttributes(Style style, Element elem, bool allowStates) {
|
||||||
style.fontFamily = decodeFontFamily(elem.tag.attr["fontFamily"]);
|
style.fontFamily = decodeFontFamily(elem.tag.attr["fontFamily"]);
|
||||||
if ("fontSize" in elem.tag.attr)
|
if ("fontSize" in elem.tag.attr)
|
||||||
style.fontSize = cast(int)decodeDimension(elem.tag.attr["fontSize"]);
|
style.fontSize = cast(int)decodeDimension(elem.tag.attr["fontSize"]);
|
||||||
|
if ("fontWeight" in elem.tag.attr)
|
||||||
|
style.fontWeight = cast(ushort)decodeFontWeight(elem.tag.attr["fontWeight"]);
|
||||||
if ("layoutWidth" in elem.tag.attr)
|
if ("layoutWidth" in elem.tag.attr)
|
||||||
style.layoutWidth = decodeLayoutDimension(elem.tag.attr["layoutWidth"]);
|
style.layoutWidth = decodeLayoutDimension(elem.tag.attr["layoutWidth"]);
|
||||||
if ("layoutHeight" in elem.tag.attr)
|
if ("layoutHeight" in elem.tag.attr)
|
||||||
|
|
|
@ -184,10 +184,18 @@ class TreeItem {
|
||||||
return root.selectedItem();
|
return root.selectedItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSelected() {
|
@property TreeItem defaultItem() {
|
||||||
|
return root.defaultItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@property bool isSelected() {
|
||||||
return (selectedItem is this);
|
return (selectedItem is this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property bool isDefault() {
|
||||||
|
return (defaultItem is this);
|
||||||
|
}
|
||||||
|
|
||||||
/// get widget text
|
/// get widget text
|
||||||
@property dstring text() { return _text; }
|
@property dstring text() { return _text; }
|
||||||
/// set text to show
|
/// set text to show
|
||||||
|
@ -344,6 +352,7 @@ class TreeItems : TreeItem {
|
||||||
@property TreeItems noCollapseForSingleTopLevelItem(bool flg) { _noCollapseForSingleTopLevelItem = flg; return this; }
|
@property TreeItems noCollapseForSingleTopLevelItem(bool flg) { _noCollapseForSingleTopLevelItem = flg; return this; }
|
||||||
|
|
||||||
protected TreeItem _selectedItem;
|
protected TreeItem _selectedItem;
|
||||||
|
protected TreeItem _defaultItem;
|
||||||
|
|
||||||
this() {
|
this() {
|
||||||
super("tree");
|
super("tree");
|
||||||
|
@ -400,6 +409,12 @@ class TreeItems : TreeItem {
|
||||||
selectionListener(this, _selectedItem, false);
|
selectionListener(this, _selectedItem, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setDefaultItem(TreeItem item) {
|
||||||
|
_defaultItem = item;
|
||||||
|
if (stateListener.assigned)
|
||||||
|
stateListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
override void activateItem(TreeItem item) {
|
override void activateItem(TreeItem item) {
|
||||||
if (!(_selectedItem is item)) {
|
if (!(_selectedItem is item)) {
|
||||||
_selectedItem = item;
|
_selectedItem = item;
|
||||||
|
@ -414,6 +429,10 @@ class TreeItems : TreeItem {
|
||||||
return _selectedItem;
|
return _selectedItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property override TreeItem defaultItem() {
|
||||||
|
return _defaultItem;
|
||||||
|
}
|
||||||
|
|
||||||
void selectNext() {
|
void selectNext() {
|
||||||
if (!hasChildren)
|
if (!hasChildren)
|
||||||
return;
|
return;
|
||||||
|
@ -647,6 +666,10 @@ class TreeItemWidget : HorizontalLayout {
|
||||||
setState(State.Selected);
|
setState(State.Selected);
|
||||||
else
|
else
|
||||||
resetState(State.Selected);
|
resetState(State.Selected);
|
||||||
|
if (_item.isDefault)
|
||||||
|
setState(State.Default);
|
||||||
|
else
|
||||||
|
resetState(State.Default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -422,8 +422,9 @@
|
||||||
layoutWidth="FILL_PARENT"
|
layoutWidth="FILL_PARENT"
|
||||||
layoutHeight="WRAP_CONTENT"
|
layoutHeight="WRAP_CONTENT"
|
||||||
align="Left|VCenter"
|
align="Left|VCenter"
|
||||||
textFlags="Parent"
|
textFlags="Parent">
|
||||||
/>
|
<state state_default="true" fontWeight="bold"/>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style id="SETTINGS_TREE"
|
<style id="SETTINGS_TREE"
|
||||||
margins="8,8,8,8"
|
margins="8,8,8,8"
|
||||||
|
|
Loading…
Reference in New Issue