Add a bit more functionality to the controls

This commit is contained in:
Magnus Norddahl 2023-12-27 04:46:14 +01:00 committed by Christoph Oelckers
commit b7362aa3f2
7 changed files with 164 additions and 6 deletions

View file

@ -13,13 +13,19 @@ public:
void SetChecked(bool value);
bool GetChecked() const;
void Toggle();
double GetPreferredHeight() const;
protected:
void OnPaint(Canvas* canvas) override;
void OnMouseDown(const Point& pos, int key) override;
void OnMouseUp(const Point& pos, int key) override;
void OnMouseLeave() override;
void OnKeyUp(EInputKey key) override;
private:
std::string text;
bool checked = false;
bool mouseDownActive = false;
};

View file

@ -14,6 +14,10 @@ public:
protected:
void OnPaint(Canvas* canvas) override;
void OnPaintFrame(Canvas* canvas) override;
void OnMouseDown(const Point& pos, int key) override;
void OnMouseDoubleclick(const Point& pos, int key) override;
void OnKeyDown(EInputKey key) override;
std::vector<std::string> items;
int selectedItem = 0;
};

View file

@ -2,6 +2,7 @@
#pragma once
#include "../../core/widget.h"
#include <functional>
class PushButton : public Widget
{
@ -13,10 +14,22 @@ public:
double GetPreferredHeight() const;
void Click();
std::function<void()> OnClick;
protected:
void OnPaintFrame(Canvas* canvas) override;
void OnPaint(Canvas* canvas) override;
void OnMouseMove(const Point& pos) override;
void OnMouseDown(const Point& pos, int key) override;
void OnMouseUp(const Point& pos, int key) override;
void OnMouseLeave() override;
void OnKeyDown(EInputKey key) override;
void OnKeyUp(EInputKey key) override;
private:
std::string text;
bool buttonDown = false;
bool hot = false;
};