Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
Public Member Functions | Public Attributes | List of all members
AlertDialog Class Reference
Inheritance diagram for AlertDialog:
Inheritance graph
[legend]
Collaboration diagram for AlertDialog:
Collaboration graph
[legend]

Public Member Functions

 AlertDialog (const std::string &title, const std::string &message)
 
void show ()
 
void setText (const std::string &newText)
 
virtual void render (Element *parent) override
 display the current state of the display More...
 
virtual bool process (InputEvents *event) override
 process any input that is received for this element More...
 
- Public Member Functions inherited from Element
virtual bool process (InputEvents *event)
 process any input that is received for this element More...
 
virtual void render (Element *parent)
 display the current state of the display More...
 
bool onTouchDown (InputEvents *event)
 
bool onTouchDrag (InputEvents *event)
 
bool onTouchUp (InputEvents *event)
 
void hide ()
 
void unhide ()
 
void renderBackground (bool fill=true)
 
void append (Element *element)
 
void remove (Element *element)
 
void removeAll (bool moveToTrash=false)
 
void position (int x, int y)
 position the element More...
 
void recalcPosition (Element *parent)
 
CST_Rect getBounds ()
 
CST_Renderer * getRenderer ()
 
void wipeAll (bool delSelf=false)
 
Elementchild (Element *child)
 
ElementsetPosition (int x, int y)
 
ElementsetAction (std::function< void()> func)
 
ElementcenterHorizontallyIn (Element *parent)
 
ElementcenterVerticallyIn (Element *parent)
 
ElementcenterIn (Element *parent)
 
ElementsetAbsolute (bool isAbs)
 
Elementconstrain (int flags, int padding=0)
 
Elementanimate (int durationIn, std::function< void(float)> onStep, std::function< void()> onFinish)
 
ElementmoveToFront ()
 
ElementsetTouchable (bool touchable)
 
void screenshot (std::string path)
 Take a screenshot of this element and its children, and save it to the given path. More...
 

Public Attributes

std::string title
 
std::string message
 
std::function< void()> onConfirm
 
std::function< void()> onCancel
 
bool useAnimation = true
 
CST_Color blackColor = CST_Color{0, 0, 0, 0xff}
 
TextElementmessageText = new TextElement("(Placeholder text)", 20, &blackColor, NORMAL, 400)
 
Elementoverlay = new Element()
 
ContainervStack = new Container(COL_LAYOUT, 50)
 
int dialogWidth = 450
 
int dialogHeight = 200
 
- Public Attributes inherited from Element
std::function< void()> action = NULL
 the action to call (from binded callback) on touch or button selection https://stackoverflow.com/questions/14189440/c-class-member-callback-simple-examples More...
 
std::function< void(InputEvents *event)> actionWithEvents = NULL
 
std::vector< Element * > elements
 visible GUI child elements of this element More...
 
float scale = 1.0f
 
bool touchable = false
 whether or not this element can be touched (highlights bounds) More...
 
bool dragging = false
 whether or not this element is currently being dragged More...
 
bool needsRedraw = false
 whether or not this element needs the screen redrawn next time it's processed More...
 
int futureRedrawCounter = 0
 whether this element needs a redraw for the next X redraws (decreases each time) (0 is no redraws) More...
 
int lastMouseY = 0
 the last Y, X coordinate of the mouse (from a drag probably) More...
 
int lastMouseX = 0
 
bool hasBackground = false
 
rgb backgroundColor = {0, 0, 0}
 
int backgroundOpacity = 0xff
 
bool isAbsolute = false
 
Elementparent = NULL
 the parent element (can sometimes be null if it isn't set) More...
 
bool hidden = false
 whether this element should skip rendering or not More...
 
bool isProtected = false
 
int elasticCounter = 0
 how much time is left in an elastic-type flick/scroll set by the last distance traveled in a scroll, and counts down every frame More...
 
int width = 0
 width and height of this element (must be manually set, isn't usually calculated (but is in some cases, like text or images)) More...
 
int height = 0
 
int x = 0
 
int y = 0
 
int xAbs = 0
 
int yAbs = 0
 
double angle = 0
 rotation angle in degrees More...
 
int xOff = 0
 
int yOff = 0
 
int cornerRadius = 0
 
std::vector< Constraint * > constraints
 
std::vector< Animation * > animations
 
bool useColorMask = false
 whether or not to overlay a color mask on top of this element More...
 
CST_Color maskColor = {0,0,0,0}
 The color to overlay on top. More...
 

Additional Inherited Members

- Public Types inherited from Element
typedef Element super
 

Detailed Description

Definition at line 6 of file AlertDialog.hpp.

Constructor & Destructor Documentation

◆ AlertDialog()

AlertDialog::AlertDialog ( const std::string &  title,
const std::string &  message 
)

AlertDialog

  • Overlay (full screen dimmer, 100% width/height)
    • VStack (border of window, centered with light bg, dialog dimensions)
      • VStack (inner content, sized to fit the inner content)

Definition at line 6 of file AlertDialog.cpp.

7 : title(title), message(message)
8{
17 hidden = true;
18
19 messageText->setText(message);
20 messageText->update(); // to set the size
21
22 // just add the single button for now
23 auto okButton = (new Button("OK", A_BUTTON));
24 okButton->setAction([this]() {
25 if (onConfirm) onConfirm();
26 });
27 okButton->cornerRadius = 10;
28 okButton->updateBounds();
29
30 auto innerVStack = new Container(COL_LAYOUT, 50);
31 innerVStack->add(messageText);
32 innerVStack->add(okButton);
33 innerVStack->width = dialogWidth;
34 // innerVStack->backgroundColor = fromRGB(0xff, 0, 0);
35 // innerVStack->hasBackground = true;
36
37 messageText->constrain(ALIGN_CENTER_HORIZONTAL, 0);
38 okButton->constrain(ALIGN_CENTER_HORIZONTAL, 0);
39
40 // prompt background color
41 vStack->backgroundColor = fromRGB(0xdd, 0xdd, 0xdd);
42 vStack->hasBackground = true;
43 vStack->cornerRadius = 15;
44 vStack->width = dialogWidth;
45 vStack->height = dialogHeight;
46 vStack->add(innerVStack);
47
48 innerVStack->constrain(ALIGN_CENTER_BOTH, 0);
49
50 // overlay and shade bg color
51 overlay->width = RootDisplay::mainDisplay->width;
52 overlay->height = RootDisplay::mainDisplay->height;
53 overlay->backgroundColor = fromRGB(0, 0, 0);
54 overlay->backgroundOpacity = 0x00;
55 overlay->cornerRadius = 1; // forces transparency to render properly (via sdl_gfx)
56 overlay->hasBackground = true;
57
58 overlay->child(vStack);
59
60 vStack->constrain(ALIGN_CENTER_BOTH, 0);
61
62 this->child(overlay);
63}
Definition: Button.hpp:7
bool hidden
whether this element should skip rendering or not
Definition: Element.hpp:110
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
Definition: Element.hpp:123
void update(bool forceUpdate=false)
update TextElement with changes
Definition: TextElement.cpp:90

References Element::hidden, TextElement::update(), and Element::width.

Member Function Documentation

◆ process()

bool AlertDialog::process ( InputEvents event)
overridevirtual

process any input that is received for this element

Reimplemented from Element.

Definition at line 102 of file AlertDialog.cpp.

102 {
103 // Implementation for processing input events
104 return super::process(event);
105}
virtual bool process(InputEvents *event)
process any input that is received for this element
Definition: Element.cpp:17

References Element::process().

◆ render()

void AlertDialog::render ( Element parent)
overridevirtual

display the current state of the display

Reimplemented from Element.

Definition at line 97 of file AlertDialog.cpp.

97 {
98 // Implementation for rendering the dialog
99 super::render(this);
100}
virtual void render(Element *parent)
display the current state of the display
Definition: Element.cpp:60

References Element::render().

◆ setText()

void AlertDialog::setText ( const std::string &  newText)

Definition at line 65 of file AlertDialog.cpp.

65 {
66 messageText->setText(newText);
67 messageText->update();
68}

◆ show()

void AlertDialog::show ( )

Definition at line 70 of file AlertDialog.cpp.

70 {
71 // we have to go from being 100% transparent and small size to being opaque and full size
72 // TODO: need opacity that affects all children elements
73 hidden = false;
74
75 if (useAnimation) {
76 // start animation
77 animate(250, [this](float progress) {
78 // on step
79 this->vStack->width = (dialogWidth * progress);
80 this->vStack->height = (dialogHeight * progress);
81 this->overlay->backgroundOpacity = (int)(0x80 * progress);
82 }, [this]() {
83 this->vStack->width = dialogWidth;
84 this->vStack->height = dialogHeight;
85 this->overlay->backgroundOpacity = 0x80;
86 });
87 return;
88 }
89
90 // no animation, just do it!
91 // this->setVisible(true);
92 this->width = dialogWidth;
93 this->width = dialogHeight;
94
95}

Member Data Documentation

◆ blackColor

CST_Color AlertDialog::blackColor = CST_Color{0, 0, 0, 0xff}

Definition at line 21 of file AlertDialog.hpp.

◆ dialogHeight

int AlertDialog::dialogHeight = 200

Definition at line 28 of file AlertDialog.hpp.

◆ dialogWidth

int AlertDialog::dialogWidth = 450

Definition at line 27 of file AlertDialog.hpp.

◆ message

std::string AlertDialog::message

Definition at line 14 of file AlertDialog.hpp.

◆ messageText

TextElement* AlertDialog::messageText = new TextElement("(Placeholder text)", 20, &blackColor, NORMAL, 400)

Definition at line 22 of file AlertDialog.hpp.

◆ onCancel

std::function<void()> AlertDialog::onCancel

Definition at line 16 of file AlertDialog.hpp.

◆ onConfirm

std::function<void()> AlertDialog::onConfirm

Definition at line 15 of file AlertDialog.hpp.

◆ overlay

Element* AlertDialog::overlay = new Element()

Definition at line 23 of file AlertDialog.hpp.

◆ title

std::string AlertDialog::title

Definition at line 13 of file AlertDialog.hpp.

◆ useAnimation

bool AlertDialog::useAnimation = true

Definition at line 17 of file AlertDialog.hpp.

◆ vStack

Container* AlertDialog::vStack = new Container(COL_LAYOUT, 50)

Definition at line 24 of file AlertDialog.hpp.


The documentation for this class was generated from the following files: