Loading...
Searching...
No Matches
Toast.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith.
2// Malena Framework — Licensed under PolyForm Noncommercial 1.0.0; commercial use requires a paid license. See LICENSE.
3
4#ifndef MALENA_TOAST_H
5#define MALENA_TOAST_H
6
7#pragma once
8
14#include <functional>
15#include <string>
16
17namespace ml
18{
42 class MALENA_API Toast : public Component<>
43 {
44 public:
45 enum class Anchor { TOP, BOTTOM };
46
47 private:
49 ml::Text _message;
50 ml::RectangleButton _action;
51 ml::RectangleButton _dismiss;
52
53 bool _visible = false;
54 bool _hasAction = false;
55 Anchor _anchor = Anchor::BOTTOM;
56
57 std::function<void()> _onAction;
58 std::function<void()> _onDismiss;
59
60 void layout();
61
62 protected:
63 void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
64
65 public:
67
68 void setMessage(const std::string& text);
69 void setActionLabel(const std::string& label); // empty hides the action button
70 void setAnchor(Anchor a) { _anchor = a; }
71
72 void show();
73 void hide();
74 [[nodiscard]] bool isVisible() const { return _visible; }
75
76 void onAction (std::function<void()> cb) { _onAction = std::move(cb); }
77 void onDismiss(std::function<void()> cb) { _onDismiss = std::move(cb); }
78
79 void setPosition(const sf::Vector2f& pos) override;
80 sf::Vector2f getPosition() const override;
82 };
83
84} // namespace ml
85
86#endif // MALENA_TOAST_H
Primary base class for all user-facing Malena components.
Definition Component.h:299
A rectangular button with a centered text label.
A framework-integrated text object with word-wrap support.
Definition Text.h:57
void setPosition(const sf::Vector2f &pos) override
void setMessage(const std::string &text)
void onDismiss(std::function< void()> cb)
Definition Toast.h:77
void setAnchor(Anchor a)
Definition Toast.h:70
void setActionLabel(const std::string &label)
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
void show()
bool isVisible() const
Definition Toast.h:74
void hide()
sf::FloatRect getGlobalBounds() const override
void onAction(std::function< void()> cb)
Definition Toast.h:76
sf::Vector2f getPosition() const override
#define MALENA_API
Definition Animate.h:25
Rect< float > FloatRect
Vector2< float > Vector2f