Label.h
1 /* Copyright (C) 2015 Marc Boris Duerner
2  Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27  MA 02110-1301 USA
28 */
29 
30 #ifndef Pt_Forms_Label_H
31 #define Pt_Forms_Label_H
32 
33 #include <Pt/Forms/Control.h>
34 #include <Pt/Forms/Alignment.h>
35 #include <Pt/Forms/Adjustment.h>
36 #include <Pt/Forms/PanelStyler.h>
37 #include <Pt/Forms/TextBlock.h>
38 #include <Pt/Forms/PixmapSurface.h>
39 #include <Pt/Forms/Icon.h>
40 #include <Pt/Gfx/Rect.h>
41 #include <Pt/SmartPtr.h>
42 #include <Pt/String.h>
43 
44 namespace Pt {
45 
46 namespace Forms {
47 
79 class PT_FORMS_API Label : public Control
80 {
81  public:
82  typedef Control Base;
83 
84  public:
87  Label();
88 
91  virtual ~Label();
92 
96 
100 
103  const Pt::String& text() const;
104 
107  void setText(const Pt::String& text);
108 
113  void setIcon(const Icon& icon, const Gfx::SizeF& iconSize);
114 
115  public:
118  const Gfx::Brush* background() const;
119 
122  void setBackground(const Gfx::Brush& b);
123 
126  void setBackground(bool b);
127 
130  const Gfx::Pen* contour() const;
131 
134  void setContour(const Gfx::Pen& p);
135 
138  void setFrame(bool b);
139 
142  const Gfx::Color& textColor() const;
143 
146  void setTextColor(const Gfx::Color& color);
147 
150  Gfx::Font font() const;
151 
154  void setFont(const Gfx::Font& font);
155 
158  void setFontSize(std::size_t size);
159 
163 
167 
173  void setRenderer(PanelRenderer* renderer);
174 
175  protected:
178  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
179 
182  virtual void onLayout(const Gfx::RectF& rect);
183 
186  virtual void onRescaleEvent(const RescaleEvent& ev);
187 
190  virtual void onResizeEvent(const ResizeEvent& ev);
191 
192  protected:
195  virtual void onConnect(Screen& screen);
196 
203  virtual void onInvalidate();
204 
207  virtual void onPaint(PaintContext& context,
208  const Gfx::RectF& rect);
209 
214  virtual void onPaintBackground(PaintContext& context,
215  const Gfx::RectF& rect,
216  const PanelState& state);
217 
222  virtual void onPaintFrame(PaintContext& context,
223  const Gfx::RectF& rect,
224  const PanelState& state);
225 
230  virtual void onPaintIcon(PaintContext& context,
231  const Gfx::RectF& contentRect,
232  const PanelState& state);
233 
238  virtual void onPaintText(PaintContext& context,
239  const Gfx::RectF& contentRect,
240  const PanelState& state);
241 
242  private:
243  Adjustment adjustment() const;
244 
245  PanelState panelState() const;
246 
247  private:
248  Alignment _alignment;
249 
250  Pt::String _text;
251  Adjustment _adjustment;
252  TextBlock _textBlock;
253 
254  Icon _icon;
255  Gfx::PointF _iconPos;
256  Gfx::SizeF _iconSize;
257  Gfx::SizeF _measuredIconSize;
258  bool _iconInvalid;
259 
260  PanelStyler _styler;
261  bool _hasBackground;
262  bool _hasFrame;
263  Gfx::RectF _contentRect;
264  Pixmap _pixmap;
265 };
266 
267 } // namespace
268 
269 } // namespace
270 
271 #endif
virtual void onRescaleEvent(const RescaleEvent &ev)
Invalidates a prepared icon after a scale change.
Core module.
Definition: Allocator.h:33
Represents an image at one or more logical sizes.
Definition: Icon.h:144
Attributes for the drawing of outlines.
Definition: Pen.h:54
const Gfx::Color & textColor() const
Returns the effective text color.
Control that displays text or an icon.
Definition: Label.h:80
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p and enables the frame.
Reports that a widget was resized.
Definition: ResizeEvent.h:50
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
virtual void onInvalidate()
Binds the styler and prepares the icon.
Slant
Describes the requested font slant.
Definition: Font.h:76
Label()
Creates an empty label.
void setBackground(bool b)
Sets whether the label paints a background fill.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
virtual void onPaintFrame(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)
Paints the label frame layer.
Active painting session on a Forms paint surface.
Definition: PaintContext.h:51
virtual void onPaintIcon(PaintContext &context, const Gfx::RectF &contentRect, const PanelState &state)
Paints the label icon layer.
void setText(const Pt::String &text)
Sets the caption to text and clears any icon.
Represents wrapped text as positioned lines.
Definition: TextBlock.h:148
Size with floating-point width and height.
Definition: Size.h:47
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b and enables the fill.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
void setIcon(const Icon &icon, const Gfx::SizeF &iconSize)
Shows icon instead of the caption.
Reusable view used as application content.
Definition: Control.h:107
virtual void onPaintText(PaintContext &context, const Gfx::RectF &contentRect, const PanelState &state)
Paints the label text layer.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the caption or icon and the frame.
Binds a panel-like widget to the current style renderer.
Definition: PanelStyler.h:218
Weight
Describes the requested font weight.
Definition: Font.h:61
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
virtual void onPaint(PaintContext &context, const Gfx::RectF &rect)
Paints background, frame, icon, and caption.
Display root for top-level windows.
Definition: Screen.h:83
const Gfx::Brush * background() const
Returns the background brush, or 0 if the fill is off.
const Gfx::Pen * contour() const
Returns the contour pen, or 0 if the frame is off.
virtual void onConnect(Screen &screen)
Forwards the screen connection to the base control.
const Pt::String & text() const
Returns the caption.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
virtual ~Label()
Destroys the label.
Aligns content along one axis.
Definition: Adjustment.h:60
Widget that hosts controls on a paint surface.
Definition: View.h:86
Font request used for text drawing and measurement.
Definition: Font.h:56
Alignment alignment() const
Returns the alignment of the caption or icon.
void setRenderer(PanelRenderer *renderer)
Assigns renderer as the family renderer.
Constraint used when measuring a control.
Definition: SizePolicy.h:48
void setFrame(bool b)
Sets whether the label paints a frame.
Standard color type.
Definition: Color.h:47
Renders the look of a panel-like widget.
Definition: PanelStyler.h:93
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
Gfx::Font font() const
Returns the effective font.
Unicode capable basic_string.
Definition: Api-String.h:44
Fill description for shapes and text.
Definition: Brush.h:145
Transient visual state of a panel-like widget.
Definition: PanelStyler.h:48
Rect with floating-point coordinates.
Definition: Rect.h:47
Off-screen Forms paint surface.
Definition: Pixmap.h:130
virtual void onLayout(const Gfx::RectF &rect)
Places the caption or icon in rect.
Names a position in a rectangle.
Definition: Alignment.h:61
void setAlignment(Alignment a)
Sets the alignment of the caption or icon to a.
virtual void onPaintBackground(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)
Paints the label background layer.
virtual void onResizeEvent(const ResizeEvent &ev)
Forwards the resize to the base control.