Skip to content

Commit

Permalink
libgui|DialogWidget: Minimum width for buttons
Browse files Browse the repository at this point in the history
The "OK" button has been a bit too narrow, especially usually being the default button.
  • Loading branch information
skyjake committed Jan 5, 2020
1 parent 132a79f commit a9a6702
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doomsday/libs/gui/include/de/widgets/labelwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class LIBGUI_PUBLIC LabelWidget : public GuiWidget, public IAssetGroup

void setMaximumTextWidth(const Rule &pixels);

void setMinimumWidth(const Rule &minWidth);

void setMinimumHeight(const Rule &minHeight);

/**
Expand Down
5 changes: 3 additions & 2 deletions doomsday/libs/gui/net.dengine.stdlib.gui.pack/rules.dei
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ list {
}

dialog {
rule gap { constant $= UNIT * 2 }
rule separator { constant $= UNIT * 4 }
rule gap { constant $= UNIT * 2 }
rule separator { constant $= UNIT * 4 }
rule button.minwidth { constant $= UNIT * 20 }

rule message.width { constant $= UNIT * 115 }
}
8 changes: 7 additions & 1 deletion doomsday/libs/gui/src/widgets/dialogwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ DE_GUI_PIMPL(DialogWidget)
}
else if (i->role() & (Reject | No))
{
but.setActionFn([this](){ self().reject(); });
but.setActionFn([this]() { self().reject(); });
}
}
}
Expand All @@ -347,6 +347,12 @@ DE_GUI_PIMPL(DialogWidget)
// Button images must be a certain size.
but.setOverrideImageSize(style().fonts().font("default").height());

// Normal buttons should not be too small.
if (~i->role() & Action)
{
but.setMinimumWidth(rule("dialog.button.minwidth"));
}

// Set default label?
if (item.label().isEmpty())
{
Expand Down
12 changes: 10 additions & 2 deletions doomsday/libs/gui/src/widgets/labelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public Font::RichFormat::IStyle

ConstantRule *width;
ConstantRule *height;
IndirectRule *minWidth;
IndirectRule *minHeight;
const Rule *outHeight;
AnimationRule *appearSize;
Expand All @@ -73,10 +74,10 @@ public Font::RichFormat::IStyle
ColorBank::Color altAccentColor;
const Font::RichFormat::IStyle *richStyle;

// Content.
String styledText;
TextDrawable glText;
mutable Vec2ui latestTextSize;

std::unique_ptr<ProceduralImage> image;
std::unique_ptr<ProceduralImage> overlayImage;
GuiVertexBuilder verts;
Expand Down Expand Up @@ -104,6 +105,7 @@ public Font::RichFormat::IStyle
{
width = new ConstantRule(0);
height = new ConstantRule(0);
minWidth = new IndirectRule;
minHeight = new IndirectRule;
outHeight = new OperatorRule(OperatorRule::Maximum, *height, *minHeight);

Expand All @@ -117,6 +119,7 @@ public Font::RichFormat::IStyle
{
releaseRef(width);
releaseRef(height);
releaseRef(minWidth);
releaseRef(minHeight);
releaseRef(outHeight);
releaseRef(appearSize);
Expand Down Expand Up @@ -766,6 +769,11 @@ void LabelWidget::setMaximumTextWidth(const Rule &pixels)
requestGeometry();
}

void LabelWidget::setMinimumWidth(const Rule &minWidth)
{
d->minWidth->setSource(minWidth);
}

void LabelWidget::setMinimumHeight(const Rule &minHeight)
{
d->minHeight->setSource(minHeight);
Expand Down Expand Up @@ -885,7 +893,7 @@ void LabelWidget::setWidthPolicy(SizePolicy policy)
d->horizPolicy = policy;
if (policy == Expand)
{
rule().setInput(Rule::Width, *d->widthRule());
rule().setInput(Rule::Width, OperatorRule::maximum(*d->minWidth, *d->widthRule()));
}
else
{
Expand Down

0 comments on commit a9a6702

Please sign in to comment.