Draw and event position relative to parent (for pages)

This commit is contained in:
dec05eba
2024-08-01 22:19:59 +02:00
parent 67216467d4
commit 10a5669330
15 changed files with 280 additions and 150 deletions

View File

@@ -1,25 +1,28 @@
#pragma once
#include "Widget.hpp"
#include <string>
#include <functional>
#include <mglpp/graphics/Color.hpp>
#include <mglpp/graphics/Text.hpp>
namespace gsr {
class Button : public Widget {
public:
Button(mgl::vec2f size);
Button(mgl::Font *font, const char *text, mgl::vec2f size, mgl::Color bg_color);
Button(const Button&) = delete;
Button& operator=(const Button&) = delete;
bool on_event(mgl::Event &event, mgl::Window &window) override;
void draw(mgl::Window &window) override;
bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override;
void draw(mgl::Window &window, mgl::vec2f offset) override;
mgl::vec2f get_size() const { return size; }
std::function<void()> on_click;
private:
mgl::vec2f size;
mgl::Color bg_color;
bool mouse_inside = false;
bool pressed_inside = false;
mgl::Text text;
};
}