输出测试,RenderableString基本完成
This commit is contained in:
@@ -4,10 +4,45 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "def.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
class Widget : public Renderable {
|
||||
protected:
|
||||
int left = 0, top = 0, width = 0, height = 0;
|
||||
mutable bool hasMouse = false;
|
||||
|
||||
public:
|
||||
using Action = Function<void()>;
|
||||
double x, y, w, h;
|
||||
Action hover;
|
||||
Action longHover;
|
||||
Action mouseDown;
|
||||
Action mouseUp;
|
||||
Action mouseLeave;
|
||||
explicit Widget(const double x, const double y, const double w, const double h) : x(x), y(y), w(w), h(h) {}
|
||||
void render() const noexcept override {}
|
||||
virtual void onResize() {}
|
||||
|
||||
virtual bool isMouseIn(int x, int y) noexcept {
|
||||
x -= left;
|
||||
y -= top;
|
||||
if (0 <= x and x <= width and 0 <= y and y <= height) hasMouse = true;
|
||||
hasMouse = false;
|
||||
return hasMouse;
|
||||
}
|
||||
|
||||
virtual void onHover() noexcept { if (hover) hover(); }
|
||||
virtual void onLongHover() noexcept { if (longHover) longHover(); }
|
||||
virtual void onMouseDown() noexcept { if (mouseDown) mouseDown(); }
|
||||
virtual void onMouseUp() noexcept { if (mouseUp) mouseUp(); }
|
||||
virtual void onMouseLeave() noexcept { if (mouseLeave) mouseLeave(); }
|
||||
};
|
||||
|
||||
class Window : public Renderable {
|
||||
protected:
|
||||
List<Widget*> widgets;
|
||||
|
||||
Window() = default;
|
||||
|
||||
public:
|
||||
@@ -24,4 +59,17 @@ public:
|
||||
* 注意,关闭未必就是删除。
|
||||
*/
|
||||
virtual void onClose() = 0;
|
||||
virtual void onResize();
|
||||
};
|
||||
|
||||
class FloatWindow final : public Window {
|
||||
public:
|
||||
void render() const noexcept override;
|
||||
bool onOpen() override { return true; }
|
||||
void onClose() override {}
|
||||
};
|
||||
|
||||
class Button final : public Widget {
|
||||
public:
|
||||
explicit Button(const double x, const double y, const double w, const double h) : Widget(x, y, w, h) {}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user