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/Pixmap.h>
39#include <Pt/Forms/Icon.h>
40#include <Pt/Gfx/Rect.h>
41#include <Pt/SmartPtr.h>
42#include <Pt/String.h>
43
44namespace Pt {
45
46namespace Forms {
47
79class PT_FORMS_API Label : public Control
80{
81 public:
82 typedef Control Base;
83
84 public:
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
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
Aligns content along one axis.
Definition Adjustment.h:60
Names a position in a rectangle.
Definition Alignment.h:61
Control()
Creates an unparented control.
Represents an image at one or more logical sizes.
Definition Icon.h:144
Alignment alignment() const
Returns the alignment of the caption or icon.
const Gfx::Color & textColor() const
Returns the effective text color.
void setText(const Pt::String &text)
Sets the caption to text and clears any icon.
virtual void onRescaleEvent(const RescaleEvent &ev)
Invalidates a prepared icon after a scale change.
Label()
Creates an empty label.
void setBackground(bool b)
Sets whether the label paints a background fill.
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.
const Gfx::Brush * background() const
Returns the background brush, or 0 if the fill is off.
void setIcon(const Icon &icon, const Gfx::SizeF &iconSize)
Shows icon instead of the caption.
virtual void onPaint(PaintContext &context, const Gfx::RectF &rect)
Paints background, frame, icon, and caption.
virtual void onPaintFrame(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)
Paints the label frame layer.
const Pt::String & text() const
Returns the caption.
virtual void onResizeEvent(const ResizeEvent &ev)
Forwards the resize to the base control.
Gfx::Font font() const
Returns the effective font.
virtual void onLayout(const Gfx::RectF &rect)
Places the caption or icon in rect.
virtual void onConnect(Screen &screen)
Forwards the screen connection to the base control.
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b and enables the fill.
virtual void onPaintIcon(PaintContext &context, const Gfx::RectF &contentRect, const PanelState &state)
Paints the label icon layer.
virtual void onPaintText(PaintContext &context, const Gfx::RectF &contentRect, const PanelState &state)
Paints the label text layer.
const Gfx::Pen * contour() const
Returns the contour pen, or 0 if the frame is off.
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p and enables the frame.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the caption or icon and the frame.
void setFrame(bool b)
Sets whether the label paints a frame.
virtual ~Label()
Destroys the label.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
void setRenderer(PanelRenderer *renderer)
Assigns renderer as the family renderer.
virtual void onInvalidate()
Binds the styler and prepares the icon.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Renders the look of a panel-like widget.
Definition PanelStyler.h:93
Transient visual state of a panel-like widget.
Definition PanelStyler.h:48
Binds a panel-like widget to the current style renderer.
Definition PanelStyler.h:218
Off-screen Forms paint surface.
Definition Pixmap.h:130
Reports that a widget was resized.
Definition ResizeEvent.h:50
Display root for top-level windows.
Definition Screen.h:83
Constraint used when measuring a control.
Definition SizePolicy.h:48
Represents wrapped text as positioned lines.
Definition TextBlock.h:148
const Gfx::SizeF & size() const
Returns the size in local logical coordinates.
Screen * screen()
Returns the connected screen, or 0 when disconnected.
Fill color, gradient or texture.
Definition Brush.h:151
8-bit ARGB color.
Definition Color.h:65
Font family, size and style.
Definition Font.h:63
Slant
Describes the requested font slant.
Definition Font.h:83
Weight
Describes the requested font weight.
Definition Font.h:68
Outline color, width and style.
Definition Pen.h:59
Unicode capable basic_string.
Definition Api-String.h:67
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33