Event listener names refactoring

This commit is contained in:
Vadim Lopatin 2015-12-03 16:29:45 +03:00
parent 2e15fbca78
commit 1dde772437
12 changed files with 44 additions and 54 deletions

View File

@ -16,7 +16,7 @@ Getting Started Tutorial: [https://github.com/buggins/dlangui/wiki/Getting-Start
Screenshots: [http://buggins.github.io/dlangui/screenshots.html](http://buggins.github.io/dlangui/screenshots.html) Screenshots: [http://buggins.github.io/dlangui/screenshots.html](http://buggins.github.io/dlangui/screenshots.html)
WARNING: recent breaking change: when specifying dlangui library as DUB dependency, use "dlangui" instead of "dlangui:dlanguilib". WARNING: recent breaking change: some event listeners were renamed, e.g. onClickListener -> click, onFocusChangeListener -> focusChange...
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/buggins/dlangui?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/buggins/dlangui.svg?branch=master)](https://travis-ci.org/buggins/dlangui) [![PayPayl donate button](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KPSNU8TYF6M5N "Donate once-off to this project using Paypal") [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/buggins/dlangui?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/buggins/dlangui.svg?branch=master)](https://travis-ci.org/buggins/dlangui) [![PayPayl donate button](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KPSNU8TYF6M5N "Donate once-off to this project using Paypal")

View File

@ -312,17 +312,17 @@ class EditFrame : AppFrame {
auto cbFillHorizontal = new CheckBox(null, "Fill Horizontal"d); auto cbFillHorizontal = new CheckBox(null, "Fill Horizontal"d);
auto cbFillVertical = new CheckBox(null, "Fill Vertical"d); auto cbFillVertical = new CheckBox(null, "Fill Vertical"d);
auto cbHighlightBackground = new CheckBox(null, "Background"d); auto cbHighlightBackground = new CheckBox(null, "Background"d);
cbFillHorizontal.onCheckChangeListener = delegate(Widget source, bool checked) { cbFillHorizontal.checkChange = delegate(Widget source, bool checked) {
_fillHorizontal = checked; _fillHorizontal = checked;
updatePreview(); updatePreview();
return true; return true;
}; };
cbFillVertical.onCheckChangeListener = delegate(Widget source, bool checked) { cbFillVertical.checkChange = delegate(Widget source, bool checked) {
_fillVertical = checked; _fillVertical = checked;
updatePreview(); updatePreview();
return true; return true;
}; };
cbHighlightBackground.onCheckChangeListener = delegate(Widget source, bool checked) { cbHighlightBackground.checkChange = delegate(Widget source, bool checked) {
_highlightBackground = checked; _highlightBackground = checked;
updatePreview(); updatePreview();
return true; return true;

View File

@ -49,12 +49,12 @@ extern (C) int UIAppMain(string[] args) {
auto edit1 = window.mainWidget.childById!EditLine("edit1"); auto edit1 = window.mainWidget.childById!EditLine("edit1");
auto edit2 = window.mainWidget.childById!EditLine("edit2"); auto edit2 = window.mainWidget.childById!EditLine("edit2");
// close window on Cancel button click // close window on Cancel button click
window.mainWidget.childById!Button("btnCancel").onClickListener = delegate(Widget w) { window.mainWidget.childById!Button("btnCancel").click = delegate(Widget w) {
window.close(); window.close();
return true; return true;
}; };
// show message box with content of editors // show message box with content of editors
window.mainWidget.childById!Button("btnOk").onClickListener = delegate(Widget w) { window.mainWidget.childById!Button("btnOk").click = delegate(Widget w) {
window.showMessageBox(UIString("Ok button pressed"d), window.showMessageBox(UIString("Ok button pressed"d),
UIString("Editors content\nEdit1: "d ~ edit1.text ~ "\nEdit2: "d ~ edit2.text)); UIString("Editors content\nEdit1: "d ~ edit1.text ~ "\nEdit2: "d ~ edit2.text));
return true; return true;

View File

@ -33,7 +33,7 @@ Widget createAboutWidget()
res.addChild(new TextWidget(null, "(C) Vadim Lopatin, 2014"d)); res.addChild(new TextWidget(null, "(C) Vadim Lopatin, 2014"d));
res.addChild(new TextWidget(null, "http://github.com/buggins/dlangui"d)); res.addChild(new TextWidget(null, "http://github.com/buggins/dlangui"d));
Button closeButton = new Button("close", "Close"d); Button closeButton = new Button("close", "Close"d);
closeButton.onClickListener = delegate(Widget src) { closeButton.click = delegate(Widget src) {
Log.i("Closing window"); Log.i("Closing window");
res.window.close(); res.window.close();
return true; return true;
@ -521,7 +521,7 @@ class StatusWidget : VerticalLayout {
ImageWidget image = new ImageWidget(null, "tetris_logo_big"); ImageWidget image = new ImageWidget(null, "tetris_logo_big");
image.layoutWidth(FILL_PARENT).alignment(Align.Center).clickable(true); image.layoutWidth(FILL_PARENT).alignment(Align.Center).clickable(true);
image.onClickListener = delegate(Widget src) { image.click = delegate(Widget src) {
_cup.handleAction(ACTION_PAUSE); _cup.handleAction(ACTION_PAUSE);
// about dialog when clicking on image // about dialog when clicking on image
Window wnd = Platform.instance.createWindow("About...", window, WindowFlag.Modal); Window wnd = Platform.instance.createWindow("About...", window, WindowFlag.Modal);

View File

@ -438,13 +438,13 @@ class FilePathPanelItem : HorizontalLayout {
_text = new TextWidget(null, toUTF32(fname)); _text = new TextWidget(null, toUTF32(fname));
_text.styleId = STYLE_BUTTON_TRANSPARENT; _text.styleId = STYLE_BUTTON_TRANSPARENT;
_text.clickable = true; _text.clickable = true;
_text.onClickListener = &onTextClick; _text.click = &onTextClick;
//_text.backgroundColor = 0xC0FFFF; //_text.backgroundColor = 0xC0FFFF;
_text.state = State.Parent; _text.state = State.Parent;
_button = new ImageButton(null, "scrollbar_btn_right"); _button = new ImageButton(null, "scrollbar_btn_right");
_button.styleId = STYLE_BUTTON_TRANSPARENT; _button.styleId = STYLE_BUTTON_TRANSPARENT;
_button.focusable = false; _button.focusable = false;
_button.onClickListener = &onButtonClick; _button.click = &onButtonClick;
//_button.backgroundColor = 0xC0FFC0; //_button.backgroundColor = 0xC0FFC0;
_button.state = State.Parent; _button.state = State.Parent;
trackHover(true); trackHover(true);
@ -619,8 +619,8 @@ class FilePathPanel : FrameLayout {
_edPath = new EditLine(ID_EDITOR); _edPath = new EditLine(ID_EDITOR);
_edPath.layoutWidth = FILL_PARENT; _edPath.layoutWidth = FILL_PARENT;
_edPath.editorActionListener = &onEditorAction; _edPath.editorActionListener = &onEditorAction;
_edPath.onFocusChangeListener = &onEditorFocusChanged; _edPath.focusChange = &onEditorFocusChanged;
_segments.onClickListener = &onSegmentsClickOutside; _segments.click = &onSegmentsClickOutside;
_segments.onPathSelectionListener = &onPathSelected; _segments.onPathSelectionListener = &onPathSelected;
addChild(_segments); addChild(_segments);
addChild(_edPath); addChild(_edPath);

View File

@ -54,7 +54,7 @@ class CheckboxItem : SettingsItem {
CheckBox res = new CheckBox(_id, _label); CheckBox res = new CheckBox(_id, _label);
Setting setting = settings.settingByPath(_id, SettingType.FALSE); Setting setting = settings.settingByPath(_id, SettingType.FALSE);
res.checked = setting.boolean ^ _inverse; res.checked = setting.boolean ^ _inverse;
res.onCheckChangeListener = delegate(Widget source, bool checked) { res.checkChange = delegate(Widget source, bool checked) {
setting.boolean = checked ^ _inverse; setting.boolean = checked ^ _inverse;
return true; return true;
}; };

View File

@ -95,7 +95,7 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
ImageButton res = new ImageButton("COMBOBOX_BUTTON", "scrollbar_btn_down"); ImageButton res = new ImageButton("COMBOBOX_BUTTON", "scrollbar_btn_down");
res.styleId = STYLE_COMBO_BOX_BUTTON; res.styleId = STYLE_COMBO_BOX_BUTTON;
res.layoutWeight = 0; res.layoutWeight = 0;
res.onClickListener = this; res.click = this;
res.alignment = Align.VCenter | Align.Right; res.alignment = Align.VCenter | Align.Right;
return res; return res;
} }
@ -164,7 +164,7 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
protected void init() { protected void init() {
_body = createSelectedItemWidget(); _body = createSelectedItemWidget();
_body.onClickListener = this; _body.click = this;
_button = createButton(); _button = createButton();
//_body.state = State.Parent; //_body.state = State.Parent;
//focusable = true; //focusable = true;
@ -284,7 +284,7 @@ class ComboBox : ComboBoxBase {
_body.clickable = true; _body.clickable = true;
focusable = true; focusable = true;
clickable = true; clickable = true;
onClickListener = this; click = this;
} }
override protected Widget createSelectedItemWidget() { override protected Widget createSelectedItemWidget() {

View File

@ -641,16 +641,16 @@ class ScrollBar : AbstractSlider, OnClickHandler {
return true; return true;
} }
if (event.action == MouseAction.FocusOut && _dragging) { if (event.action == MouseAction.FocusOut && _dragging) {
Log.d("ScrollBar slider dragging - FocusOut"); debug(scrollbar) Log.d("ScrollBar slider dragging - FocusOut");
return true; return true;
} }
if (event.action == MouseAction.FocusIn && _dragging) { if (event.action == MouseAction.FocusIn && _dragging) {
Log.d("ScrollBar slider dragging - FocusIn"); debug(scrollbar) Log.d("ScrollBar slider dragging - FocusIn");
return true; return true;
} }
if (event.action == MouseAction.Move && _dragging) { if (event.action == MouseAction.Move && _dragging) {
int delta = _orientation == Orientation.Vertical ? event.y - _dragStart.y : event.x - _dragStart.x; int delta = _orientation == Orientation.Vertical ? event.y - _dragStart.y : event.x - _dragStart.x;
Log.d("ScrollBar slider dragging - Move delta=", delta); debug(scrollbar) Log.d("ScrollBar slider dragging - Move delta=", delta);
Rect rc = _dragStartRect; Rect rc = _dragStartRect;
int offset; int offset;
int space; int space;
@ -696,25 +696,25 @@ class ScrollBar : AbstractSlider, OnClickHandler {
} }
if (event.action == MouseAction.Move && trackHover) { if (event.action == MouseAction.Move && trackHover) {
if (!(state & State.Hovered)) { if (!(state & State.Hovered)) {
Log.d("Hover ", id); debug(scrollbar) Log.d("Hover ", id);
setState(State.Hovered); setState(State.Hovered);
} }
return true; return true;
} }
if (event.action == MouseAction.Leave && trackHover) { if (event.action == MouseAction.Leave && trackHover) {
Log.d("Leave ", id); debug(scrollbar) Log.d("Leave ", id);
resetState(State.Hovered); resetState(State.Hovered);
return true; return true;
} }
if (event.action == MouseAction.Cancel && trackHover) { if (event.action == MouseAction.Cancel && trackHover) {
Log.d("Cancel ? trackHover", id); debug(scrollbar) Log.d("Cancel ? trackHover", id);
resetState(State.Hovered); resetState(State.Hovered);
resetState(State.Pressed); resetState(State.Pressed);
_dragging = false; _dragging = false;
return true; return true;
} }
if (event.action == MouseAction.Cancel) { if (event.action == MouseAction.Cancel) {
Log.d("SliderButton.onMouseEvent event.action == MouseAction.Cancel"); debug(scrollbar) Log.d("SliderButton.onMouseEvent event.action == MouseAction.Cancel");
resetState(State.Pressed); resetState(State.Pressed);
_dragging = false; _dragging = false;
return true; return true;
@ -814,10 +814,10 @@ class ScrollBar : AbstractSlider, OnClickHandler {
_indicator.focusable = false; _indicator.focusable = false;
_pageUp.focusable = false; _pageUp.focusable = false;
_pageDown.focusable = false; _pageDown.focusable = false;
_btnBack.onClickListener = &onClick; _btnBack.click = &onClick;
_btnForward.onClickListener = &onClick; _btnForward.click = &onClick;
_pageUp.onClickListener = &onClick; _pageUp.click = &onClick;
_pageDown.onClickListener = &onClick; _pageDown.click = &onClick;
} }
override void measure(int parentWidth, int parentHeight) { override void measure(int parentWidth, int parentHeight) {

View File

@ -108,7 +108,7 @@ class TabItemWidget : HorizontalLayout {
_closeButton.styleId = STYLE_BUTTON_TRANSPARENT; _closeButton.styleId = STYLE_BUTTON_TRANSPARENT;
_closeButton.drawableId = "close"; _closeButton.drawableId = "close";
_closeButton.trackHover = true; _closeButton.trackHover = true;
_closeButton.onClickListener = &onClick; _closeButton.click = &onClick;
if (!_enableCloseButton) { if (!_enableCloseButton) {
_closeButton.visibility = Visibility.Gone; _closeButton.visibility = Visibility.Gone;
} else { } else {
@ -248,7 +248,7 @@ class TabControl : WidgetGroupDefaultDrawing {
_items = new TabItemList(); _items = new TabItemList();
_moreButton = new ImageButton("MORE", "tab_more"); _moreButton = new ImageButton("MORE", "tab_more");
_moreButton.styleId = STYLE_BUTTON_TRANSPARENT; _moreButton.styleId = STYLE_BUTTON_TRANSPARENT;
_moreButton.onClickListener = &onClick; _moreButton.click = &onClick;
_moreButton.margins(Rect(3,3,3,6)); _moreButton.margins(Rect(3,3,3,6));
_enableCloseButton = true; _enableCloseButton = true;
styleId = _tabStyle; styleId = _tabStyle;
@ -387,7 +387,7 @@ class TabControl : WidgetGroupDefaultDrawing {
_items.insert(item, index); _items.insert(item, index);
TabItemWidget widget = new TabItemWidget(item, enableCloseButton); TabItemWidget widget = new TabItemWidget(item, enableCloseButton);
widget.parent = this; widget.parent = this;
widget.onClickListener = &onClick; widget.click = &onClick;
widget.setStyles(_tabButtonStyle, _tabButtonTextStyle); widget.setStyles(_tabButtonStyle, _tabButtonTextStyle);
widget.onTabCloseListener = &onTabClose; widget.onTabCloseListener = &onTabClose;
_children.insert(widget, index); _children.insert(widget, index);

View File

@ -558,13 +558,13 @@ class TreeItemWidget : HorizontalLayout {
_expander.visibility = _item.hasChildren ? Visibility.Visible : Visibility.Invisible; _expander.visibility = _item.hasChildren ? Visibility.Visible : Visibility.Invisible;
//_expander.setState(State.Parent); //_expander.setState(State.Parent);
_expander.onClickListener = delegate(Widget source) { _expander.click = delegate(Widget source) {
_item.selectItem(_item); _item.selectItem(_item);
_item.toggleExpand(_item); _item.toggleExpand(_item);
return true; return true;
}; };
} }
onClickListener = delegate(Widget source) { click = delegate(Widget source) {
long ts = currentTimeMillis(); long ts = currentTimeMillis();
_item.selectItem(_item); _item.selectItem(_item);
if (ts - lastClickTime < DOUBLE_CLICK_TIME_MS) { if (ts - lastClickTime < DOUBLE_CLICK_TIME_MS) {
@ -598,7 +598,7 @@ class TreeItemWidget : HorizontalLayout {
} }
override bool onKeyEvent(KeyEvent event) { override bool onKeyEvent(KeyEvent event) {
if (onKeyListener.assigned && onKeyListener(this, event)) if (keyEvent.assigned && keyEvent(this, event))
return true; // processed by external handler return true; // processed by external handler
if (!focused || !visible) if (!focused || !visible)
return false; return false;
@ -729,7 +729,7 @@ class TreeWidgetBase : ScrollWidget, OnTreeContentChangeListener, OnTreeStateCh
/** Override to use custom tree item widgets. */ /** Override to use custom tree item widgets. */
protected Widget createItemWidget(TreeItem item) { protected Widget createItemWidget(TreeItem item) {
TreeItemWidget res = new TreeItemWidget(item); TreeItemWidget res = new TreeItemWidget(item);
res.onKeyListener = this; res.keyEvent = this;
res.popupMenuListener = &onTreeItemPopupMenu; res.popupMenuListener = &onTreeItemPopupMenu;
return res; return res;
} }

View File

@ -271,12 +271,12 @@ class Widget {
/// override to handle focus changes /// override to handle focus changes
protected void handleFocusChange(bool focused) { protected void handleFocusChange(bool focused) {
invalidate(); invalidate();
onFocusChangeListener(this, focused); focusChange(this, focused);
} }
/// override to handle check changes /// override to handle check changes
protected void handleCheckChange(bool checked) { protected void handleCheckChange(bool checked) {
invalidate(); invalidate();
onCheckChangeListener(this, checked); checkChange(this, checked);
} }
/// set new widget state (set of flags from State enum) /// set new widget state (set of flags from State enum)
@property Widget state(uint newState) { @property Widget state(uint newState) {
@ -1047,8 +1047,8 @@ class Widget {
// called to process click and notify listeners // called to process click and notify listeners
protected bool handleClick() { protected bool handleClick() {
bool res = false; bool res = false;
if (onClickListener.assigned) if (click.assigned)
res = onClickListener(this); res = click(this);
else if (_action) { else if (_action) {
return dispatchAction(_action); return dispatchAction(_action);
} }
@ -1085,7 +1085,7 @@ class Widget {
/// process key event, return true if event is processed. /// process key event, return true if event is processed.
bool onKeyEvent(KeyEvent event) { bool onKeyEvent(KeyEvent event) {
if (onKeyListener.assigned && onKeyListener(this, event)) if (keyEvent.assigned && keyEvent(this, event))
return true; // processed by external handler return true; // processed by external handler
if (event.action == KeyAction.KeyDown) { if (event.action == KeyAction.KeyDown) {
Action action = findKeyAction(event.keyCode, event.flags & (KeyFlag.Shift | KeyFlag.Alt | KeyFlag.Control)); Action action = findKeyAction(event.keyCode, event.flags & (KeyFlag.Shift | KeyFlag.Alt | KeyFlag.Control));
@ -1137,7 +1137,7 @@ class Widget {
/// process mouse event; return true if event is processed by widget. /// process mouse event; return true if event is processed by widget.
bool onMouseEvent(MouseEvent event) { bool onMouseEvent(MouseEvent event) {
if (onMouseListener.assigned && onMouseListener(this, event)) if (mouseEvent.assigned && mouseEvent(this, event))
return true; // processed by external handler return true; // processed by external handler
//Log.d("onMouseEvent ", id, " ", event.action, " (", event.x, ",", event.y, ")"); //Log.d("onMouseEvent ", id, " ", event.action, " (", event.x, ",", event.y, ")");
// support onClick // support onClick
@ -1205,44 +1205,34 @@ class Widget {
/// on click event listener (bool delegate(Widget)) /// on click event listener (bool delegate(Widget))
Signal!OnClickHandler click; Signal!OnClickHandler click;
/// click signal alias for backward compatibility; will be deprecated in future
alias onClickListener = click;
/// checked state change event listener (bool delegate(Widget, bool)) /// checked state change event listener (bool delegate(Widget, bool))
Signal!OnCheckHandler checkChange; Signal!OnCheckHandler checkChange;
/// checkChange signal alias for backward compatibility; will be deprecated in future
alias onCheckChangeListener = checkChange;
/// focus state change event listener (bool delegate(Widget, bool)) /// focus state change event listener (bool delegate(Widget, bool))
Signal!OnFocusHandler focusChange; Signal!OnFocusHandler focusChange;
/// focusChange signal alias for backward compatibility; will be deprecated in future
alias onFocusChangeListener = focusChange;
/// key event listener (bool delegate(Widget, KeyEvent)) - return true if event is processed by handler /// key event listener (bool delegate(Widget, KeyEvent)) - return true if event is processed by handler
Signal!OnKeyHandler keyEvent; Signal!OnKeyHandler keyEvent;
/// keyEvent signal alias for backward compatibility; will be deprecated in future
alias onKeyListener = keyEvent;
/// mouse event listener (bool delegate(Widget, MouseEvent)) - return true if event is processed by handler /// mouse event listener (bool delegate(Widget, MouseEvent)) - return true if event is processed by handler
Signal!OnMouseHandler mouseEvent; Signal!OnMouseHandler mouseEvent;
/// mouseEvent signal alias for backward compatibility; will be deprecated in future
alias onMouseListener = mouseEvent;
/// helper function to add onCheckChangeListener in method chain /// helper function to add onCheckChangeListener in method chain
Widget addOnClickListener(bool delegate(Widget) listener) { Widget addOnClickListener(bool delegate(Widget) listener) {
onClickListener.connect(listener); click.connect(listener);
return this; return this;
} }
/// helper function to add onCheckChangeListener in method chain /// helper function to add onCheckChangeListener in method chain
Widget addOnCheckChangeListener(bool delegate(Widget, bool) listener) { Widget addOnCheckChangeListener(bool delegate(Widget, bool) listener) {
onCheckChangeListener.connect(listener); checkChange.connect(listener);
return this; return this;
} }
/// helper function to add onFocusChangeListener in method chain /// helper function to add onFocusChangeListener in method chain
Widget addOnFocusChangeListener(bool delegate(Widget, bool) listener) { Widget addOnFocusChangeListener(bool delegate(Widget, bool) listener) {
onFocusChangeListener.connect(listener); focusChange.connect(listener);
return this; return this;
} }

View File

@ -69,7 +69,7 @@ class WindowFrame : VerticalLayout {
_closeButton.styleId = STYLE_BUTTON_TRANSPARENT; _closeButton.styleId = STYLE_BUTTON_TRANSPARENT;
_closeButton.drawableId = "close"; _closeButton.drawableId = "close";
_closeButton.trackHover = true; _closeButton.trackHover = true;
_closeButton.onClickListener = &onCloseButtonClick; _closeButton.click = &onCloseButtonClick;
if (!_showCloseButton) if (!_showCloseButton)
_closeButton.visibility = Visibility.Gone; _closeButton.visibility = Visibility.Gone;