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
Chesto::AlertDialog Class Reference
Inheritance diagram for Chesto::AlertDialog:
Inheritance graph
[legend]
Collaboration diagram for Chesto::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 Chesto::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 addNode (std::unique_ptr< Element > node)
 
void remove (Element *element)
 
void removeAll ()
 
void position (int x, int y)
 position the element More...
 
void recalcPosition (Element *parent)
 
float getEffectiveScale () const
 
CST_Rect getBounds ()
 
CST_Renderer * getRenderer ()
 
ElementsetPosition (int x, int y)
 
ElementsetAction (std::function< void()> func)
 
ElementsetAbsolute (bool isAbs)
 
template<typename T , typename... Args>
T * createNode (Args &&... args)
 
Elementconstrain (int flags, int padding=0)
 
ElementconstrainToTarget (Element *target, 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 = nullptr
 
Elementoverlay = nullptr
 
ContainervStack = nullptr
 
int dialogWidth = 450
 
int dialogHeight = 200
 
- Public Attributes inherited from Chesto::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< std::unique_ptr< Element, std::function< void(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 = nullptr
 the parent element (reference only, not owned) 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 cornerRadius = 0
 
int tag = 0
 
std::vector< std::unique_ptr< Constraint > > constraints
 
std::vector< std::unique_ptr< 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 Chesto::Element
typedef Element super
 
- Protected Member Functions inherited from Chesto::Element
void addStackMember (Element *element)
 

Detailed Description

Definition at line 8 of file AlertDialog.hpp.

Constructor & Destructor Documentation

◆ AlertDialog()

Chesto::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 8 of file AlertDialog.cpp.

9 : title(title)
10 , message(message)
11{
20 hidden = true;
21
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; // forces transparency to render properly (via sdl_gfx)
28 overlay->hasBackground = true;
29
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);
37
38 auto innerVStack = vStack->createNode<Container>(COL_LAYOUT, 50);
39 innerVStack->width = dialogWidth;
40 innerVStack->constrain(ALIGN_CENTER_BOTH, 0);
41 // innerVStack->backgroundColor = fromRGB(0xff, 0, 0);
42 // innerVStack->hasBackground = true;
43
44 messageText = innerVStack->createNode<TextElement>("(Placeholder text)", 20, &blackColor, NORMAL, 400);
45 messageText->setText(message);
46 messageText->update(); // to set the size
47 messageText->constrain(ALIGN_CENTER_HORIZONTAL, 0);
48
49 // TODO: add a second button for prompts, not just alerts
50 auto okButton = innerVStack->createNode<Button>("OK", A_BUTTON);
51 okButton->setAction([this]() {
52 if (onConfirm) {
53 onConfirm();
54 }
55 });
56 okButton->cornerRadius = 10;
57 okButton->updateBounds();
58 okButton->constrain(ALIGN_CENTER_HORIZONTAL, 0);
59}
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
Definition: Element.hpp:132
bool hidden
whether this element should skip rendering or not
Definition: Element.hpp:119
void update(bool forceUpdate=false)
update TextElement with changes

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

Member Function Documentation

◆ process()

bool Chesto::AlertDialog::process ( InputEvents event)
overridevirtual

process any input that is received for this element

Reimplemented from Chesto::Element.

Definition at line 101 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:29

References Chesto::Element::process().

◆ render()

void Chesto::AlertDialog::render ( Element parent)
overridevirtual

display the current state of the display

Reimplemented from Chesto::Element.

Definition at line 95 of file AlertDialog.cpp.

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

References Chesto::Element::render().

◆ setText()

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

Definition at line 61 of file AlertDialog.cpp.

62{
63 messageText->setText(newText);
64 messageText->update();
65}

◆ show()

void Chesto::AlertDialog::show ( )

Definition at line 67 of file AlertDialog.cpp.

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

Member Data Documentation

◆ blackColor

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

Definition at line 23 of file AlertDialog.hpp.

◆ dialogHeight

int Chesto::AlertDialog::dialogHeight = 200

Definition at line 32 of file AlertDialog.hpp.

◆ dialogWidth

int Chesto::AlertDialog::dialogWidth = 450

Definition at line 31 of file AlertDialog.hpp.

◆ message

std::string Chesto::AlertDialog::message

Definition at line 16 of file AlertDialog.hpp.

◆ messageText

TextElement* Chesto::AlertDialog::messageText = nullptr

Definition at line 26 of file AlertDialog.hpp.

◆ onCancel

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

Definition at line 18 of file AlertDialog.hpp.

◆ onConfirm

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

Definition at line 17 of file AlertDialog.hpp.

◆ overlay

Element* Chesto::AlertDialog::overlay = nullptr

Definition at line 27 of file AlertDialog.hpp.

◆ title

std::string Chesto::AlertDialog::title

Definition at line 15 of file AlertDialog.hpp.

◆ useAnimation

bool Chesto::AlertDialog::useAnimation = true

Definition at line 19 of file AlertDialog.hpp.

◆ vStack

Container* Chesto::AlertDialog::vStack = nullptr

Definition at line 28 of file AlertDialog.hpp.


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