Loading...
Searching...
No Matches
ml::Toast Class Reference

A transient, dismissible notification anchored to an edge of the window. More...

#include <Malena/Graphics/Controls/Toast.h>

Inheritance diagram for ml::Toast:
[legend]

Public Types

enum class  Anchor { TOP , BOTTOM }

Public Member Functions

 Toast ()
sf::FloatRect getGlobalBounds () const override
sf::Vector2f getPosition () const override
void hide ()
bool isVisible () const
void onAction (std::function< void()> cb)
void onDismiss (std::function< void()> cb)
void setActionLabel (const std::string &label)
void setAnchor (Anchor a)
void setMessage (const std::string &text)
void setPosition (const sf::Vector2f &pos) override
void show ()

Protected Member Functions

void draw (sf::RenderTarget &target, sf::RenderStates states) const override

Detailed Description

A transient, dismissible notification anchored to an edge of the window.

A Toast shows a short message with an optional action button (e.g. "Connect") and a dismiss button. It is hidden by default; call show() to reveal it and hide() to remove it. While hidden it draws nothing and its buttons are disabled so they never intercept clicks.

Unlike Modal, a Toast does not block the rest of the UI — it sits in a corner and the user can ignore it. Typical use is a non-intrusive prompt:

ml::Toast toast;
toast.setMessage("Prof. Smith's hub is online");
toast.setActionLabel("Connect");
toast.onAction ([this]{ connectToHub(); });
toast.onDismiss([]{ /* user ignored it *\/ });
* addComponent(toast); // add to the app so it overlays the active scene
* toast.show();
*
A transient, dismissible notification anchored to an edge of the window.
Definition Toast.h:43
void setMessage(const std::string &text)
void onDismiss(std::function< void()> cb)
Definition Toast.h:77
void setActionLabel(const std::string &label)
void onAction(std::function< void()> cb)
Definition Toast.h:76
See also
Modal

Definition at line 42 of file Toast.h.

Member Enumeration Documentation

◆ Anchor

enum class ml::Toast::Anchor
strong
Enumerator
TOP 
BOTTOM 

Definition at line 45 of file Toast.h.

Constructor & Destructor Documentation

◆ Toast()

ml::Toast::Toast ( )

Member Function Documentation

◆ draw()

void ml::Toast::draw ( sf::RenderTarget & target,
sf::RenderStates states ) const
overrideprotected

◆ getGlobalBounds()

sf::FloatRect ml::Toast::getGlobalBounds ( ) const
override

◆ getPosition()

sf::Vector2f ml::Toast::getPosition ( ) const
override

◆ hide()

void ml::Toast::hide ( )

◆ isVisible()

bool ml::Toast::isVisible ( ) const
inlinenodiscard

Definition at line 74 of file Toast.h.

◆ onAction()

void ml::Toast::onAction ( std::function< void()> cb)
inline

Definition at line 76 of file Toast.h.

◆ onDismiss()

void ml::Toast::onDismiss ( std::function< void()> cb)
inline

Definition at line 77 of file Toast.h.

◆ setActionLabel()

void ml::Toast::setActionLabel ( const std::string & label)

◆ setAnchor()

void ml::Toast::setAnchor ( Anchor a)
inline

Definition at line 70 of file Toast.h.

◆ setMessage()

void ml::Toast::setMessage ( const std::string & text)

◆ setPosition()

void ml::Toast::setPosition ( const sf::Vector2f & pos)
override

◆ show()

void ml::Toast::show ( )

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