add simple button widget
This commit is contained in:
parent
529c286b8f
commit
9fe7659a0f
5 changed files with 13 additions and 8 deletions
|
@ -9,6 +9,7 @@ executable(
|
|||
'./src/Box.cpp',
|
||||
'./src/Events.cpp',
|
||||
'./src/Widget.cpp',
|
||||
'./src/Button.cpp',
|
||||
'./src/Painter.cpp',
|
||||
'./src/Window.cpp',
|
||||
'./src/main.cpp',
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
#include "Button.hpp"
|
||||
#include "Box.hpp"
|
||||
#include "Window.hpp"
|
||||
|
||||
namespace Raven {
|
||||
|
||||
void Button::on_paint() {
|
||||
auto painter = get_window()->get_painter();
|
||||
auto ctx = painter.get_cairo();
|
||||
|
||||
auto cr = painter.get_cairo();
|
||||
|
||||
cr->set_source_rgb(0.866, 0.713, 0.949);
|
||||
painter.rounded_rectangle(get_current_geometry(), 8);
|
||||
cr->fill();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ private:
|
|||
std::string m_text;
|
||||
public:
|
||||
Button(std::string text)
|
||||
: Widget()
|
||||
, m_text(text) {}
|
||||
: m_text(text)
|
||||
, Widget() {}
|
||||
|
||||
void set_text(std::string text) { m_text = text; wants_repaint(); }
|
||||
std::string &get_text() { return m_text; }
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
virtual void on_mouse_move(MouseMoveEvent &event) {};
|
||||
virtual void on_paint() {};
|
||||
|
||||
virtual ~Widget() = default;
|
||||
virtual ~Widget() {};
|
||||
private:
|
||||
void process_event(Event &event);
|
||||
void handle_repaint_requested(WidgetRepaintRequestedEvent &event);
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
#include <iostream>
|
||||
#include "Window.hpp"
|
||||
#include "Widget.hpp"
|
||||
#include "Button.hpp"
|
||||
#include "Box.hpp"
|
||||
|
||||
int main() {
|
||||
Raven::Window window {};
|
||||
Raven::Widget main_widget {};
|
||||
Raven::Button button {"click me!"};
|
||||
|
||||
window.spawn_window();
|
||||
|
||||
main_widget.set_current_geometry(Raven::Box(10, 10, 100, 30));
|
||||
window.set_main_widget(&main_widget);
|
||||
button.set_current_geometry(Raven::Box(10, 10, 100, 30));
|
||||
window.set_main_widget(&button);
|
||||
|
||||
window.run(true);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue