Skip to content

Commit

Permalink
UI|Client|Widgets: ChoiceWidget's width depends on widest child item
Browse files Browse the repository at this point in the history
Also corrected some workarounds to issues that are no longer relevant,
related to hidden children in a MenuWidget. There is no reason to not
update or otherwise ignore hidden widgets any more.
  • Loading branch information
skyjake committed Aug 24, 2013
1 parent b47daf4 commit 5b8bf0f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
1 change: 0 additions & 1 deletion doomsday/client/include/ui/widgets/choicewidget.h
Expand Up @@ -63,7 +63,6 @@ class ChoiceWidget : public ButtonWidget
void setSelected(ui::Context::Pos pos);

ui::Context::Pos selected() const;

ui::Item const &selectedItem() const;

public slots:
Expand Down
8 changes: 7 additions & 1 deletion doomsday/client/src/ui/widgets/choicewidget.cpp
Expand Up @@ -27,7 +27,7 @@ DENG_GUI_PIMPL(ChoiceWidget),
DENG2_OBSERVES(Context, Addition),
DENG2_OBSERVES(Context, Removal),
DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
{
{
/**
* Items in the choice's popup uses this as action to change the selected
* item.
Expand Down Expand Up @@ -61,6 +61,8 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
Instance(Public *i) : Base(i), selected(Context::InvalidPos)
{
self.setFont("choice.selected");
self.setSizePolicy(ui::Fixed, ui::Expand);
//self.setAlignment(ui::AlignLeft);

choices = new PopupMenuWidget;
choices->setAnchorAndOpeningDirection(self.hitRule(), ui::Right);
Expand All @@ -69,6 +71,10 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
choices->menu().organizer().audienceForWidgetCreation += this;
self.add(choices);

// The choice button itself has the same width as the choice menu
// (i.e., the longest item's width).
self.rule().setInput(Rule::Width, choices->menu().rule().width());

self.setAction(new SignalAction(thisPublic, SLOT(openPopup())));

updateButtonWithSelection();
Expand Down
12 changes: 6 additions & 6 deletions doomsday/client/src/ui/widgets/contextwidgetorganizer.cpp
Expand Up @@ -88,12 +88,6 @@ DENG2_OBSERVES(ui::Item, Change )
GuiWidget *w = factory->makeItemWidget(item, container);
if(!w) return; // Unpresentable.

// Others may alter the widget in some way.
DENG2_FOR_PUBLIC_AUDIENCE(WidgetCreation, i)
{
i->widgetCreatedForItem(*w, item);
}

// Update the widget immediately.
mapping.insert(&item, w);
itemChanged(item);
Expand All @@ -108,6 +102,12 @@ DENG2_OBSERVES(ui::Item, Change )
container->insertBefore(w, *mapping[&context->at(pos + 1)]);
}

// Others may alter the widget in some way.
DENG2_FOR_PUBLIC_AUDIENCE(WidgetCreation, i)
{
i->widgetCreatedForItem(*w, item);
}

// Observe.
w->audienceForDeletion += this; // in case it's manually deleted
item.audienceForChange += this;
Expand Down
5 changes: 4 additions & 1 deletion doomsday/client/src/ui/widgets/dialogwidget.cpp
Expand Up @@ -241,7 +241,10 @@ DENG2_OBSERVES(ui::Context, Removal)
// All label-based widgets should expand on their own.
if(LabelWidget *lab = w.maybeAs<LabelWidget>())
{
lab->setSizePolicy(ui::Expand, ui::Expand);
if(!w.is<ChoiceWidget>())
{
lab->setSizePolicy(ui::Expand, ui::Expand);
}
}

// Toggles should have no background.
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/ui/widgets/gltextcomposer.cpp
Expand Up @@ -211,6 +211,8 @@ DENG2_PIMPL(GLTextComposer)

void updateLineLayout(Rangei const &lineRange)
{
if(lineRange.isEmpty()) return;

Rangei current = lineRange;
forever
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/labelwidget.cpp
Expand Up @@ -532,7 +532,7 @@ void LabelWidget::update()
{
GuiWidget::update();

if(!isHidden())
//if(!isHidden())
{
d->update();
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/widgets/menuwidget.cpp
Expand Up @@ -227,7 +227,7 @@ public ContextWidgetOrganizer::IWidgetFactory
{
if(GuiWidget const *widget = child->maybeAs<GuiWidget>())
{
return widget->isVisible();
return !widget->behavior().testFlag(Widget::Hidden);
}
return false;
}
Expand Down Expand Up @@ -336,7 +336,7 @@ ContextWidgetOrganizer const &MenuWidget::organizer() const

void MenuWidget::update()
{
if(isHidden()) return;
//if(isHidden()) return;

if(d->needLayout)
{
Expand Down

0 comments on commit 5b8bf0f

Please sign in to comment.