neoGFX
C++ GPU-oriented GUI library and app/game creation framework.
text.hpp
Go to the documentation of this file.
1 // text.hpp
2 /*
3  neogfx C++ GUI Library
4  Copyright (c) 2015 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>
23 #include <neogfx/gfx/text/font.hpp>
24 #include "shape.hpp"
25 
26 namespace neogfx
27 {
28  class text : public shape
29  {
30  public:
31  text(i_shape_container& aContainer, const vec3& aPosition, const std::string& aText, const neogfx::font& aFont, const neogfx::text_appearance& aAppearance, neogfx::alignment aAlignment = alignment::Left);
32  public:
33  const std::string& value() const;
34  void set_value(const std::string& aText);
35  const neogfx::font& font() const;
36  void set_font(const neogfx::font& aFont);
37  const neogfx::text_appearance& appearance() const;
38  void set_appearance(const neogfx::text_appearance& aAppearance);
40  void set_alignment(neogfx::alignment aAlignment);
41  const optional_dimension& border() const;
42  void set_border(const optional_dimension& aBorder);
43  const optional_margins& margins() const;
44  void set_margins(const optional_margins& aMargins);
45  public:
46  vec3 extents() const override;
47  rect bounding_box_2d(bool aWithPosition = true) const override;
48  public:
49  void paint(graphics_context& aGraphicsContext) const override;
50  private:
51  size text_extent() const;
52  private:
53  std::string iText;
54  neogfx::font iFont;
55  neogfx::text_appearance iAppearance;
56  neogfx::alignment iAlignment;
57  mutable optional_size iTextExtent;
58  mutable glyph_text iGlyphTextCache;
59  optional_dimension iBorder;
60  optional_margins iMargins;
61  };
62 }
boost::optional< margins > optional_margins
boost::optional< dimension > optional_dimension
const neogfx::text_appearance & appearance() const
void set_border(const optional_dimension &aBorder)
const std::string & value() const
const optional_dimension & border() const
rect bounding_box_2d(bool aWithPosition=true) const override
boost::optional< size > optional_size
void set_alignment(neogfx::alignment aAlignment)
void set_appearance(const neogfx::text_appearance &aAppearance)
const neogfx::font & font() const
vec3 extents() const override
void set_value(const std::string &aText)
std::string string
Definition: glyph.hpp:31
void paint(graphics_context &aGraphicsContext) const override
void set_font(const neogfx::font &aFont)
void set_margins(const optional_margins &aMargins)
const optional_margins & margins() const
text(i_shape_container &aContainer, const vec3 &aPosition, const std::string &aText, const neogfx::font &aFont, const neogfx::text_appearance &aAppearance, neogfx::alignment aAlignment=alignment::Left)
neogfx::alignment alignment() const