fixed Signal opAssign with null

This commit is contained in:
Vadim Lopatin 2014-04-18 06:45:04 +04:00
parent 71a1e4cc78
commit adac2b3c8d
3 changed files with 30 additions and 10 deletions

View File

@ -3,6 +3,8 @@ Dlang UI
GUI for D programming language, written in D. GUI for D programming language, written in D.
Alpha stage of development.
* Crossplatform (Win32 and Linux are supported in current version) * Crossplatform (Win32 and Linux are supported in current version)
* Mostly inspired by Android UI API (layouts, styles, two phase layout, ...) * Mostly inspired by Android UI API (layouts, styles, two phase layout, ...)
* Supports highly customizable UI themes and styles * Supports highly customizable UI themes and styles
@ -13,6 +15,24 @@ GUI for D programming language, written in D.
* Almost ready for 2D games development * Almost ready for 2D games development
* Goal: provide set of widgets suitable for building of IDE. * Goal: provide set of widgets suitable for building of IDE.
Widgets
-------
Currently implemented widgets:
* TextWidget - simple static text (TODO: implement multiline formatting)
* ImageWidget - static image
* Button - simple button with text label
* ImageButton - image only button
* TextImageButton - button with icon and label
* CheckBox - check button with label
* RadioButton - radio button with label
* VSpacer - vertical spacer - just an empty widget with layoutHeight == FILL_PARENT, to fill vertical space in layouts
* HSpacer - horizontal spacer - just an empty widget with layoutWidth == FILL_PARENT, to fill horizontal space in layouts
* ScrollBar - scroll bar
Layouts
-------
Win32 builds Win32 builds
------------ ------------

View File

@ -177,6 +177,7 @@ struct Signal(T1) if (is(T1 == interface) && __traits(allMembers, T1).length ==
/// replace all previously assigned listeners with new one (if null passed, remove all listeners) /// replace all previously assigned listeners with new one (if null passed, remove all listeners)
final void opAssign(slot_t listener) { final void opAssign(slot_t listener) {
_listeners.clear(); _listeners.clear();
if (listener !is null)
_listeners ~= listener; _listeners ~= listener;
} }
/// call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero /// call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero
@ -225,8 +226,10 @@ struct Signal(RETURN_T, T1...)
final bool assigned() { final bool assigned() {
return _listeners.length > 0; return _listeners.length > 0;
} }
/// replace all previously assigned listeners with new one (if null passed, remove all listeners)
final void opAssign(slot_t listener) { final void opAssign(slot_t listener) {
_listeners.clear(); _listeners.clear();
if (listener !is null)
_listeners ~= listener; _listeners ~= listener;
} }
/// call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero /// call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero

View File

@ -112,7 +112,7 @@ class TextWidget : Widget {
} }
} }
/// image widget /// static image widget
class ImageWidget : Widget { class ImageWidget : Widget {
protected string _drawableId; protected string _drawableId;
@ -339,11 +339,8 @@ class AbstractSlider : WidgetGroup {
super(ID); super(ID);
} }
protected bool delegate(AbstractSlider source, ScrollEvent event) _onScrollEventListener; /// scroll event listeners
/// scroll event listener Signal!OnScrollHandler onScrollEventListener;
@property bool delegate(AbstractSlider source, ScrollEvent event) onScrollEventListener() const { return _onScrollEventListener; }
/// sets new scroll event listener
@property AbstractSlider onScrollEventListener(bool delegate(AbstractSlider source, ScrollEvent event) listener) { _onScrollEventListener = listener; return this; }
/// returns slider position /// returns slider position
@property int position() const { return _position; } @property int position() const { return _position; }
@ -383,10 +380,10 @@ class AbstractSlider : WidgetGroup {
} }
protected bool sendScrollEvent(ScrollAction action, int position) { protected bool sendScrollEvent(ScrollAction action, int position) {
if (_onScrollEventListener is null) if (!onScrollEventListener.assigned)
return false; return false;
ScrollEvent event = new ScrollEvent(action, _minValue, _maxValue, _pageSize, position); ScrollEvent event = new ScrollEvent(action, _minValue, _maxValue, _pageSize, position);
bool res = _onScrollEventListener(this, event); bool res = onScrollEventListener(this, event);
if (event.positionChanged) { if (event.positionChanged) {
_position = event.position; _position = event.position;
if (_position > _maxValue) if (_position > _maxValue)