neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
label.hpp
Go to the documentation of this file.
1// label.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
27
28namespace neogfx
29{
30 class i_spacer;
31
54
56 {
57 return static_cast<label_placement>(static_cast<uint32_t>(aLhs) | static_cast<uint32_t>(aRhs));
58 }
59
61 {
62 return static_cast<label_placement>(static_cast<uint32_t>(aLhs) & static_cast<uint32_t>(aRhs));
63 }
64}
65
75declare_enum_string(neogfx::label_placement, TextSpacerImageHorizontal)
76declare_enum_string(neogfx::label_placement, TextSpacerImageVertical)
77declare_enum_string(neogfx::label_placement, ImageSpacerTextHorizontal)
78declare_enum_string(neogfx::label_placement, ImageSpacerTextVertical)
80
81namespace neogfx
82{
83 typedef text_widget_type label_type;
84
85 class label : public widget<>
86 {
87 meta_object(widget<>)
88 public:
89 struct no_center_spacer : std::logic_error { no_center_spacer() : std::logic_error("neogfx::label::no_center_spacer") {} };
90 struct no_buddy : std::logic_error { no_buddy() : std::logic_error("neogfx::label::no_buddy") {} };
91 public:
92 label(label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
93 label(std::string const& aText, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
94 label(const i_texture& aTexture, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
95 label(const i_image& aImage, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
96 label(std::string const& aText, const i_texture& aTexture, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
97 label(std::string const& aText, const i_image& aImage, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
98 label(i_widget& aParent, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
99 label(i_widget& aParent, std::string const& aText, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
100 label(i_widget& aParent, const i_texture& aTexture, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
101 label(i_widget& aParent, const i_image& aImage, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
102 label(i_widget& aParent, std::string const& aText, const i_texture& aTexture, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
103 label(i_widget& aParent, std::string const& aText, const i_image& aImage, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
104 label(i_layout& aLayout, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
105 label(i_layout& aLayout, std::string const& aText, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
106 label(i_layout& aLayout, const i_texture& aTexture, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
107 label(i_layout& aLayout, const i_image& aImage, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
108 label(i_layout& aLayout, std::string const& aText, const i_texture& aTexture, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
109 label(i_layout& aLayout, std::string const& aText, const i_image& aImage, label_type aType = label_type::MultiLine, neogfx::alignment aAlignment = neogfx::alignment::Left | neogfx::alignment::VCenter, label_placement aPlacement = label_placement::ImageTextHorizontal);
110 ~label();
111 public:
112 const grid_layout& layout() const override;
113 grid_layout& layout() override;
114 public:
115 neogfx::size_policy size_policy() const override;
116 public:
117 void set_font_role(const optional_font_role& aFontRole) override;
118 void set_font(optional_font const& aFont) override;
119 public:
121 void set_alignment(neogfx::alignment aAlignment);
122 public:
123 i_string const& text() const;
124 void set_text(i_string const& aText);
125 const texture& image() const;
126 void set_image(i_string const& aImageUri);
127 void set_image(const neogfx::image& aImage);
128 void set_image(const texture& aImage);
129 label_placement placement() const;
130 void set_placement(label_placement aPlacement);
131 label_placement effective_placement() const;
132 const neogfx::text_widget& text_widget() const;
133 neogfx::text_widget& text_widget();
134 const neogfx::image_widget& image_widget() const;
135 neogfx::image_widget& image_widget();
136 const i_spacer& center_spacer() const;
137 i_spacer& center_spacer();
138 bool has_buddy() const;
139 i_widget& buddy() const;
140 void set_buddy(i_widget& aBuddy);
141 void set_buddy(std::shared_ptr<i_widget> aBuddy);
142 void unset_buddy();
143 private:
144 void init();
145 void handle_placement_change();
146 private:
147 sink iSink;
148 neogfx::alignment iAlignment;
149 label_placement iPlacement;
150 grid_layout iLayout;
151 size_policy_of_parent<neogfx::text_widget, layout_item_category::Widget> iText;
152 size_policy_of_parent<neogfx::image_widget, layout_item_category::Widget> iImage;
153 i_spacer* iCenterSpacer;
154 std::shared_ptr<i_widget> iBuddy;
155 };
156}
#define end_declare_enum(enumName)
Definition i_enum.hpp:62
#define declare_enum_string(enumName, enumEnumerator)
Definition i_enum.hpp:59
#define begin_declare_enum(enumName)
Definition i_enum.hpp:52
constexpr style_aspect operator&(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:60
optional< font_role > optional_font_role
Definition i_style.hpp:74
constexpr style_aspect operator|(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:55
label_placement
Definition label.hpp:33
Definition plf_hive.h:79
#define meta_object(...)
Definition i_object.hpp:28