Skip to content

Commit 664800b

Browse files
authoredMay 6, 2020
FormSpec: Add universal style selector * (#9718)
1 parent 4f9a5f6 commit 664800b

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed
 

Diff for: ‎doc/lua_api.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -2567,7 +2567,7 @@ Elements
25672567

25682568
* Set the style for the element(s) matching `selector` by name.
25692569
* `selector` can be one of:
2570-
* `<name>` - An element name.
2570+
* `<name>` - An element name. Includes `*`, which represents every element.
25712571
* `<name>:<state>` - An element name, a colon, and one or more states.
25722572
* `state` is a list of states separated by the `+` character.
25732573
* If a state is provided, the style will only take effect when the element is in that state.
@@ -2580,7 +2580,7 @@ Elements
25802580

25812581
* Set the style for the element(s) matching `selector` by type.
25822582
* `selector` can be one of:
2583-
* `<type>` - An element type.
2583+
* `<type>` - An element type. Includes `*`, which represents every element.
25842584
* `<type>:<state>` - An element type, a colon, and one or more states.
25852585
* `state` is a list of states separated by the `+` character.
25862586
* If a state is provided, the style will only take effect when the element is in that state.
@@ -2647,6 +2647,8 @@ A name/type can optionally be a comma separated list of names/types, like so:
26472647
world_delete,world_create,world_configure
26482648
button,image_button
26492649

2650+
A `*` type can be used to select every element in the formspec.
2651+
26502652
Any name/type in the list can also be accompanied by a `+`-separated list of states, like so:
26512653

26522654
world_delete:hovered+pressed

Diff for: ‎src/gui/guiFormSpecMenu.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -4609,20 +4609,32 @@ StyleSpec GUIFormSpecMenu::getDefaultStyleForElement(const std::string &type,
46094609
return getStyleForElement(type, name, parent_type)[StyleSpec::STATE_DEFAULT];
46104610
}
46114611

4612-
std::array<StyleSpec, StyleSpec::NUM_STATES> GUIFormSpecMenu::getStyleForElement(const std::string &type,
4613-
const std::string &name, const std::string &parent_type)
4612+
std::array<StyleSpec, StyleSpec::NUM_STATES> GUIFormSpecMenu::getStyleForElement(
4613+
const std::string &type, const std::string &name, const std::string &parent_type)
46144614
{
46154615
std::array<StyleSpec, StyleSpec::NUM_STATES> ret;
46164616

4617+
auto it = theme_by_type.find("*");
4618+
if (it != theme_by_type.end()) {
4619+
for (const StyleSpec &spec : it->second)
4620+
ret[(u32)spec.getState()] |= spec;
4621+
}
4622+
4623+
it = theme_by_name.find("*");
4624+
if (it != theme_by_name.end()) {
4625+
for (const StyleSpec &spec : it->second)
4626+
ret[(u32)spec.getState()] |= spec;
4627+
}
4628+
46174629
if (!parent_type.empty()) {
4618-
auto it = theme_by_type.find(parent_type);
4630+
it = theme_by_type.find(parent_type);
46194631
if (it != theme_by_type.end()) {
46204632
for (const StyleSpec &spec : it->second)
46214633
ret[(u32)spec.getState()] |= spec;
46224634
}
46234635
}
46244636

4625-
auto it = theme_by_type.find(type);
4637+
it = theme_by_type.find(type);
46264638
if (it != theme_by_type.end()) {
46274639
for (const StyleSpec &spec : it->second)
46284640
ret[(u32)spec.getState()] |= spec;

0 commit comments

Comments
 (0)
Please sign in to comment.