ComboEdit enhancements - issue #224

This commit is contained in:
Vadim Lopatin 2016-04-22 12:17:11 +03:00
parent 53e13ff706
commit c32df24ad9
4 changed files with 41 additions and 7 deletions

View File

@ -49,6 +49,7 @@ extern (C) int UIAppMain(string[] args) {
ComboEdit { id: ce1; text: "some text"; minWidth: 100; items: ["Item 1", "Item 2", "Additional item"] }
}
}
EditBox { layoutWidth: 300; layoutHeight: 80 }
HorizontalLayout {
Button { id: btnOk; text: "Ok" }
Button { id: btnCancel; text: "Cancel" }

View File

@ -118,6 +118,9 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
_button.layout(rc);
}
protected void popupClosed() {
}
protected void showPopup() {
if (!_adapter || !_adapter.itemCount)
return; // don't show empty popup
@ -138,6 +141,7 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
if (_popup !is null) {
_popup.close();
_popup = null;
popupClosed();
}
return true;
};
@ -490,14 +494,29 @@ class ComboEdit : ComboBox {
focusable = false;
clickable = false;
_edit.focusable = true;
keyEvent = delegate(Widget source, KeyEvent event) {
if (event.keyCode == KeyCode.DOWN) {
if (event.action == KeyAction.KeyDown) {
showPopup();
}
}
/// process key event, return true if event is processed.
override bool onKeyEvent(KeyEvent event) {
if (event.keyCode == KeyCode.DOWN && enabled) {
if (event.action == KeyAction.KeyDown) {
showPopup();
}
return _edit.onKeyEvent(event);
};
return true;
}
if ((event.keyCode == KeyCode.SPACE || event.keyCode == KeyCode.RETURN) && readOnly && enabled) {
if (event.action == KeyAction.KeyDown) {
showPopup();
}
return true;
}
if (_edit.onKeyEvent(event))
return true;
return super.onKeyEvent(event);
}
override protected void popupClosed() {
_edit.setFocus();
}
// called to process click and notify listeners

View File

@ -1624,6 +1624,12 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
}
return true;
}
if (event.keyCode == KeyCode.SPACE && !readOnly) {
return true;
}
if (event.keyCode == KeyCode.RETURN && !readOnly && !_content.multiline) {
return true;
}
return super.onKeyEvent(event);
}

View File

@ -1211,6 +1211,14 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler {
// TODO
}
}
if ((event.keyCode == KeyCode.SPACE || event.keyCode == KeyCode.RETURN)) {
if (event.action == KeyAction.KeyDown && enabled) {
if (itemEnabled(_selectedItemIndex)) {
itemClicked(_selectedItemIndex);
}
}
return true;
}
return super.onKeyEvent(event);
//if (_selectedItemIndex != -1 && event.action == KeyAction.KeyUp && (event.keyCode == KeyCode.SPACE || event.keyCode == KeyCode.RETURN)) {
// itemClicked(_selectedItemIndex);