support simple text popups; issue #43 is completed

This commit is contained in:
Vadim Lopatin 2015-02-12 15:38:12 +03:00
parent 08e9cd8d06
commit 4ffd0af922
2 changed files with 18 additions and 2 deletions

View File

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

View File

@ -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;
}