Merge pull request #501 from denizzzka/const_adding

Widget methods: adding const
This commit is contained in:
Vadim Lopatin 2017-10-27 16:44:53 +03:00 committed by GitHub
commit ea7925feac
3 changed files with 7 additions and 12 deletions

View File

@ -244,12 +244,7 @@ struct ObjectList(T) {
@property int count() const { return _count; }
alias length = count;
/** get item by index */
T get(int index) {
assert(index >= 0 && index < _count, "child index out of range");
return _list[index];
}
/** get const item by index */
const(T) get(int index) const {
inout(T) get(int index) inout {
assert(index >= 0 && index < _count, "child index out of range");
return _list[index];
}

View File

@ -95,7 +95,7 @@ class TextWidget : Widget {
protected UIString _text;
/// get widget text
override @property dstring text() { return _text; }
override @property dstring text() const { return _text; }
/// set text to show
override @property Widget text(dstring s) {
_text = s;
@ -529,7 +529,7 @@ class RadioButton : ImageTextButton {
/// Text only button
class Button : Widget {
protected UIString _text;
override @property dstring text() { return _text; }
override @property dstring text() const { return _text; }
override @property Widget text(dstring s) { _text = s; requestLayout(); return this; }
override @property Widget text(UIString s) { _text = s; requestLayout(); return this; }
@property Widget textResource(string s) { _text = s; requestLayout(); return this; }

View File

@ -1523,9 +1523,9 @@ public:
// Widget hierarhy methods
/// returns number of children of this widget
@property int childCount() { return 0; }
@property int childCount() const { return 0; }
/// returns child by index
Widget child(int index) { return null; }
inout(Widget) child(int index) inout { return null; }
/// adds child, returns added item
Widget addChild(Widget item) { assert(false, "addChild: children not suported for this widget type"); }
/// adds child, returns added item
@ -1739,9 +1739,9 @@ class WidgetGroup : Widget {
protected WidgetList _children;
/// returns number of children of this widget
@property override int childCount() { return _children.count; }
@property override int childCount() const { return _children.count; }
/// returns child by index
override Widget child(int index) { return _children.get(index); }
override inout(Widget) child(int index) inout { return _children.get(index); }
/// adds child, returns added item
override Widget addChild(Widget item) { return _children.add(item).parent(this); }
/// inserts child at given index, returns inserted item