From 55b8353d6de0b8f200f24dc08452b6a11b7b9f7a Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Thu, 28 Jul 2022 18:54:29 +0300 Subject: [PATCH] remove on_click from button and add it to the Widget class --- src/Button.cpp | 6 ------ src/Button.hpp | 10 ++-------- src/Widget.cpp | 4 ++++ src/Widget.hpp | 1 + 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Button.cpp b/src/Button.cpp index 1a88a66..53f270c 100644 --- a/src/Button.cpp +++ b/src/Button.cpp @@ -35,10 +35,4 @@ void Button::on_paint() { painter.fill(); } -void Button::on_activation_update(ActivationUpdateEvent &event) { - if (event.activation_status() == false) { - on_click(); - } -} - } diff --git a/src/Button.hpp b/src/Button.hpp index c543970..47ebddf 100644 --- a/src/Button.hpp +++ b/src/Button.hpp @@ -1,3 +1,5 @@ +#pragma once + #include #include #include "Widget.hpp" @@ -5,8 +7,6 @@ #include "pango/pango-font.h" #include "Window.hpp" -#pragma once - namespace Raven { class Button : public Widget { @@ -15,18 +15,12 @@ public: : Widget(WidgetType::Button) , m_text(text) {} - std::function on_click { [](){} }; - void set_text(std::string text); std::string &text() { return m_text; } protected: void on_paint(); void on_init(); - void on_activation_update(ActivationUpdateEvent &event); private: - void update_color(); - void recompute_text_size(); - std::string m_text; }; diff --git a/src/Widget.cpp b/src/Widget.cpp index a8f7174..6f0bf40 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -257,6 +257,10 @@ void Widget::handle_mouse_button_event(MouseButtonEvent &event) { auto activation_update_event = ActivationUpdateEvent(update_activation_to); on_activation_update(activation_update_event); + if (update_activation_to == false) { + on_click(); + } + if (m_style->update_background()) { repaint(); } diff --git a/src/Widget.hpp b/src/Widget.hpp index 1fcb94f..2707d7f 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -44,6 +44,7 @@ public: virtual ~Widget() {}; std::function on_event { [](Event&){} }; + std::function on_click { [](){} }; bool fit_text(std::string &text);