Skip to content

Commit

Permalink
libappfw|LabelWidget: Added special "separate" align mode for labels
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 24, 2014
1 parent 4cf3e69 commit f66dc5a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 40 deletions.
3 changes: 2 additions & 1 deletion doomsday/libappfw/include/de/widgets/labelwidget.h
Expand Up @@ -97,7 +97,8 @@ class LIBAPPFW_PUBLIC LabelWidget : public GuiWidget
enum AlignmentMode {
AlignByCombination,
AlignOnlyByImage,
AlignOnlyByText
AlignOnlyByText,
AlignSeparately ///< Aligned separately within the entire content rectangle.
};

/**
Expand Down
94 changes: 55 additions & 39 deletions doomsday/libappfw/src/widgets/labelwidget.cpp
Expand Up @@ -322,63 +322,79 @@ public Font::RichFormat::IStyle
// By default the image and the text are centered over each other.
layout.image.move((Vector2f(layout.text.size()) - layout.image.size()) / 2);

if(hasImage() && hasText())
if(alignMode == AlignSeparately)
{
// Determine the position of the image in relation to the text
// (keeping the image at its current position).
if(textAlign & AlignLeft)
// When aligning separately, simply align both the image and the text
// within the main content rectangle as specified.
if(hasImage())
{
layout.text.moveLeft(layout.image.left() - layout.text.width() - gap);
applyAlignment(imageAlign, layout.image, contentRect);
}
if(textAlign & AlignRight)
if(hasText())
{
layout.text.moveLeft(layout.image.right() + gap);
applyAlignment(textAlign, layout.text, contentRect);
}
if(textAlign & AlignTop)
{
layout.text.moveTop(layout.image.top() - layout.text.height() - gap);
}
if(textAlign & AlignBottom)
{
layout.text.moveTop(layout.image.bottom() + gap);
}

// Align the image in relation to the text on the other axis.
if(textAlign & (AlignLeft | AlignRight))
}
else
{
if(hasImage() && hasText())
{
if(imageAlign & AlignTop)
// Determine the position of the image in relation to the text
// (keeping the image at its current position).
if(textAlign & AlignLeft)
{
layout.image.moveTop(layout.text.top());
layout.text.moveLeft(layout.image.left() - layout.text.width() - gap);
}
if(imageAlign & AlignBottom)
if(textAlign & AlignRight)
{
layout.image.moveTop(layout.text.bottom() - layout.image.height());
layout.text.moveLeft(layout.image.right() + gap);
}
}
if(textAlign & (AlignTop | AlignBottom))
{
if(imageAlign & AlignLeft)
if(textAlign & AlignTop)
{
layout.text.moveTop(layout.image.top() - layout.text.height() - gap);
}
if(textAlign & AlignBottom)
{
layout.image.moveLeft(layout.text.left());
layout.text.moveTop(layout.image.bottom() + gap);
}
if(imageAlign & AlignRight)

// Align the image in relation to the text on the other axis.
if(textAlign & (AlignLeft | AlignRight))
{
layout.image.moveLeft(layout.text.right() - layout.image.width());
if(imageAlign & AlignTop)
{
layout.image.moveTop(layout.text.top());
}
if(imageAlign & AlignBottom)
{
layout.image.moveTop(layout.text.bottom() - layout.image.height());
}
}
if(textAlign & (AlignTop | AlignBottom))
{
if(imageAlign & AlignLeft)
{
layout.image.moveLeft(layout.text.left());
}
if(imageAlign & AlignRight)
{
layout.image.moveLeft(layout.text.right() - layout.image.width());
}
}
}
}

// Align the final combination within the content.
Rectanglef combined =
(alignMode == AlignByCombination? (layout.image | layout.text) :
alignMode == AlignOnlyByImage? layout.image :
layout.text);
// Align the final combination within the content.
Rectanglef combined =
(alignMode == AlignByCombination? (layout.image | layout.text) :
alignMode == AlignOnlyByImage? layout.image :
layout.text);

Vector2f delta = applyAlignment(align, combined.size(), contentRect);
delta -= combined.topLeft;
Vector2f delta = applyAlignment(align, combined.size(), contentRect);
delta -= combined.topLeft;

layout.image.move(delta);
layout.text.move(delta.toVector2i());
layout.image.move(delta);
layout.text.move(delta.toVector2i());
}
}

/**
Expand Down

0 comments on commit f66dc5a

Please sign in to comment.