Skip to content

Commit

Permalink
Client|UI|Default Style: Menu and popup menu separators
Browse files Browse the repository at this point in the history
Also updated the Default Style with the rules and fonts for menu
separators.
  • Loading branch information
skyjake committed Jul 16, 2013
1 parent 651c191 commit dedd901
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 10 deletions.
10 changes: 10 additions & 0 deletions doomsday/client/data/defaultstyle.pack/fonts.dei
Expand Up @@ -65,3 +65,13 @@ group editor {
weight: light
}
}

group separator {
font empty inherits default {
size $: gui.scale(__this__.size, 0.5)
}
font label inherits default {
size $: gui.scale(__this__.size, 0.75)
weight: bold
}
}
5 changes: 3 additions & 2 deletions doomsday/client/data/defaultstyle.pack/rules.dei
Expand Up @@ -4,8 +4,9 @@ script {
UNIT = 4.0
}

rule unit { constant $= UNIT }
rule gap { constant $= UNIT * 3 }
rule unit { constant $= UNIT }
rule halfunit { constant $= UNIT / 2 }
rule gap { constant $= UNIT * 3 }

group console {
rule width { constant = 500 }
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/widgets/menuwidget.h
Expand Up @@ -61,6 +61,8 @@ class MenuWidget : public ScrollAreaWidget

ButtonWidget *addItem(de::Image const &image, de::String const &styledText, de::Action *action = 0);

GuiWidget *addSeparator(de::String const &labelText = "");

void removeItem(GuiWidget *child);

/**
Expand Down
5 changes: 4 additions & 1 deletion doomsday/client/include/ui/widgets/popupmenuwidget.h
Expand Up @@ -32,7 +32,10 @@ class PopupMenuWidget : public PopupWidget

MenuWidget &menu() const;

ButtonWidget *addItem(de::String const &styledText, de::Action *action = 0);
ButtonWidget *addItem(de::String const &styledText, de::Action *action = 0,
bool dismissOnTriggered = true);

GuiWidget *addSeparator(de::String const &optionalLabel = "");

protected:
void glMakeGeometry(DefaultVertexBuf::Builder &verts);
Expand Down
12 changes: 12 additions & 0 deletions doomsday/client/src/ui/widgets/menuwidget.cpp
Expand Up @@ -254,6 +254,18 @@ ButtonWidget *MenuWidget::addItem(Image const &image, String const &styledText,
return b;
}

GuiWidget *MenuWidget::addSeparator(String const &labelText)
{
LabelWidget *lab = new LabelWidget;
lab->setText(labelText);
lab->setAlignment(ui::AlignLeft);
lab->setTextLineAlignment(ui::AlignLeft);
lab->setSizePolicy(ui::Expand, ui::Expand);
add(lab);
d->needLayout = true;
return lab;
}

void MenuWidget::removeItem(GuiWidget *child)
{
d->needLayout = true;
Expand Down
31 changes: 24 additions & 7 deletions doomsday/client/src/ui/widgets/popupmenuwidget.cpp
Expand Up @@ -85,26 +85,25 @@ PopupMenuWidget::PopupMenuWidget(String const &name)
setContent(new MenuWidget(name.isEmpty()? "" : name + "-content"));

menu().setGridSize(1, ui::Expand, 0, ui::Expand);

//addItem("First "_E(b)"Menu"_E(.)" Item");
//addItem("2nd Menu Item");
//addItem("3nd Item");
}

MenuWidget &PopupMenuWidget::menu() const
{
return static_cast<MenuWidget &>(content());
}

ButtonWidget *PopupMenuWidget::addItem(String const &styledText, Action *action)
ButtonWidget *PopupMenuWidget::addItem(String const &styledText, Action *action, bool dismissOnTriggered)
{
ButtonWidget *b = menu().addItem(styledText, action);
b->setSizePolicy(ui::Expand, ui::Expand);
b->setMargin("unit");
b->set(Background(/*Vector4f(1, 0, 0, .5f)*/));
b->set(Background());

b->audienceForStateChange += d;
b->audienceForTriggered += d;
if(dismissOnTriggered)
{
b->audienceForTriggered += d;
}

// We want items to be hittable throughtout the width of the menu.
b->hitRule()
Expand All @@ -114,6 +113,24 @@ ButtonWidget *PopupMenuWidget::addItem(String const &styledText, Action *action)
return b;
}

GuiWidget *PopupMenuWidget::addSeparator(String const &optionalLabel)
{
GuiWidget *sep = menu().addSeparator(optionalLabel);
if(optionalLabel.isEmpty())
{
sep->setMargin("");
sep->setFont("separator.empty");
}
else
{
sep->setMargin("halfunit");
sep->setFont("separator.label");
}
sep->setTextColor("label.accent");
sep->set(Background());
return sep;
}

void PopupMenuWidget::glMakeGeometry(DefaultVertexBuf::Builder &verts)
{
PopupWidget::glMakeGeometry(verts);
Expand Down

0 comments on commit dedd901

Please sign in to comment.