neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
text_widget.hpp
Go to the documentation of this file.
1// text_widget.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#pragma once
20
21#include <neogfx/neogfx.hpp>
24
25namespace neogfx
26{
27 class text_widget : public widget<i_text_widget>
28 {
30 public:
31 define_event(TextChanged, text_changed)
32 define_event(TextGeometryChanged, text_geometry_changed)
33 private:
34 typedef std::variant<std::monostate, neogfx::glyph_text, neogfx::multiline_glyph_text> glyph_text_t;
35 public:
36 text_widget(std::string const& aText = std::string{}, text_widget_type aType = text_widget_type::SingleLine, text_widget_flags aFlags = text_widget_flags::None);
37 text_widget(i_widget& aParent, std::string const& aText = std::string{}, text_widget_type aType = text_widget_type::SingleLine, text_widget_flags aFlags = text_widget_flags::None);
38 text_widget(i_layout& aLayout, std::string const& aText = std::string{}, text_widget_type aType = text_widget_type::SingleLine, text_widget_flags aFlags = text_widget_flags::None);
40 public:
41 neogfx::size_policy size_policy() const override;
42 size minimum_size(optional_size const& aAvailableSpace = optional_size{}) const override;
43 public:
44 void paint(i_graphics_context& aGc) const override;
45 public:
46 void set_font(optional_font const& aFont) override;
47 public:
48 bool visible() const override;
49 public:
50 i_string const& text() const override;
51 void set_text(i_string const& aText) override;
52 void set_size_hint(const size_hint& aSizeHint) override;
53 bool multi_line() const override;
54 text_widget_flags flags() const override;
55 void set_flags(text_widget_flags aFlags) override;
56 neogfx::alignment alignment() const override;
57 void set_alignment(neogfx::alignment aAlignment, bool aUpdateLayout = true) override;
58 bool has_text_color() const override;
59 color text_color() const override;
60 void set_text_color(const optional_color& aTextColor) override;
61 bool has_text_format() const override;
62 neogfx::text_format text_format() const override;
63 void set_text_format(const optional_text_format& aTextAppearance) override;
64 protected:
67 private:
68 void init();
69 const glyph_text_t& glyph_text() const;
70 void reset_cache();
71 private:
72 string iText;
73 mutable glyph_text_t iGlyphText;
74 mutable optional_size iTextExtent;
75 size_hint iSizeHint;
76 mutable optional_size iSizeHintExtent;
77 text_widget_type iType;
78 text_widget_flags iFlags;
79 neogfx::alignment iAlignment;
80 optional_text_format iTextAppearance;
81 sink iSink;
82 };
83}
bool has_text_format() const override
void set_size_hint(const size_hint &aSizeHint) override
bool has_text_color() const override
neogfx::size_policy size_policy() const override
void set_text(i_string const &aText) override
bool multi_line() const override
text_widget(i_layout &aLayout, std::string const &aText=std::string{}, text_widget_type aType=text_widget_type::SingleLine, text_widget_flags aFlags=text_widget_flags::None)
void paint(i_graphics_context &aGc) const override
void set_font(optional_font const &aFont) override
text_widget(std::string const &aText=std::string{}, text_widget_type aType=text_widget_type::SingleLine, text_widget_flags aFlags=text_widget_flags::None)
void set_text_format(const optional_text_format &aTextAppearance) override
size minimum_size(optional_size const &aAvailableSpace=optional_size{}) const override
text_widget(i_widget &aParent, std::string const &aText=std::string{}, text_widget_type aType=text_widget_type::SingleLine, text_widget_flags aFlags=text_widget_flags::None)
void set_flags(text_widget_flags aFlags) override
i_string const & text() const override
void set_alignment(neogfx::alignment aAlignment, bool aUpdateLayout=true) override
color text_color() const override
size size_hint_extent() const
void set_text_color(const optional_color &aTextColor) override
size text_extent() const
neogfx::text_format text_format() const override
text_widget_flags flags() const override
neogfx::alignment alignment() const override
bool visible() const override
#define meta_object(...)
Definition i_object.hpp:28
#define define_event(name, declName,...)
Definition event.hpp:200