diff --git a/examples/example1/src/example1.d b/examples/example1/src/example1.d index 0306c44a..7d43fe4b 100644 --- a/examples/example1/src/example1.d +++ b/examples/example1/src/example1.d @@ -516,7 +516,7 @@ extern (C) int UIAppMain(string[] args) { layout3.addChild(new TextWidget(null, "Buttons in HorizontalLayout"d)); WidgetGroup buttons1 = new HorizontalLayout(); buttons1.addChild(new TextWidget(null, "Button widgets: "d)); - buttons1.addChild(new Button("btn1", "Button"d)); + buttons1.addChild((new Button("btn1", "Button"d)).tooltipText("Tooltip text for button"d)); buttons1.addChild((new Button("btn2", "Disabled Button"d)).enabled(false)); buttons1.addChild(new TextWidget(null, "ImageButton widgets: "d)); buttons1.addChild(new ImageButton("btn3", "text-plain")); diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index 9b4da932..3e1b1855 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -682,12 +682,28 @@ class Widget { } } + protected UIString _tooltipText; + /// tooltip text - when not empty, widget will show tooltips automatically; for advanced tooltips - override hasTooltip and createTooltip + @property dstring tooltipText() { return _tooltipText; } + /// tooltip text - when not empty, widget will show tooltips automatically; for advanced tooltips - override hasTooltip and createTooltip + @property Widget tooltipText(dstring text) { _tooltipText = text; return this; } + /// tooltip text - when not empty, widget will show tooltips automatically; for advanced tooltips - override hasTooltip and createTooltip + @property Widget tooltipText(UIString text) { _tooltipText = text; return this; } + + /// returns true if widget has tooltip to show @property bool hasTooltip() { - return false; + return !_tooltipText.empty; } /// will be called from window once tooltip request timer expired; if null is returned, popup will not be shown; you can change alignment and position of popup here Widget createTooltip(int mouseX, int mouseY, ref uint alignment, ref int x, ref int y) { + // default implementation supports tooltips when tooltipText property is set + if (!_tooltipText.empty) { + import dlangui.widgets.controls; + Widget res = new TextWidget("tooltip", _tooltipText.value); + res.styleId = STYLE_TOOLTIP; + return res; + } return null; }