remove on_click from button and add it to the Widget class
This commit is contained in:
parent
909f911260
commit
55b8353d6d
4 changed files with 7 additions and 14 deletions
|
@ -35,10 +35,4 @@ void Button::on_paint() {
|
||||||
painter.fill();
|
painter.fill();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::on_activation_update(ActivationUpdateEvent &event) {
|
|
||||||
if (event.activation_status() == false) {
|
|
||||||
on_click();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "Widget.hpp"
|
#include "Widget.hpp"
|
||||||
|
@ -5,8 +7,6 @@
|
||||||
#include "pango/pango-font.h"
|
#include "pango/pango-font.h"
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
class Button : public Widget {
|
class Button : public Widget {
|
||||||
|
@ -15,18 +15,12 @@ public:
|
||||||
: Widget(WidgetType::Button)
|
: Widget(WidgetType::Button)
|
||||||
, m_text(text) {}
|
, m_text(text) {}
|
||||||
|
|
||||||
std::function<void()> on_click { [](){} };
|
|
||||||
|
|
||||||
void set_text(std::string text);
|
void set_text(std::string text);
|
||||||
std::string &text() { return m_text; }
|
std::string &text() { return m_text; }
|
||||||
protected:
|
protected:
|
||||||
void on_paint();
|
void on_paint();
|
||||||
void on_init();
|
void on_init();
|
||||||
void on_activation_update(ActivationUpdateEvent &event);
|
|
||||||
private:
|
private:
|
||||||
void update_color();
|
|
||||||
void recompute_text_size();
|
|
||||||
|
|
||||||
std::string m_text;
|
std::string m_text;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -257,6 +257,10 @@ void Widget::handle_mouse_button_event(MouseButtonEvent &event) {
|
||||||
auto activation_update_event = ActivationUpdateEvent(update_activation_to);
|
auto activation_update_event = ActivationUpdateEvent(update_activation_to);
|
||||||
on_activation_update(activation_update_event);
|
on_activation_update(activation_update_event);
|
||||||
|
|
||||||
|
if (update_activation_to == false) {
|
||||||
|
on_click();
|
||||||
|
}
|
||||||
|
|
||||||
if (m_style->update_background()) {
|
if (m_style->update_background()) {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ public:
|
||||||
virtual ~Widget() {};
|
virtual ~Widget() {};
|
||||||
|
|
||||||
std::function<void(Event&)> on_event { [](Event&){} };
|
std::function<void(Event&)> on_event { [](Event&){} };
|
||||||
|
std::function<void()> on_click { [](){} };
|
||||||
|
|
||||||
bool fit_text(std::string &text);
|
bool fit_text(std::string &text);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue