Smolgui
Immediate gui library based on SFML
Loading...
Searching...
No Matches
Layout.tpp
Go to the documentation of this file.
1namespace sgui
2{
3/////////////////////////////////////////////////
4template <typename LayoutType>
5bool Layout::has (const std::string& entry) const
6{
7 const auto end = std::string::npos;
8 for (const auto& set : m_setFilenames) {
9 for (const auto& key : m_layoutEntries.at (set)) {
10 if (key.find (layoutTypeName <LayoutType> ()) != end && key.find (entry) != end) {
11 return true;
12 }
13 }
14 }
15 return false;
16}
17
18/////////////////////////////////////////////////
19template <typename LayoutType>
20LayoutType& Layout::get (
21 const std::string& entry,
22 bool addLayoutType)
23{
24 return const_cast <LayoutType&> (std::as_const (*this).get <LayoutType> (entry, addLayoutType));
25}
26
27/////////////////////////////////////////////////
28template <typename LayoutType>
29const LayoutType& Layout::get (
30 const std::string& entry,
31 bool addLayoutType) const
32{
33 // get key. We need these two cases for serialization ease
34 auto key = entry;
35 if (addLayoutType) {
36 key = layoutTypeName <LayoutType> () + entry;
37 }
38
39 // return requested entry
40 if constexpr (std::is_same_v <LayoutType, Panel>) {
41 return m_entries.at (key).panel;
42 } else if constexpr (std::is_same_v <LayoutType, sf::Vector2f>) {
43 return m_entries.at (key).position;
44 } else if constexpr (std::is_same_v <LayoutType, Window>) {
45 return m_entries.at (key).window;
46 } else {
47 return m_entries.at (key).constraints;
48 }
49}
50
51} // namespace sgui