Loading...
Searching...
No Matches
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
10#include <Malena/Core/Core.h>
14#include <functional>
15#include <memory>
16#include <string>
17#include <type_traits>
18
19namespace ml
20{
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)
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
std::function< void(sf::Vector2f)> resizeFn
Definition Tab.h:44
float width
computed by TabbedPanel
Definition Tab.h:48
std::string label
Definition Tab.h:42
void setIcon(const sf::Texture *icon_)
Definition Tab.h:73
std::unique_ptr< ml::Core > content
Definition Tab.h:43
float x
computed by TabbedPanel
Definition Tab.h:47
const sf::Texture * icon
Definition Tab.h:45
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
void setLabel(const std::string &l)
Definition Tab.h:72
void setCloseable(bool c)
Definition Tab.h:74
bool closeable
Definition Tab.h:46
#define MALENA_API
Definition Component.h:22
Vector2< float > Vector2f