From 094ac735e16ad94c12bc1d866253f1c1d84a9af6 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 17 Jul 2020 23:08:03 +0200 Subject: Added Widget::tooltip() support. Minor cleanups. --- src/ui/widget.cc | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/ui/widget.cc') diff --git a/src/ui/widget.cc b/src/ui/widget.cc index 982b792..8c40c04 100644 --- a/src/ui/widget.cc +++ b/src/ui/widget.cc @@ -228,14 +228,31 @@ void Widget::set_label(const std::string & label) widget_label.assign(label); aux::to_label(widget_label); } - + void Widget::set_label(const char *label) { - if (label) { + if (label == nullptr) + { + widget_label.clear(); + } else { widget_label.assign(label); aux::to_label(widget_label); + } +} + + +void Widget::set_tooltip(const std::string &tooltip) +{ + widget_tooltip.assign(tooltip); +} + +void Widget::set_tooltip(const char *tooltip) +{ + if (tooltip == nullptr) + { + widget_tooltip.clear(); } else { - widget_label.clear(); + widget_label.assign(tooltip); } } @@ -300,7 +317,7 @@ Widget *Widget::next_sibling() // find this widget in the parent's children Children::iterator it = parent()->children().begin(); while (it != parent()->children().end() && ((*it) != this)) { - it++; + it++; } // assert this widget is a child of its parent @@ -384,17 +401,17 @@ Widget *Widget::find_visible_child(const Widget *widget) return 0; } -Widget *Widget::find_mouse_focus(const math::Vector2f & pos) +Widget *Widget::find_widget_in_location(const math::Vector2f & location) { // this widget is not visible - if (!visible() || !size().contains(pos)) - return 0; + if (!visible() || !size().contains(location)) + return nullptr; // reverse-iterate children for (Children::reverse_iterator rit = widget_children.rbegin(); rit != widget_children.rend(); ++rit) { Widget *w = (*rit); if (w->visible() && w->enabled()) { - Widget *f = w->find_mouse_focus(pos - w->location()); + Widget *f = w->find_widget_in_location(location - w->location()); if (f) return f; } -- cgit v1.2.3