Skip to content

Commit

Permalink
UI|Widgets: Word wrap long choice widget items
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 15, 2018
1 parent 6fbe344 commit 82a2868
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Expand Up @@ -44,6 +44,10 @@ slider {
rule editor { constant $= UNIT * 20 }
}

choice {
rule item.width.max { constant $= UNIT * 100 }
}

list {
rule width { constant $= UNIT * 120 }
}
Expand Down
11 changes: 9 additions & 2 deletions doomsday/sdk/libappfw/src/widgets/choicewidget.cpp
Expand Up @@ -64,6 +64,8 @@ DENG2_OBSERVES(ChildWidgetOrganizer, WidgetUpdate)
{
maxWidth = new IndirectRule;

self().setMaximumTextWidth(rule("choice.item.width.max"));
self().setTextLineAlignment(ui::AlignLeft);
self().setFont("choice.selected");

choices = new PopupMenuWidget;
Expand Down Expand Up @@ -102,7 +104,11 @@ DENG2_OBSERVES(ChildWidgetOrganizer, WidgetUpdate)

void widgetCreatedForItem(GuiWidget &widget, ui::Item const &item)
{
if (ButtonWidget *but = maybeAs<ButtonWidget>(widget))
if (auto *label = maybeAs<LabelWidget>(widget))
{
label->setMaximumTextWidth(rule("choice.item.width.max"));
}
if (auto *but = maybeAs<ButtonWidget>(widget))
{
// Make sure the created buttons have an action that updates the
// selected item.
Expand Down Expand Up @@ -131,7 +137,8 @@ DENG2_OBSERVES(ChildWidgetOrganizer, WidgetUpdate)
esc.parse(items().at(i).label());
widest = de::max(widest, font.advanceWidth(esc.plainText()));
}
maxWidth->setSource(Const(widest) + self().margins().width());
maxWidth->setSource(OperatorRule::minimum(rule("choice.item.width.max"),
Const(widest) + self().margins().width()));
}

Data const &items() const
Expand Down
Expand Up @@ -36,6 +36,10 @@ group slider {
rule editor { constant $= UNIT * 20 }
}

group choice {
rule item.width.max { constant $= UNIT * 100 }
}

group dialog {
rule gap { constant $= UNIT * 2 }

Expand Down

0 comments on commit 82a2868

Please sign in to comment.