add on_click to buttons
This commit is contained in:
parent
736cef4667
commit
9c267cc87b
3 changed files with 10 additions and 0 deletions
|
@ -40,6 +40,9 @@ void Button::on_focus_update(FocusUpdateEvent &event) {
|
||||||
|
|
||||||
void Button::on_activation_update(ActivationUpdateEvent &event) {
|
void Button::on_activation_update(ActivationUpdateEvent &event) {
|
||||||
update_color();
|
update_color();
|
||||||
|
if (event.get_activation_status() == false) {
|
||||||
|
on_click();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <functional>
|
||||||
#include "Widget.hpp"
|
#include "Widget.hpp"
|
||||||
#include "RGB.hpp"
|
#include "RGB.hpp"
|
||||||
#include "pango/pango-font.h"
|
#include "pango/pango-font.h"
|
||||||
|
@ -19,6 +20,8 @@ public:
|
||||||
void set_text(std::string text) { m_text = text; wants_repaint(); }
|
void set_text(std::string text) { m_text = text; wants_repaint(); }
|
||||||
std::string &get_text() { return m_text; }
|
std::string &get_text() { return m_text; }
|
||||||
|
|
||||||
|
std::function<void()> on_click { [](){} };
|
||||||
|
protected:
|
||||||
void on_paint();
|
void on_paint();
|
||||||
void on_init();
|
void on_init();
|
||||||
void on_focus_update(FocusUpdateEvent &event);
|
void on_focus_update(FocusUpdateEvent &event);
|
||||||
|
|
|
@ -15,6 +15,10 @@ int main() {
|
||||||
main_widget.set_do_background_fill(true);
|
main_widget.set_do_background_fill(true);
|
||||||
window.set_main_widget(&main_widget);
|
window.set_main_widget(&main_widget);
|
||||||
|
|
||||||
|
button.on_click = [&button]() {
|
||||||
|
button.set_text("clicked!");
|
||||||
|
};
|
||||||
|
|
||||||
main_widget.add_child(&button);
|
main_widget.add_child(&button);
|
||||||
|
|
||||||
window.run(true);
|
window.run(true);
|
||||||
|
|
Loading…
Reference in a new issue