malena
Why malena
Quick start
Tutorials
API docs
GitHub
GitHub
Tutorials
Loading...
Searching...
No Matches
Graphics
Controls
Tab.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_TAB_H
5
#define MALENA_TAB_H
6
7
#pragma once
8
9
#include <
Malena/Core/malena_export.h
>
10
#include <
Malena/Core/Core.h
>
11
#include <
Malena/Utilities/HasSetSize.h
>
12
#include <
SFML/Graphics/Texture.hpp
>
13
#include <
SFML/System/Vector2.hpp
>
14
#include <functional>
15
#include <memory>
16
#include <string>
17
#include <type_traits>
18
19
namespace
ml
20
{
39
class
MALENA_API
Tab
40
{
41
public
:
42
std::string
label
;
43
std::unique_ptr<ml::Core>
content
;
44
std::function<void(
sf::Vector2f
)>
resizeFn
;
45
const
sf::Texture
*
icon
=
nullptr
;
46
bool
closeable
=
false
;
47
float
x
= 0.f;
48
float
width
= 0.f;
49
59
template
<
typename
T>
60
Tab
(
const
std::string&
label
, std::unique_ptr<T>
content
,
61
const
sf::Texture
*
icon
=
nullptr
,
bool
closeable
=
false
)
62
:
label
(
label
),
icon
(
icon
),
closeable
(
closeable
)
63
{
64
static_assert
(std::is_base_of_v<ml::Core, T>,
65
"[Malena] Tab content must derive from ml::Core"
);
66
T* ptr =
content
.get();
67
this->content = std::move(
content
);
68
if
constexpr
(detail::has_setSize<T>::value)
69
resizeFn
= [ptr](
sf::Vector2f
sz){ ptr->setSize(sz); };
70
}
71
72
void
setLabel
(
const
std::string& l) {
label
= l; }
73
void
setIcon
(
const
sf::Texture
* icon_) {
icon
= icon_; }
74
void
setCloseable
(
bool
c) {
closeable
= c; }
75
};
76
77
}
// namespace ml
78
79
#endif
// MALENA_TAB_H
Core.h
HasSetSize.h
Texture.hpp
Vector2.hpp
ml::Tab::resizeFn
std::function< void(sf::Vector2f)> resizeFn
Definition
Tab.h:44
ml::Tab::width
float width
computed by TabbedPanel
Definition
Tab.h:48
ml::Tab::label
std::string label
Definition
Tab.h:42
ml::Tab::setIcon
void setIcon(const sf::Texture *icon_)
Definition
Tab.h:73
ml::Tab::content
std::unique_ptr< ml::Core > content
Definition
Tab.h:43
ml::Tab::x
float x
computed by TabbedPanel
Definition
Tab.h:47
ml::Tab::icon
const sf::Texture * icon
Definition
Tab.h:45
ml::Tab::Tab
Tab(const std::string &label, std::unique_ptr< T > content, const sf::Texture *icon=nullptr, bool closeable=false)
Construct a tab with owned content.
Definition
Tab.h:60
ml::Tab::setLabel
void setLabel(const std::string &l)
Definition
Tab.h:72
ml::Tab::setCloseable
void setCloseable(bool c)
Definition
Tab.h:74
ml::Tab::closeable
bool closeable
Definition
Tab.h:46
sf::Texture
malena_export.h
MALENA_API
#define MALENA_API
Definition
malena_export.h:18
ml
Definition
Component.h:22
sf::Vector2f
Vector2< float > Vector2f