Skip to content

Commit

Permalink
Client|Widgets: Added LabelWidget
Browse files Browse the repository at this point in the history
A label consists of an image plus styled text (both are optional). This
will serve as a base class for the ButtonWidget.
  • Loading branch information
skyjake committed May 29, 2013
1 parent 936b566 commit 3d6ec72
Show file tree
Hide file tree
Showing 3 changed files with 535 additions and 4 deletions.
86 changes: 86 additions & 0 deletions doomsday/client/include/ui/widgets/labelwidget.h
Expand Up @@ -19,16 +19,102 @@
#ifndef DENG_CLIENT_LABELWIDGET_H
#define DENG_CLIENT_LABELWIDGET_H

#include <de/Image>

#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);

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();

protected:
void glInit();
void glDeinit();

private:
DENG2_PRIVATE(d)
};
Expand Down
14 changes: 13 additions & 1 deletion doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -39,6 +39,7 @@
#include "ui/widgets/lineeditwidget.h"
#include "ui/widgets/consolecommandwidget.h"
#include "ui/widgets/logwidget.h"
#include "ui/widgets/labelwidget.h"
#include "ui/mouse_qt.h"

#include "dd_main.h"
Expand Down Expand Up @@ -102,9 +103,20 @@ DENG2_OBSERVES(Canvas, FocusChange)
.setInput(Rule::Left, root.viewLeft())
.setInput(Rule::Width, root.viewWidth())
.setInput(Rule::Bottom, test->rule().top())
.setInput(Rule::Top, root.viewTop() + 200);
.setInput(Rule::Top, root.viewHeight() / 2);
root.add(log);

LabelWidget *lab = new LabelWidget;
lab->setText("Hello World");
lab->setImage(ClientApp::windowSystem().style().images().image("logo.256"));
lab->setSizePolicy(LabelWidget::Expand, LabelWidget::Expand);
lab->rule()
.setInput(Rule::Left, root.viewLeft())
//.setInput(Rule::Width, root.viewWidth())
//.setInput(Rule::Top, root.viewTop())
.setInput(Rule::Bottom, log->rule().top());
root.add(lab);

// Initially the widget is disabled. It will be enabled when the window
// is visible and ready to be drawn.
legacy->disable();
Expand Down

0 comments on commit 3d6ec72

Please sign in to comment.