diff --git a/doomsday/libappfw/include/de/widgets/labelwidget.h b/doomsday/libappfw/include/de/widgets/labelwidget.h index 278417155f..551f11ba73 100644 --- a/doomsday/libappfw/include/de/widgets/labelwidget.h +++ b/doomsday/libappfw/include/de/widgets/labelwidget.h @@ -97,7 +97,8 @@ class LIBAPPFW_PUBLIC LabelWidget : public GuiWidget enum AlignmentMode { AlignByCombination, AlignOnlyByImage, - AlignOnlyByText + AlignOnlyByText, + AlignSeparately ///< Aligned separately within the entire content rectangle. }; /** diff --git a/doomsday/libappfw/src/widgets/labelwidget.cpp b/doomsday/libappfw/src/widgets/labelwidget.cpp index 96354ece89..301e658f30 100644 --- a/doomsday/libappfw/src/widgets/labelwidget.cpp +++ b/doomsday/libappfw/src/widgets/labelwidget.cpp @@ -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()); + } } /**