malena
Why malena
Quick start
Tutorials
API docs
GitHub
GitHub
Tutorials
Loading...
Searching...
No Matches
Graphics
Controls
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
9
#include <
Malena/Core/malena_export.h
>
10
#include <
Malena/Core/Component.h
>
11
#include <
Malena/Graphics/Text/Text.h
>
12
#include <
Malena/Graphics/Controls/RectangleButton.h
>
13
#include <
SFML/Graphics/RectangleShape.hpp
>
14
#include <functional>
15
#include <string>
16
17
namespace
ml
18
{
42
class
MALENA_API
Toast
:
public
Component
<>
43
{
44
public
:
45
enum class
Anchor
{ TOP, BOTTOM };
46
47
private
:
48
sf::RectangleShape
_bg;
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
:
66
Toast
();
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
;
81
sf::FloatRect
getGlobalBounds
()
const override
;
82
};
83
84
}
// namespace ml
85
86
#endif
// MALENA_TOAST_H
Component.h
RectangleButton.h
RectangleShape.hpp
Text.h
ml::Component
Primary base class for all user-facing Malena components.
Definition
Component.h:299
ml::RectangleButton
A rectangular button with a centered text label.
Definition
RectangleButton.h:48
ml::Text
A framework-integrated text object with word-wrap support.
Definition
Text.h:57
ml::Toast::setPosition
void setPosition(const sf::Vector2f &pos) override
ml::Toast::setMessage
void setMessage(const std::string &text)
ml::Toast::onDismiss
void onDismiss(std::function< void()> cb)
Definition
Toast.h:77
ml::Toast::setAnchor
void setAnchor(Anchor a)
Definition
Toast.h:70
ml::Toast::setActionLabel
void setActionLabel(const std::string &label)
ml::Toast::draw
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
ml::Toast::show
void show()
ml::Toast::isVisible
bool isVisible() const
Definition
Toast.h:74
ml::Toast::hide
void hide()
ml::Toast::getGlobalBounds
sf::FloatRect getGlobalBounds() const override
ml::Toast::Toast
Toast()
ml::Toast::onAction
void onAction(std::function< void()> cb)
Definition
Toast.h:76
ml::Toast::getPosition
sf::Vector2f getPosition() const override
ml::Toast::Anchor
Anchor
Definition
Toast.h:45
sf::RectangleShape
sf::RenderTarget
malena_export.h
MALENA_API
#define MALENA_API
Definition
malena_export.h:18
ml
Definition
Animate.h:25
sf::FloatRect
Rect< float > FloatRect
sf::Vector2f
Vector2< float > Vector2f
ml::Anchor
Definition
Anchor.h:56
sf::RenderStates