From 41ec4ed68571091f2e2500344a7aeb527a91dc92 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 18 Jul 2020 17:20:32 +0200 Subject: Added standard close button widget class, added tooltips where approriate. --- src/ui/iconbutton.cc | 7 ++++--- src/ui/iconbutton.h | 4 ++-- src/ui/tooltip.cc | 9 ++++++++- src/ui/tooltip.h | 7 ++++++- 4 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src/ui') diff --git a/src/ui/iconbutton.cc b/src/ui/iconbutton.cc index 18bfb5a..c23ed66 100644 --- a/src/ui/iconbutton.cc +++ b/src/ui/iconbutton.cc @@ -18,14 +18,15 @@ namespace ui { -IconButton::IconButton(Widget *parent, const char *icon, const char *command) : Widget(parent) +IconButton::IconButton(Widget *parent, const char *icon, const char *tooltip, const char *command) : Widget(parent) { set_label("iconbutton"); set_background(false); set_border(false); - set_command(command); - set_icon(icon); set_highlight(false); + set_icon(icon); + set_tooltip(tooltip); + set_command(command); } IconButton::~IconButton() diff --git a/src/ui/iconbutton.h b/src/ui/iconbutton.h index 92e73ee..0382e1a 100644 --- a/src/ui/iconbutton.h +++ b/src/ui/iconbutton.h @@ -15,8 +15,8 @@ namespace ui class IconButton : public Widget { public: - IconButton(Widget *parent, const char *icon = 0, const char *command = 0); - ~IconButton(); + IconButton(Widget *parent, const char *icon = 0, const char *tooltip = 0, const char *command = 0); + virtual ~IconButton(); /// the command this button executes inline const std::string & command() const { diff --git a/src/ui/tooltip.cc b/src/ui/tooltip.cc index 95f1ac8..b1e8c3c 100644 --- a/src/ui/tooltip.cc +++ b/src/ui/tooltip.cc @@ -6,6 +6,7 @@ #include "ui/tooltip.h" #include "ui/ui.h" +#include "ui/paint.h" #include @@ -32,9 +33,15 @@ void Tooltip::resize() set_location((parent()->width() - width()) * 0.5f, parent()->height()); } +void Tooltip::draw_background() +{ + Paint::draw_material(global_location(), size(), "ui/window"); +} + void Tooltip::draw() { - if (tooltip_global != this) { + if (tooltip_global != this) + { hide(); } else { Label::draw(); diff --git a/src/ui/tooltip.h b/src/ui/tooltip.h index 2345973..0cfa12d 100644 --- a/src/ui/tooltip.h +++ b/src/ui/tooltip.h @@ -19,7 +19,7 @@ class Tooltip : public Label { public: Tooltip(Widget *parent); - ~Tooltip(); + virtual ~Tooltip(); /** * @brief resize the tooltip @@ -51,6 +51,11 @@ class Tooltip : public Label */ virtual void draw(); + /** + * @brief draw the tooltip background + */ + virtual void draw_background(); + private: static Tooltip *tooltip_global; -- cgit v1.2.3