forked from Mirrorlandia_minetest/minetest
FormSpec: Add universal style selector *
(#9718)
This commit is contained in:
parent
4f9a5f67ee
commit
664800b2ad
@ -2567,7 +2567,7 @@ Elements
|
|||||||
|
|
||||||
* Set the style for the element(s) matching `selector` by name.
|
* Set the style for the element(s) matching `selector` by name.
|
||||||
* `selector` can be one of:
|
* `selector` can be one of:
|
||||||
* `<name>` - An element name.
|
* `<name>` - An element name. Includes `*`, which represents every element.
|
||||||
* `<name>:<state>` - An element name, a colon, and one or more states.
|
* `<name>:<state>` - An element name, a colon, and one or more states.
|
||||||
* `state` is a list of states separated by the `+` character.
|
* `state` is a list of states separated by the `+` character.
|
||||||
* If a state is provided, the style will only take effect when the element is in that state.
|
* If a state is provided, the style will only take effect when the element is in that state.
|
||||||
@ -2580,7 +2580,7 @@ Elements
|
|||||||
|
|
||||||
* Set the style for the element(s) matching `selector` by type.
|
* Set the style for the element(s) matching `selector` by type.
|
||||||
* `selector` can be one of:
|
* `selector` can be one of:
|
||||||
* `<type>` - An element type.
|
* `<type>` - An element type. Includes `*`, which represents every element.
|
||||||
* `<type>:<state>` - An element type, a colon, and one or more states.
|
* `<type>:<state>` - An element type, a colon, and one or more states.
|
||||||
* `state` is a list of states separated by the `+` character.
|
* `state` is a list of states separated by the `+` character.
|
||||||
* If a state is provided, the style will only take effect when the element is in that state.
|
* 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:
|
|||||||
world_delete,world_create,world_configure
|
world_delete,world_create,world_configure
|
||||||
button,image_button
|
button,image_button
|
||||||
|
|
||||||
|
A `*` type can be used to select every element in the formspec.
|
||||||
|
|
||||||
Any name/type in the list can also be accompanied by a `+`-separated list of states, like so:
|
Any name/type in the list can also be accompanied by a `+`-separated list of states, like so:
|
||||||
|
|
||||||
world_delete:hovered+pressed
|
world_delete:hovered+pressed
|
||||||
|
@ -4609,20 +4609,32 @@ StyleSpec GUIFormSpecMenu::getDefaultStyleForElement(const std::string &type,
|
|||||||
return getStyleForElement(type, name, parent_type)[StyleSpec::STATE_DEFAULT];
|
return getStyleForElement(type, name, parent_type)[StyleSpec::STATE_DEFAULT];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<StyleSpec, StyleSpec::NUM_STATES> GUIFormSpecMenu::getStyleForElement(const std::string &type,
|
std::array<StyleSpec, StyleSpec::NUM_STATES> GUIFormSpecMenu::getStyleForElement(
|
||||||
const std::string &name, const std::string &parent_type)
|
const std::string &type, const std::string &name, const std::string &parent_type)
|
||||||
{
|
{
|
||||||
std::array<StyleSpec, StyleSpec::NUM_STATES> ret;
|
std::array<StyleSpec, StyleSpec::NUM_STATES> ret;
|
||||||
|
|
||||||
|
auto it = theme_by_type.find("*");
|
||||||
|
if (it != theme_by_type.end()) {
|
||||||
|
for (const StyleSpec &spec : it->second)
|
||||||
|
ret[(u32)spec.getState()] |= spec;
|
||||||
|
}
|
||||||
|
|
||||||
|
it = theme_by_name.find("*");
|
||||||
|
if (it != theme_by_name.end()) {
|
||||||
|
for (const StyleSpec &spec : it->second)
|
||||||
|
ret[(u32)spec.getState()] |= spec;
|
||||||
|
}
|
||||||
|
|
||||||
if (!parent_type.empty()) {
|
if (!parent_type.empty()) {
|
||||||
auto it = theme_by_type.find(parent_type);
|
it = theme_by_type.find(parent_type);
|
||||||
if (it != theme_by_type.end()) {
|
if (it != theme_by_type.end()) {
|
||||||
for (const StyleSpec &spec : it->second)
|
for (const StyleSpec &spec : it->second)
|
||||||
ret[(u32)spec.getState()] |= spec;
|
ret[(u32)spec.getState()] |= spec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = theme_by_type.find(type);
|
it = theme_by_type.find(type);
|
||||||
if (it != theme_by_type.end()) {
|
if (it != theme_by_type.end()) {
|
||||||
for (const StyleSpec &spec : it->second)
|
for (const StyleSpec &spec : it->second)
|
||||||
ret[(u32)spec.getState()] |= spec;
|
ret[(u32)spec.getState()] |= spec;
|
||||||
|
Loading…
Reference in New Issue
Block a user