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)
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")

View File

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

View File

@ -49,12 +49,12 @@ extern (C) int UIAppMain(string[] args) {
auto edit1 = window.mainWidget.childById!EditLine("edit1");
auto edit2 = window.mainWidget.childById!EditLine("edit2");
// 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();
return true;
};
// 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),
UIString("Editors content\nEdit1: "d ~ edit1.text ~ "\nEdit2: "d ~ edit2.text));
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, "http://github.com/buggins/dlangui"d));
Button closeButton = new Button("close", "Close"d);
closeButton.onClickListener = delegate(Widget src) {
closeButton.click = delegate(Widget src) {
Log.i("Closing window");
res.window.close();
return true;
@ -521,7 +521,7 @@ class StatusWidget : VerticalLayout {
ImageWidget image = new ImageWidget(null, "tetris_logo_big");
image.layoutWidth(FILL_PARENT).alignment(Align.Center).clickable(true);
image.onClickListener = delegate(Widget src) {
image.click = delegate(Widget src) {
_cup.handleAction(ACTION_PAUSE);
// about dialog when clicking on image
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.styleId = STYLE_BUTTON_TRANSPARENT;
_text.clickable = true;
_text.onClickListener = &onTextClick;
_text.click = &onTextClick;
//_text.backgroundColor = 0xC0FFFF;
_text.state = State.Parent;
_button = new ImageButton(null, "scrollbar_btn_right");
_button.styleId = STYLE_BUTTON_TRANSPARENT;
_button.focusable = false;
_button.onClickListener = &onButtonClick;
_button.click = &onButtonClick;
//_button.backgroundColor = 0xC0FFC0;
_button.state = State.Parent;
trackHover(true);
@ -619,8 +619,8 @@ class FilePathPanel : FrameLayout {
_edPath = new EditLine(ID_EDITOR);
_edPath.layoutWidth = FILL_PARENT;
_edPath.editorActionListener = &onEditorAction;
_edPath.onFocusChangeListener = &onEditorFocusChanged;
_segments.onClickListener = &onSegmentsClickOutside;
_edPath.focusChange = &onEditorFocusChanged;
_segments.click = &onSegmentsClickOutside;
_segments.onPathSelectionListener = &onPathSelected;
addChild(_segments);
addChild(_edPath);

View File

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

View File

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

View File

@ -641,16 +641,16 @@ class ScrollBar : AbstractSlider, OnClickHandler {
return true;
}
if (event.action == MouseAction.FocusOut && _dragging) {
Log.d("ScrollBar slider dragging - FocusOut");
debug(scrollbar) Log.d("ScrollBar slider dragging - FocusOut");
return true;
}
if (event.action == MouseAction.FocusIn && _dragging) {
Log.d("ScrollBar slider dragging - FocusIn");
debug(scrollbar) Log.d("ScrollBar slider dragging - FocusIn");
return true;
}
if (event.action == MouseAction.Move && _dragging) {
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;
int offset;
int space;
@ -696,25 +696,25 @@ class ScrollBar : AbstractSlider, OnClickHandler {
}
if (event.action == MouseAction.Move && trackHover) {
if (!(state & State.Hovered)) {
Log.d("Hover ", id);
debug(scrollbar) Log.d("Hover ", id);
setState(State.Hovered);
}
return true;
}
if (event.action == MouseAction.Leave && trackHover) {
Log.d("Leave ", id);
debug(scrollbar) Log.d("Leave ", id);
resetState(State.Hovered);
return true;
}
if (event.action == MouseAction.Cancel && trackHover) {
Log.d("Cancel ? trackHover", id);
debug(scrollbar) Log.d("Cancel ? trackHover", id);
resetState(State.Hovered);
resetState(State.Pressed);
_dragging = false;
return true;
}
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);
_dragging = false;
return true;
@ -814,10 +814,10 @@ class ScrollBar : AbstractSlider, OnClickHandler {
_indicator.focusable = false;
_pageUp.focusable = false;
_pageDown.focusable = false;
_btnBack.onClickListener = &onClick;
_btnForward.onClickListener = &onClick;
_pageUp.onClickListener = &onClick;
_pageDown.onClickListener = &onClick;
_btnBack.click = &onClick;
_btnForward.click = &onClick;
_pageUp.click = &onClick;
_pageDown.click = &onClick;
}
override void measure(int parentWidth, int parentHeight) {

View File

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

View File

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

View File

@ -271,12 +271,12 @@ class Widget {
/// override to handle focus changes
protected void handleFocusChange(bool focused) {
invalidate();
onFocusChangeListener(this, focused);
focusChange(this, focused);
}
/// override to handle check changes
protected void handleCheckChange(bool checked) {
invalidate();
onCheckChangeListener(this, checked);
checkChange(this, checked);
}
/// set new widget state (set of flags from State enum)
@property Widget state(uint newState) {
@ -1047,8 +1047,8 @@ class Widget {
// called to process click and notify listeners
protected bool handleClick() {
bool res = false;
if (onClickListener.assigned)
res = onClickListener(this);
if (click.assigned)
res = click(this);
else if (_action) {
return dispatchAction(_action);
}
@ -1085,7 +1085,7 @@ class Widget {
/// process key event, return true if event is processed.
bool onKeyEvent(KeyEvent event) {
if (onKeyListener.assigned && onKeyListener(this, event))
if (keyEvent.assigned && keyEvent(this, event))
return true; // processed by external handler
if (event.action == KeyAction.KeyDown) {
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.
bool onMouseEvent(MouseEvent event) {
if (onMouseListener.assigned && onMouseListener(this, event))
if (mouseEvent.assigned && mouseEvent(this, event))
return true; // processed by external handler
//Log.d("onMouseEvent ", id, " ", event.action, " (", event.x, ",", event.y, ")");
// support onClick
@ -1205,44 +1205,34 @@ class Widget {
/// on click event listener (bool delegate(Widget))
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))
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))
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
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
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
Widget addOnClickListener(bool delegate(Widget) listener) {
onClickListener.connect(listener);
click.connect(listener);
return this;
}
/// helper function to add onCheckChangeListener in method chain
Widget addOnCheckChangeListener(bool delegate(Widget, bool) listener) {
onCheckChangeListener.connect(listener);
checkChange.connect(listener);
return this;
}
/// helper function to add onFocusChangeListener in method chain
Widget addOnFocusChangeListener(bool delegate(Widget, bool) listener) {
onFocusChangeListener.connect(listener);
focusChange.connect(listener);
return this;
}

View File

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