1#include "AlertDialog.hpp"
3#include "Constraint.hpp"
4#include "Container.hpp"
22 overlay = createNode<Element>();
23 overlay->
width = RootDisplay::mainDisplay->width;
24 overlay->height = RootDisplay::mainDisplay->height;
25 overlay->backgroundColor = fromRGB(0, 0, 0);
26 overlay->backgroundOpacity = 0x00;
27 overlay->cornerRadius = 1;
28 overlay->hasBackground =
true;
30 vStack = overlay->createNode<
Container>(COL_LAYOUT, 50);
31 vStack->backgroundColor = fromRGB(0xdd, 0xdd, 0xdd);
32 vStack->hasBackground =
true;
33 vStack->cornerRadius = 15;
34 vStack->
width = dialogWidth;
35 vStack->height = dialogHeight;
36 vStack->constrain(ALIGN_CENTER_BOTH, 0);
38 auto innerVStack = vStack->createNode<
Container>(COL_LAYOUT, 50);
39 innerVStack->
width = dialogWidth;
40 innerVStack->constrain(ALIGN_CENTER_BOTH, 0);
44 messageText = innerVStack->createNode<
TextElement>(
"(Placeholder text)", 20, &blackColor, NORMAL, 400);
45 messageText->setText(message);
47 messageText->constrain(ALIGN_CENTER_HORIZONTAL, 0);
50 auto okButton = innerVStack->createNode<
Button>(
"OK", A_BUTTON);
51 okButton->setAction([
this]() {
56 okButton->cornerRadius = 10;
57 okButton->updateBounds();
58 okButton->constrain(ALIGN_CENTER_HORIZONTAL, 0);
61void AlertDialog::setText(
const std::string& newText)
63 messageText->setText(newText);
67void AlertDialog::show()
76 animate(250, [
this](
float progress)
79 this->vStack->
width = (dialogWidth * progress);
80 this->vStack->height = (dialogHeight * progress);
81 this->overlay->backgroundOpacity = (int)(0x80 * progress); }, [
this]()
83 this->vStack->
width = dialogWidth;
84 this->vStack->height = dialogHeight;
85 this->overlay->backgroundOpacity = 0x80; });
91 this->
width = dialogWidth;
92 this->
width = dialogHeight;
virtual void render(Element *parent) override
display the current state of the display
virtual bool process(InputEvents *event) override
process any input that is received for this element
AlertDialog(const std::string &title, const std::string &message)
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
virtual void render(Element *parent)
display the current state of the display
bool hidden
whether this element should skip rendering or not
virtual bool process(InputEvents *event)
process any input that is received for this element
void update(bool forceUpdate=false)
update TextElement with changes