/
labelwidget.h
141 lines (119 loc) · 4.66 KB
/
labelwidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/** @file labelwidget.h
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef DENG_CLIENT_LABELWIDGET_H
#define DENG_CLIENT_LABELWIDGET_H
#include <de/Image>
#include <de/GLBuffer>
#include <de/GLUniform>
#include "guiwidget.h"
#include "alignment.h"
/**
* Widget showing a label text and/or image.
*
* LabelWidget offers several parameters for controlling the layout of the text
* and image components. The widget is also able to independently determine its
* size to exactly fit its contents (according to the LabelWidget::SizePolicy).
*
* The alignment parameters are applied as follows:
*
* - LabelWidget::setAlignment() defines where the content of the widget is
* aligned as a group, once the relative positions of the image and the text
* have been determined.
*
* - LabelWidget::setTextAlignment() defines where the text will be positioned
* in relation to the image. For instance, if the text alignment is AlignRight,
* the text will be placed on the right side of the image. If there is no
* image, this has no effect.
*
* - LabelWidget::setImageAlignment() defines how the image is aligned in
* relation to text when both are visible. For instance, if text is aligned to
* AlignRight (appearing on the right side of the image), then an image
* alignment of AlignTop would align the top of the image with the top of the
* text. AlignBottom would align the bottom of the image with the bottom of the
* text. This value must be on the perpendicular axis when compared to text
* alignment (otherwise it has no effect).
*
* - LabelWidget::setTextLineAlignment() defines the alignment of each individual
* wrapped line of text within the text block.
*
* Additionally, LabelWidget::setImageFit() defines how the image will be
* scaled inside the area reserved for the image.
*/
class LabelWidget : public GuiWidget
{
public:
LabelWidget(de::String const &name = "");
void setText(de::String const &text);
void setImage(de::Image const &image);
/**
* Sets the alignment of the entire contents of the widget inside its
* rectangle.
*
* @param align Alignment for all content.
*/
void setAlignment(Alignment const &align);
void setTextAlignment(Alignment const &textAlign);
void setTextLineAlignment(Alignment const &textLineAlign);
/**
* Sets the alignment of the image when there is both an image
* and a text in the label.
*
* @param imageAlign Alignment for the image.
*/
void setImageAlignment(Alignment const &imageAlign);
void setImageFit(ContentFit const &fit);
void setImageScale(float scaleFactor);
enum SizePolicy {
Fixed, ///< Size is fixed, content positioned inside.
Filled, ///< Size is fixed, content expands to fill entire area.
Expand ///< Size depends on content, expands/contracts to fit.
};
/**
* Allows or disallows the label to expand vertically to fit the provided
* content. By default, labels do not adjust their own size.
*
* @param expand @c true to allow the widget to modify its own height.
*/
void setSizePolicy(SizePolicy horizontal, SizePolicy vertical) {
setWidthPolicy(horizontal);
setHeightPolicy(vertical);
}
void setWidthPolicy(SizePolicy policy);
void setHeightPolicy(SizePolicy policy);
// Events.
void viewResized();
void update();
void draw();
struct ContentLayout {
de::Rectanglef image;
de::Rectanglei text;
};
void contentLayout(ContentLayout &layout);
protected:
void glInit();
void glDeinit();
void glMakeGeometry(DefaultVertexBuf::Builder &verts);
/**
* Called before drawing to update the model-view-projection matrix.
* Derived classes may override this to set a custom matrix for the label.
*/
virtual void updateModelViewProjection(de::GLUniform &uMvp);
private:
DENG2_PRIVATE(d)
};
#endif // DENG_CLIENT_LABELWIDGET_H