mirror of https://github.com/buggins/dlangui.git
popup menus
This commit is contained in:
parent
61b8fe91d4
commit
c96d74ee18
|
@ -381,7 +381,6 @@ class ListWidget : WidgetGroup, OnScrollHandler {
|
|||
} else {
|
||||
scrollOffset.x = _scrollPosition;
|
||||
}
|
||||
// todo: scrollOffset
|
||||
// draw items
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
Rect itemrc = _itemRects[i];
|
||||
|
@ -400,5 +399,34 @@ class ListWidget : WidgetGroup, OnScrollHandler {
|
|||
}
|
||||
}
|
||||
|
||||
/// process mouse event; return true if event is processed by widget.
|
||||
override bool onMouseEvent(MouseEvent event) {
|
||||
Log.d("onMouseEvent ", id, " ", event.action, " (", event.x, ",", event.y, ")");
|
||||
// support onClick
|
||||
Rect rc = _pos;
|
||||
applyMargins(rc);
|
||||
applyPadding(rc);
|
||||
Point scrollOffset;
|
||||
if (_orientation == Orientation.Vertical) {
|
||||
scrollOffset.y = _scrollPosition;
|
||||
} else {
|
||||
scrollOffset.x = _scrollPosition;
|
||||
}
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
Rect itemrc = _itemRects[i];
|
||||
itemrc.left += rc.left - scrollOffset.x;
|
||||
itemrc.right += rc.left - scrollOffset.x;
|
||||
itemrc.top += rc.top - scrollOffset.y;
|
||||
itemrc.bottom += rc.top - scrollOffset.y;
|
||||
if (itemrc.isPointInside(Point(event.x, event.y))) {
|
||||
Widget w = itemWidget(i);
|
||||
if (w.onMouseEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onMouseEvent(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ class MainMenu : HorizontalLayout, MenuItemWidgetHandler {
|
|||
}
|
||||
}
|
||||
|
||||
class PopupMenu : ListWidget {
|
||||
class PopupMenu : ListWidget, MenuItemWidgetHandler {
|
||||
protected MenuItem _item;
|
||||
this(MenuItem item) {
|
||||
id = "popup_menu";
|
||||
|
@ -160,8 +160,30 @@ class PopupMenu : ListWidget {
|
|||
for (int i=0; i < _item.subitemCount; i++) {
|
||||
MenuItem subitem = _item.subitem(i);
|
||||
MenuItemWidget widget = new MenuItemWidget(subitem);
|
||||
widget.handler = this;
|
||||
adapter.widgets.add(widget);
|
||||
}
|
||||
ownAdapter = adapter;
|
||||
}
|
||||
|
||||
override protected bool onItemMouseDown(MenuItemWidget itemWidget, MouseEvent ev) {
|
||||
if (itemWidget.item.isSubmenu()) {
|
||||
PopupMenu popupMenu = new PopupMenu(itemWidget.item);
|
||||
PopupWidget popup = window.showPopup(popupMenu, itemWidget, PopupAlign.Below);
|
||||
ev.track(popupMenu);
|
||||
} else {
|
||||
// normal item
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
override protected bool onItemMouseUp(MenuItemWidget itemWidget, MouseEvent ev) {
|
||||
if (itemWidget.item.isSubmenu()) {
|
||||
} else {
|
||||
// normal item
|
||||
// TODO: action
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue