Smolgui
Immediate gui library based on SFML
Loading...
Searching...
No Matches
Layout.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5#include <utility>
6#include <unordered_map>
7
10
11namespace sgui
12{
14
18{
19 LayoutEntry () = default;
20 // data
23 sf::Vector2f position;
25};
26
27
29
32class Layout
33{
34public:
38 bool loadFromFile (const std::string& set);
42 void saveInFile (const bool compact = false);
46 std::vector<std::string> entries (const std::string& set) const;
50 void add (
51 const std::string& set,
52 const std::string& entry,
53 LayoutEntry&& data);
57 template <typename LayoutType>
58 bool has (const std::string& entry) const;
62 template <typename LayoutType>
63 LayoutType& get (
64 const std::string& entry,
65 bool addLayoutType = true);
69 template <typename LayoutType>
70 const LayoutType& get (
71 const std::string& entry,
72 bool addLayoutType = true) const;
73private:
74 std::vector <std::string> m_setFilenames;
75 std::unordered_map <std::string, LayoutEntry> m_entries;
76 std::unordered_map <std::string, std::vector <std::string>> m_layoutEntries;
77};
78
79
81
84template <typename LayoutData>
85constexpr std::string layoutTypeName ()
86{
87 if constexpr (std::is_same_v <LayoutData, Panel>) {
88 return std::string ("Panel::");
89 } else if constexpr (std::is_same_v <LayoutData, sf::Vector2f>) {
90 return std::string ("Position::");
91 } else if constexpr (std::is_same_v <LayoutData, Window>) {
92 return std::string ("Window::");
93 } else {
94 return std::string ("Constraints::");
95 }
96 return "Err::";
97}
98
99} // namespace sgui
100
allow to store and load Gui layou
Definition Layout.h:33
LayoutType & get(const std::string &entry, bool addLayoutType=true)
get entry data without any sanity check
bool has(const std::string &entry) const
test if entry exist
std::vector< std::string > entries(const std::string &set) const
get entries names in a layout
Definition Layout.cpp:25
void add(const std::string &set, const std::string &entry, LayoutEntry &&data)
add or remove an entry to the layout
Definition Layout.cpp:34
const LayoutType & get(const std::string &entry, bool addLayoutType=true) const
get mutable entry data without any sanity check
void saveInFile(const bool compact=false)
save all layouts in their respecting file
Definition Layout.cpp:17
bool loadFromFile(const std::string &set)
load layouts from file
Definition Layout.cpp:7
Definition Interpolation.h:16
constexpr std::string layoutTypeName()
return special prefix to avoid name collision and to infer type from file
Definition Layout.h:85
Store constraints on position for gui panel. Alignment always precede relative position.
Definition Constraints.h:36
Data structure stored in Layout. Its a dumb std::variant basically...
Definition Layout.h:18
LayoutEntry()=default
Panel panel
Definition Layout.h:21
sf::Vector2f position
Definition Layout.h:23
Window window
Definition Layout.h:22
Constraints constraints
Definition Layout.h:24
store panel posiiton, size and some parameters
Definition Panel.h:16
small struct to ease use of beginPanel and beginWindow in Gui
Definition Panel.h:41