Add multiple element selection to `style` and `style_type` (#9380)
authorv-rob <robinsonvincent89@gmail.com>
Sun, 1 Mar 2020 14:39:57 +0000 (06:39 -0800)
committerGitHub <noreply@github.com>
Sun, 1 Mar 2020 14:39:57 +0000 (14:39 +0000)
doc/lua_api.txt
games/minimal/mods/test/formspec.lua
src/gui/guiFormSpecMenu.cpp

index 6ff7f802a2f3265c327f226c9683c9e6e0df50c5..4b7132828bb0ab1a663727bbd7e1781ed072aa26 100644 (file)
@@ -2495,16 +2495,16 @@ Elements
         * `span=<value>`: number of following columns to affect
           (default: infinite).
 
-### `style[<name>;<prop1>;<prop2>;...]`
+### `style[<name 1>,<name 2>,...;<prop1>;<prop2>;...]`
 
-* Set the style for the named element `name`.
+* Set the style for the named element(s) `name`.
 * Note: this **must** be before the element is defined.
 * See [Styling Formspecs].
 
 
-### `style_type[<type>;<prop1>;<prop2>;...]`
+### `style_type[<type 1>,<type 2>,...;<prop1>;<prop2>;...]`
 
-* Sets the style for all elements of type `type` which appear after this element.
+* Sets the style for all elements of type(s) `type` which appear after this element.
 * See [Styling Formspecs].
 
 Migrating to Real Coordinates
@@ -2547,13 +2547,18 @@ Styling Formspecs
 
 Formspec elements can be themed using the style elements:
 
-    style[<name>;<prop1>;<prop2>;...]
-    style_type[<type>;<prop1>;<prop2>;...]
+    style[<name 1>,<name 2>,...;<prop1>;<prop2>;...]
+    style_type[<type 1>,<type 2>,...;<prop1>;<prop2>;...]
 
 Where a prop is:
 
     property_name=property_value
 
+A name/type can optionally be a comma separated list of names/types, like so:
+
+    world_delete,world_create,world_configure
+    button,image_button
+
 For example:
 
     style_type[button;bgcolor=#006699]
index 50c5068998d940420aa9f94297ef83704b4a61ee..a836a811d6b5ffbf55c41d37dfaba911e4662ac7 100644 (file)
@@ -1,18 +1,9 @@
 local color = minetest.colorize\r
 \r
 local clip_fs = [[\r
-       style_type[label;noclip=%c]\r
-       style_type[button;noclip=%c]\r
-       style_type[image_button;noclip=%c]\r
-       style_type[item_image_button;noclip=%c]\r
-       style_type[tabheader;noclip=%c]\r
-       style_type[field;noclip=%c]\r
-       style_type[textarea;noclip=%c]\r
-       style_type[checkbox;noclip=%c]\r
-       style_type[dropdown;noclip=%c]\r
-       style_type[scrollbar;noclip=%c]\r
-       style_type[table;noclip=%c]\r
-       style_type[animated_image;noclip=%c]\r
+       style_type[label,button,image_button,item_image_button,\r
+                       tabheader,scrollbar,table,animated_image\r
+                       ,field,textarea,checkbox,dropdown;noclip=%c]\r
 \r
        label[0,0;A clipping test]\r
        button[0,1;3,0.8;x;A clipping test]\r
index 40c3bbdaec1144a1ee6b75b5050dce8b6712791e..d892555b306eb58f04221bb3e44661614cfa587a 100644 (file)
@@ -2450,13 +2450,6 @@ bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, b
                return false;
        }
 
-       std::string selector = trim(parts[0]);
-       if (selector.empty()) {
-               errorstream << "Invalid style element (Selector required): '" << element
-                                       << "'" << std::endl;
-               return false;
-       }
-
        StyleSpec spec;
 
        for (size_t i = 1; i < parts.size(); i++) {
@@ -2486,10 +2479,21 @@ bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, b
                spec.set(prop, value);
        }
 
-       if (style_type) {
-               theme_by_type[selector] |= spec;
-       } else {
-               theme_by_name[selector] |= spec;
+       std::vector<std::string> selectors = split(parts[0], ',');
+       for (size_t sel = 0; sel < selectors.size(); sel++) {
+               std::string selector = trim(selectors[sel]);
+
+               if (selector.empty()) {
+                       errorstream << "Invalid style element (Empty selector): '" << element
+                               << "'" << std::endl;
+                       continue;
+               }
+
+               if (style_type) {
+                       theme_by_type[selector] |= spec;
+               } else {
+                       theme_by_name[selector] |= spec;
+               }
        }
 
        return true;