Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/widget.h')
-rw-r--r--src/ui/widget.h100
1 files changed, 60 insertions, 40 deletions
diff --git a/src/ui/widget.h b/src/ui/widget.h
index 14bea7b..9c7871f 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -23,6 +23,8 @@
namespace ui
{
+class Tooltip;
+
class Widget
{
@@ -129,6 +131,11 @@ public:
inline const std::string &label() const {
return widget_label;
}
+
+ /// widget tooltip
+ inline Tooltip *tooltip() {
+ return widget_tooltip;
+ }
/// true if this widget will draw a background
inline const bool background() const {
@@ -220,29 +227,35 @@ public:
/// set location of the top-left corner, relative to the parent
void set_location(const math::Vector2f &location);
- /// set the widgets width and height
+ /// set the widget's width and height
void set_size(const float w, const float h);
- /// set the widgets width and height
+ /// set the widget's width and height
void set_size(const math::Vector2f &size);
- /// set the widgets width
+ /// set the widget's width
void set_width(const float w);
- /// set the widgets height
+ /// set the widget's height
void set_height(const float h);
- /// set the widgets palette
+ /// set the widget's palette
void set_palette(const Palette *palette);
- /// set the widgets font
+ /// set the widget's font
void set_font(const Font *font);
- /// set the widgets label
+ /// set the widget's label
void set_label(const std::string &label);
- /// set the widgets label
- void set_label(const char *label);
+ /// set the widget's label
+ void set_label(const char *label = nullptr);
+
+ /// set the wdiget's tooltip text
+ void set_tooltip(const std::string &tooltip_text);
+
+ /// set the wdiget's tooltip text
+ void set_tooltip(const char *tooltip_text = nullptr);
/// enable or disable widget border
void set_border(const bool border = true);
@@ -262,7 +275,7 @@ public:
* @brief calls the draw event handler and sends the event to all child widgets
* @see draw
**/
- void event_draw();
+ virtual void event_draw();
/**
* @brief calls the key event handlers and sends unhandled keys to the parent widget
@@ -303,37 +316,14 @@ public:
inline void emit(const Event event, void *data=0) {
event_emit(this, event, data);
}
-
-protected:
-
- /// find the widget that has input focus
- virtual Widget *find_input_focus();
-
- /// find widget that has mouse focus
- /** @param cursor mouse cursor position relative to this widget's location
- */
- Widget *find_mouse_focus(const math::Vector2f & cursor);
- /// find a visible widget
- Widget *find_visible_child(const Widget *widget);
-
- /// list widget content
- size_t list(const size_t indent, const bool visible_only = false) const;
-
- /// print widget description
- virtual void print(const size_t indent) const;
-
- /// true of this sibling has local focus
- inline bool focus() const {
- return widget_focus;
- }
-
+
/* -- coordinate mapping ----------------------------------- */
/// map local widget location to global location
- inline math::Vector2f global_location() {
+ inline const math::Vector2f global_location() const {
math::Vector2f v(widget_location);
- Widget *parent = widget_parent;
+ const Widget *parent = widget_parent;
while (parent) {
v += parent->location();
parent = parent->parent();
@@ -342,9 +332,9 @@ protected:
}
/// map local coordinates to global coordinates
- inline math::Vector2f to_global_coords(const math::Vector2f &local) {
+ inline const math::Vector2f to_global_coords(const math::Vector2f &local) const {
math::Vector2f v(local);
- Widget *parent = widget_parent;
+ const Widget *parent = widget_parent;
do {
v += parent->location();
parent = parent->parent();
@@ -353,9 +343,9 @@ protected:
}
/// map global coordinates to local coordinates
- inline math::Vector2f to_local_coords(const math::Vector2f &global) {
+ inline const math::Vector2f to_local_coords(const math::Vector2f &global) const {
math::Vector2f v(global);
- Widget *parent = this;
+ const Widget *parent = this;
while (parent) {
v -= parent->location();
parent = parent->parent();
@@ -363,6 +353,34 @@ protected:
return v;
}
+protected:
+
+ /// find the widget that has input focus
+ virtual Widget *find_input_focus();
+
+ /**
+ * @brief find the widget in a given location
+ * Searches the widget's children tree for the leaf widget visible in a given location.
+ * If no child contains the location, the widget itself is tested. Returns a nullptr ig
+ * the location is not within the widget's boundries.
+ * @param location search position, relative to this widget's location
+ **/
+ Widget *find_widget_in_location(const math::Vector2f &location);
+
+ /// find a visible widget
+ Widget *find_visible_child(const Widget *widget);
+
+ /// list widget content
+ size_t list(const size_t indent, const bool visible_only = false) const;
+
+ /// print widget description
+ virtual void print(const size_t indent) const;
+
+ /// true of this sibling has local focus
+ inline bool focus() const {
+ return widget_focus;
+ }
+
/* -- event handlers --------------------------------------- */
/// called when the mouse receives mouse movement
@@ -437,6 +455,8 @@ private:
const Palette *widget_palette;
const Font *widget_font;
Widget *widget_parent;
+
+ Tooltip *widget_tooltip;
Children::iterator find_child(Widget *child);