Implement UIWindow

This commit is contained in:
MrLetsplay 2024-01-19 19:00:31 +01:00
parent 5691afe59b
commit 9b9f7a286a
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
3 changed files with 93 additions and 26 deletions

View File

@ -90,21 +90,6 @@ void TextElement::draw(UIPoint screenPos, glm::mat4 projection) {
}
}
UIWindow::UIWindow(UIValue x, UIValue y)
: UIElement(x, y) {
addChild(new TextElement(x, y));
}
UIWindow::~UIWindow() {
}
UIElementType UIWindow::getType() {
return UIElementType::WINDOW;
}
void UIWindow::draw(UIPoint screenPos, glm::mat4 projection) {
}
static float rectangleVerts[] = {
0.0f,
1.0f,
@ -345,4 +330,62 @@ void TextFieldElement::setText(std::string text) {
this->cursorPos = 0;
updateText(Unicode::convertStdToU32(text));
}
UIWindowTitleBar::UIWindowTitleBar(UIValue height)
: RectangleElement(uiPx(0), uiPx(0), uiPw(1), height) {
this->color = Colors::GRAY;
this->draggable = true;
text = new TextElement(x, uiPh(0.5));
text->setText("Window title");
text->textMode = TextMode::ORIGIN;
text->origin = Origin::LEFT_CENTER;
addChild(text);
closeButton = new ButtonElement(uiPw(1) - uiPx(30), uiPx(0), uiPx(30), uiPh(1));
closeButton->text->setText("X");
closeButton->color = Colors::RED;
closeButton->hoverColor = Colors::RED.darker();
addChild(closeButton);
}
void UIWindowTitleBar::dragEnter(UIPoint pos, UIPoint screenPos) {
// TODO
}
void UIWindowTitleBar::drag(UIPoint pos, UIPoint screenPos) {
// TODO
}
void UIWindowTitleBar::dragExit(UIPoint pos, UIPoint screenPos) {
// TODO
}
UIWindow::UIWindow(UIValue x, UIValue y, UIValue w, UIValue h)
: UIElement(x, y) {
this->w = w;
this->h = h;
this->background = new RectangleElement(x, y, w, h);
background->color = Colors::GRAY.darker();
addChild(background);
this->titleBar = new UIWindowTitleBar(uiPx(25));
addChild(titleBar);
}
UIWindow::~UIWindow() {
}
UIElementType UIWindow::getType() {
return UIElementType::WINDOW;
}
UIBounds UIWindow::getBounds() {
return offsetUIBounds(uiToScreen(w), uiToScreen(h), origin);
}
void UIWindow::draw(UIPoint screenPos, glm::mat4 projection) {
}
}

View File

@ -6,17 +6,6 @@
namespace kek {
class UIWindow: public UIElement {
UIWindow(UIValue x, UIValue y);
virtual ~UIWindow();
virtual UIElementType getType();
virtual void draw(UIPoint screenPos, glm::mat4 projection);
};
enum class TextMode {
// Draw with y as baseline, disables vertical offset from the origin position specified using setOrigin()
BASELINE,
@ -135,4 +124,36 @@ class TextFieldElement: public RectangleElement {
void setText(std::string text);
};
class UIWindowTitleBar: public RectangleElement {
public:
TextElement *text;
ButtonElement *closeButton;
UIWindowTitleBar(UIValue height);
virtual void dragEnter(UIPoint pos, UIPoint screenPos);
virtual void drag(UIPoint pos, UIPoint screenPos);
virtual void dragExit(UIPoint pos, UIPoint screenPos);
};
class UIWindow: public UIElement {
public:
RectangleElement *background;
UIWindowTitleBar *titleBar;
UIValue w, h;
UIWindow(UIValue x, UIValue y, UIValue w, UIValue h);
virtual ~UIWindow();
virtual UIElementType getType();
virtual UIBounds getBounds();
virtual void draw(UIPoint screenPos, glm::mat4 projection);
};
}

View File

@ -172,6 +172,9 @@ int main(int argc, char **argv) {
rect2->addChild(box);
rect2->addChild(text);
UIWindow *window = new UIWindow(uiPx(0), uiPx(0), uiPx(720), uiPx(480));
UI::addElement(window);
if(Engine::start() != KEK_SUCCESS) return 1;
return 0;
}