mirror of https://github.com/buggins/dlangui.git
make tooltips working for list items - fix #303
This commit is contained in:
parent
c41225853c
commit
b07d0aae9b
|
|
@ -868,6 +868,12 @@ class MouseEvent {
|
|||
/// returns point for mouse cursor position
|
||||
@property Point pos() { return Point(_x, _y); }
|
||||
|
||||
/// returns true if no modifier flags are set
|
||||
@property bool noModifiers() { return (_flags & (MouseFlag.Control | MouseFlag.Alt | MouseFlag.Shift)) == 0; }
|
||||
/// returns true if any modifier flag is set
|
||||
@property bool hasModifiers() { return !noModifiers; }
|
||||
|
||||
|
||||
/// Returns true for ButtonDown event when button is pressed second time in short interval after pressing first time
|
||||
@property bool doubleClick() {
|
||||
if (_action != MouseAction.ButtonDown)
|
||||
|
|
@ -1239,6 +1245,8 @@ class KeyEvent {
|
|||
|
||||
/// returns true if no modifier flags are set
|
||||
@property bool noModifiers() { return (_flags & (KeyFlag.Control | KeyFlag.Alt | KeyFlag.Menu | KeyFlag.Shift)) == 0; }
|
||||
/// returns true if any modifier flag is set
|
||||
@property bool hasModifiers() { return !noModifiers; }
|
||||
|
||||
/// create key event
|
||||
this(KeyAction action, uint keyCode, uint flags, dstring text = null) {
|
||||
|
|
|
|||
|
|
@ -322,6 +322,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
|||
btn.orientation = Orientation.Vertical;
|
||||
btn.styleId = STYLE_TRANSPARENT_BUTTON_BACKGROUND;
|
||||
btn.focusable = false;
|
||||
btn.tooltipText = root.path.toUTF32;
|
||||
adapter.add(btn);
|
||||
}
|
||||
res.ownAdapter = adapter;
|
||||
|
|
|
|||
|
|
@ -57,6 +57,11 @@ interface ListAdapter {
|
|||
|
||||
/// called when theme is changed
|
||||
void onThemeChanged();
|
||||
|
||||
/// return true to receive mouse events
|
||||
@property bool wantMouseEvents();
|
||||
/// return true to receive keyboard events
|
||||
@property bool wantKeyEvents();
|
||||
}
|
||||
|
||||
/// List adapter for simple list of widget instances
|
||||
|
|
@ -122,6 +127,16 @@ class ListAdapterBase : ListAdapter {
|
|||
/// called when theme is changed
|
||||
void onThemeChanged() {
|
||||
}
|
||||
|
||||
/// return true to receive mouse events
|
||||
override @property bool wantMouseEvents() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// return true to receive keyboard events
|
||||
override @property bool wantKeyEvents() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// List adapter for simple list of widget instances
|
||||
|
|
@ -176,6 +191,11 @@ class WidgetListAdapter : ListAdapterBase {
|
|||
~this() {
|
||||
//Log.d("Destroying WidgetListAdapter");
|
||||
}
|
||||
|
||||
/// return true to receive mouse events
|
||||
override @property bool wantMouseEvents() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/** List adapter providing strings only. */
|
||||
|
|
@ -1283,6 +1303,9 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler {
|
|||
itemrc.top += rc.top - scrollOffset.y;
|
||||
itemrc.bottom += rc.top - scrollOffset.y;
|
||||
if (itemrc.isPointInside(Point(event.x, event.y))) {
|
||||
Widget itemWidget;
|
||||
if (_adapter.wantMouseEvents)
|
||||
itemWidget = _adapter.itemWidget(i);
|
||||
//Log.d("mouse event action=", event.action, " button=", event.button, " flags=", event.flags);
|
||||
if ((event.flags & (MouseFlag.LButton || MouseFlag.RButton)) || _selectOnHover) {
|
||||
if (_selectedItemIndex != i && itemEnabled(i)) {
|
||||
|
|
@ -1304,12 +1327,31 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (itemWidget) {
|
||||
Widget oldParent = itemWidget.parent;
|
||||
itemWidget.parent = this;
|
||||
if (event.action == MouseAction.Move && event.noModifiers && itemWidget.hasTooltip) {
|
||||
itemWidget.scheduleTooltip(200);
|
||||
}
|
||||
//itemWidget.onMouseEvent(event);
|
||||
itemWidget.parent = oldParent;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// returns true if item is child of this widget (when deepSearch == true - returns true if item is this widget or one of children inside children tree).
|
||||
override bool isChild(Widget item, bool deepSearch = true) {
|
||||
if (_adapter && _adapter.wantMouseEvents) {
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
auto itemWidget = _adapter.itemWidget(i);
|
||||
if (itemWidget is item)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.isChild(item, deepSearch);
|
||||
}
|
||||
}
|
||||
|
||||
class StringListWidget : ListWidget {
|
||||
|
|
|
|||
|
|
@ -790,7 +790,7 @@ public:
|
|||
}
|
||||
|
||||
/// schedule tooltip
|
||||
protected void scheduleTooltip(long delay = 300, uint alignment = 2 /*PopupAlign.Below*/, int x = 0, int y = 0) {
|
||||
void scheduleTooltip(long delay = 300, uint alignment = 2 /*PopupAlign.Below*/, int x = 0, int y = 0) {
|
||||
if (auto w = window)
|
||||
w.scheduleTooltip(this, delay, alignment, x, y);
|
||||
}
|
||||
|
|
@ -1253,7 +1253,7 @@ public:
|
|||
return true;
|
||||
}
|
||||
}
|
||||
if (event.action == MouseAction.Move && event.flags == 0 && hasTooltip) {
|
||||
if (event.action == MouseAction.Move && !event.hasModifiers && hasTooltip) {
|
||||
scheduleTooltip(200);
|
||||
}
|
||||
if (event.action == MouseAction.ButtonDown && event.button == MouseButton.Right) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue