Skip to content

Commit

Permalink
UI|Client: Various widget improvements; cleanup
Browse files Browse the repository at this point in the history
ProgressWidget's default mode is to align content normally rather
than by image only, as the latter is only really needed in
BusyWidget.

LabelWidget determines the maximum available text width better:
the constraints set on the label image must be taken into account.

PopupWidget constrains the placement of the popup so it doesn't
go outside the view with the Down opening direction.
  • Loading branch information
skyjake committed Aug 22, 2013
1 parent 33a1777 commit 5672bb5
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
31 changes: 0 additions & 31 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -147,37 +147,6 @@ public IGameChangeObserver
.setAnchorPoint(Vector2f(.5f, .5f));
root.add(games);

#if 0
// testing
games->hide();
DocumentWidget *doc = new DocumentWidget;
QFile file("/Users/jaakko/Projects/deng/doomsday/client/src/ui/widgets/documentwidget.cpp");
file.open(QFile::ReadOnly);
doc->setText(QString::fromUtf8(file.readAll()));
doc->setFont("monospace");
//doc->setWidthPolicy(ui::Fixed);
doc->set(GuiWidget::Background(Vector4f(0, 0, 1, .5f)));
doc->rule()
.setInput(Rule::Left, root.viewLeft() + 50)
//.setInput(Rule::Width, Const(400))
.setInput(Rule::Top, root.viewTop() + 50)
.setInput(Rule::Bottom, root.viewBottom() - 50);
root.add(doc);
#endif

#if 0
games->hide();
ProgressWidget *prog = new ProgressWidget;
prog->setRange(Rangei(0, 100));
prog->setProgress(100, 60);
prog->rule()
.setInput(Rule::Left, root.viewLeft())
.setInput(Rule::Right, root.viewRight())
.setInput(Rule::Top, root.viewTop())
.setInput(Rule::Bottom, root.viewBottom());
root.add(prog);
#endif

// Common notification area.
notifications = new NotificationWidget;
notifications->rule()
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/src/ui/widgets/busywidget.cpp
Expand Up @@ -49,6 +49,7 @@ DENG2_PIMPL(BusyWidget)
uMvpMatrix("uMvpMatrix", GLUniform::Mat4)
{
progress = new ProgressWidget;
progress->setAlignment(ui::AlignCenter, LabelWidget::AlignOnlyByImage);
progress->setRange(Rangei(0, 200));
progress->setImageScale(.2f);
progress->rule().setRect(self.rule());
Expand Down
36 changes: 32 additions & 4 deletions doomsday/client/src/ui/widgets/labelwidget.cpp
Expand Up @@ -348,9 +348,17 @@ public Font::RichFormat::IStyle
return Vector2ui(wraps.width(), wraps.totalHeightInPixels());
}

/**
* Determines the maximum amount of width available for text, taking into
* account the given constraints for the possible image of the label.
*/
int availableTextWidth() const
{
int w = 0;
int h = 0;

// The theorical upper limit is the entire view (when expanding) or
// the given widget width.
if(horizPolicy == Expand)
{
// Expansion can occur to full view width.
Expand All @@ -360,10 +368,30 @@ public Font::RichFormat::IStyle
{
w = self.rule().width().valuei() - (tlMargin.x + brMargin.x);
}
if(textAlign & (AlignLeft | AlignRight))
if(vertPolicy != Expand)
{
h = self.rule().height().valuei() - (tlMargin.y + brMargin.y);
}

if(hasImage())
{
// Image will be placed beside the text.
w -= gap + imageSize().x;
if(textAlign & (AlignLeft | AlignRight))
{
// Image will be placed beside the text.
Vector2f imgSize = imageSize() * imageScale;

if(vertPolicy != Expand)
{
if(imageFit & FitToHeight && imgSize.y > h)
{
float factor = float(h) / imgSize.y;
imgSize.y *= factor;
if(imageFit & OriginalAspectRatio) imgSize.x *= factor;
}
}

w -= gap + imgSize.x;
}
}
return w;
}
Expand Down Expand Up @@ -393,7 +421,7 @@ public Font::RichFormat::IStyle
ContentLayout layout;
contentPlacement(layout);
Rectanglef combined = layout.image | layout.text;
width->set(combined.width() + tlMargin.x + brMargin.x);
width->set (combined.width() + tlMargin.x + brMargin.x);
height->set(combined.height() + tlMargin.y + brMargin.y);
}
}
Expand Down
5 changes: 4 additions & 1 deletion doomsday/client/src/ui/widgets/popupwidget.cpp
Expand Up @@ -133,7 +133,10 @@ DENG2_PIMPL(PopupWidget)
case ui::Down:
self.rule()
.setInput(Rule::Top, *anchorY + *marker)
.setInput(Rule::Left, *anchorX - self.rule().width() / 2);
.setInput(Rule::Left, OperatorRule::clamped(
*anchorX - self.rule().width() / 2,
self.margin(),
self.root().viewWidth() - self.rule().width() - self.margin()));
break;

case ui::Left:
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/progresswidget.cpp
Expand Up @@ -85,8 +85,8 @@ ProgressWidget::ProgressWidget(String const &name) : d(new Instance(this))
setImageFit(ui::FitToSize | ui::OriginalAspectRatio);
setImageScale(.6f);

setAlignment(ui::AlignCenter, AlignOnlyByImage);
setTextAlignment(ui::AlignRight);
setTextLineAlignment(ui::AlignLeft);
}

void ProgressWidget::useMiniStyle()
Expand Down
1 change: 0 additions & 1 deletion doomsday/client/src/updater/updateavailabledialog.cpp
Expand Up @@ -85,7 +85,6 @@ DENG2_OBSERVES(ToggleWidget, Toggle)
{
checking = new ProgressWidget;
checking->setText(tr("Checking for Updates..."));
checking->setAlignment(ui::AlignCenter, LabelWidget::AlignByCombination);

// The checking indicator is overlaid on the normal content.
checking->rule().setRect(self.rule());
Expand Down

0 comments on commit 5672bb5

Please sign in to comment.