Skip to content

Commit 9541165

Browse files
committedAug 3, 2019
Add styles to most elements
1 parent ec3795a commit 9541165

File tree

9 files changed

+284
-100
lines changed

9 files changed

+284
-100
lines changed
 

‎build/android/jni/Android.mk

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ LOCAL_SRC_FILES := \
177177
jni/src/filesys.cpp \
178178
jni/src/genericobject.cpp \
179179
jni/src/gettext.cpp \
180+
jni/src/gui/guiButton.cpp \
180181
jni/src/gui/guiChatConsole.cpp \
181182
jni/src/gui/guiConfirmRegistration.cpp \
182183
jni/src/gui/guiEditBoxWithScrollbar.cpp \

‎builtin/mainmenu/dlg_delete_content.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ local function delete_content_formspec(dialogdata)
2222
"size[11.5,4.5,true]" ..
2323
"label[2,2;" ..
2424
fgettext("Are you sure you want to delete \"$1\"?", dialogdata.content.name) .. "]"..
25-
"style[dlg_delete_content_confirm;bgcolor;red]" ..
25+
"style[dlg_delete_content_confirm;bgcolor=red]" ..
2626
"button[3.25,3.5;2.5,0.5;dlg_delete_content_confirm;" .. fgettext("Delete") .. "]" ..
2727
"button[5.75,3.5;2.5,0.5;dlg_delete_content_cancel;" .. fgettext("Cancel") .. "]"
2828

‎builtin/mainmenu/dlg_delete_world.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ local function delete_world_formspec(dialogdata)
2121
"size[10,2.5,true]" ..
2222
"label[0.5,0.5;" ..
2323
fgettext("Delete World \"$1\"?", dialogdata.delete_name) .. "]" ..
24-
"style[world_delete_confirm;bgcolor;red]" ..
24+
"style[world_delete_confirm;bgcolor=red]" ..
2525
"button[0.5,1.5;2.5,0.5;world_delete_confirm;" .. fgettext("Delete") .. "]" ..
2626
"button[7.0,1.5;2.5,0.5;world_delete_cancel;" .. fgettext("Cancel") .. "]"
2727
return retval

‎builtin/mainmenu/tab_local.lua

-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ local function get_formspec(tabview, name, tabdata)
102102
)
103103

104104
retval = retval ..
105-
"style_type[button;bgcolor;#006699]" ..
106-
"style[world_delete;bgcolor;red]" ..
107-
"style[world_delete;textcolor;yellow]" ..
108105
"button[4,3.95;2.6,1;world_delete;".. fgettext("Delete") .. "]" ..
109106
"button[6.5,3.95;2.8,1;world_configure;".. fgettext("Configure") .. "]" ..
110107
"button[9.2,3.95;2.5,1;world_create;".. fgettext("New") .. "]" ..

‎doc/lua_api.txt

+78-25
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,10 @@ When displaying text which can contain formspec code, e.g. text set by a player,
18841884
use `minetest.formspec_escape`.
18851885
For coloured text you can use `minetest.colorize`.
18861886

1887-
WARNING: Minetest allows you to add elements to every single formspec instance
1887+
**WARNING**: do _not_ use a element name starting with `key_`; those names are
1888+
reserved to pass key press events to formspec!
1889+
1890+
**WARNING**: Minetest allows you to add elements to every single formspec instance
18881891
using `player:set_formspec_prepend()`, which may be the reason backgrounds are
18891892
appearing when you don't expect them to, or why things are styled differently
18901893
to normal. See [`no_prepend[]`] and [Styling Formspecs].
@@ -2351,22 +2354,17 @@ Elements
23512354
* `span=<value>`: number of following columns to affect
23522355
(default: infinite).
23532356

2354-
**Note**: do _not_ use a element name starting with `key_`; those names are
2355-
reserved to pass key press events to formspec!
2356-
2357-
### `style[<name>;<propery>;<value]`
2357+
### `style[<name>;<prop1>;<prop2>;...]`
23582358

2359-
Set the style for the named element `name`.
2360-
Note: this **must** be before the element's tag.
2359+
* Set the style for the named element `name`.
2360+
* Note: this **must** be before the element is defined.
2361+
* See [Styling Formspecs].
23612362

2362-
See [Styling Formspecs].
23632363

2364+
### `style_type[<type>;<prop1>;<prop2>;...]`
23642365

2365-
### `style_type[<type>;<propery>;<value>]`
2366-
2367-
Sets the style for all elements of type `type` which appear after this tag.
2368-
2369-
See [Styling Formspecs].
2366+
* Sets the style for all elements of type `type` which appear after this element.
2367+
* See [Styling Formspecs].
23702368

23712369
Migrating to Real Coordinates
23722370
-----------------------------
@@ -2406,27 +2404,82 @@ offsets when migrating:
24062404
Styling Formspecs
24072405
-----------------
24082406

2409-
Formspec elements can be themed using the style tags:
2407+
Formspec elements can be themed using the style elements:
2408+
2409+
style[<name>;<prop1>;<prop2>;...]
2410+
style_type[<type>;<prop1>;<prop2>;...]
2411+
2412+
Where a prop is:
24102413

2411-
style[ELEMENT_NAME;PROPERTY;VALUE]
2412-
style_type[ELEMENT_TYPE;PROPERTY;VALUE]
2414+
property_name=property_value
24132415

24142416
For example:
24152417

2416-
style_type[button;bgcolor;#006699]
2417-
style[world_delete;bgcolor;#ff0000]
2418-
button[4,3.95;2.6,1;world_delete;Delete]
2418+
style_type[button;bgcolor=#006699]
2419+
style[world_delete;bgcolor=red;textcolor=yellow]
2420+
button[4,3.95;2.6,1;world_delete;Delete]
24192421

2420-
### Valid Properties
2422+
Setting a property to nothing will reset it to the default value. For example:
2423+
2424+
style_type[button;bgimg=button.png;bgimg_pressed=button_pressed.png;border=false]
2425+
style[btn_exit;bgimg=;bgimg_pressed=;border=;bgcolor=red]
2426+
2427+
2428+
### Supported Element Types
24212429

2422-
* button and button_exit
2423-
* bgcolor - sets button tint
2424-
* textcolor
2430+
Some types may inherit styles from parent types.
2431+
2432+
* button
2433+
* button_exit, inherits from button
2434+
* checkbox
2435+
* scrollbar
2436+
* table
2437+
* textlist
2438+
* dropdown
2439+
* field
2440+
* pwdfield, inherits from field
2441+
* textarea
2442+
* label
2443+
* vertlabel, inherits from field
2444+
* image_button
2445+
* item_image_button, inherits from image_button
24252446
* tabheader
2426-
* bgcolor - tab background
2427-
* textcolor
24282447

24292448

2449+
### Valid Properties
2450+
2451+
* button, button_exit
2452+
* bgcolor - color, sets button tint
2453+
* textcolor - color, default white
2454+
* border - boolean, draw border. Set to false to hide the bevelled button pane. Default true.
2455+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2456+
* bgimg - standard image. Defaults to none.
2457+
* bgimg_pressed - image when pressed. Defaults to bgimg when not provided.
2458+
* alpha - boolean, whether to draw alpha in bgimg. Default true.
2459+
* checkbox
2460+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2461+
* scrollbar
2462+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2463+
* table, textlist
2464+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2465+
* dropdown
2466+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2467+
* field, pwdfield, textarea
2468+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2469+
* border - set to false to hide the textbox background and border. Default true.
2470+
* textcolor - color. Default white.
2471+
* label, vertlabel
2472+
* bgcolor - color. Default unset.
2473+
* textcolor - color. Default white.
2474+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2475+
* border - boolean, set to true to get a border. Default true.
2476+
* image_button, item_image_button
2477+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2478+
* border - boolean, draw border. Set to false to hide the bevelled button pane. Default false.
2479+
* alpha - boolean, whether to draw alpha in bgimg. Default true.
2480+
* tabheader
2481+
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
2482+
* textcolor - color. Default white.
24302483

24312484
Inventory
24322485
=========

‎src/client/renderingengine.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
5555
RenderingEngine *RenderingEngine::s_singleton = nullptr;
5656

5757

58-
static gui::GUISkin* createSkin(gui::IGUIEnvironment *environment,
59-
gui::EGUI_SKIN_TYPE type, video::IVideoDriver *driver)
58+
static gui::GUISkin *createSkin(gui::IGUIEnvironment *environment,
59+
gui::EGUI_SKIN_TYPE type, video::IVideoDriver *driver)
6060
{
61-
gui::GUISkin* skin = new gui::GUISkin(type, driver);
61+
gui::GUISkin *skin = new gui::GUISkin(type, driver);
6262

63-
gui::IGUIFont* builtinfont = environment->getBuiltInFont();
64-
gui::IGUIFontBitmap* bitfont = 0;
63+
gui::IGUIFont *builtinfont = environment->getBuiltInFont();
64+
gui::IGUIFontBitmap *bitfont = nullptr;
6565
if (builtinfont && builtinfont->getType() == gui::EGFT_BITMAP)
6666
bitfont = (gui::IGUIFontBitmap*)builtinfont;
6767

68-
gui::IGUISpriteBank* bank = 0;
68+
gui::IGUISpriteBank *bank = 0;
6969
skin->setFont(builtinfont);
7070

7171
if (bitfont)
@@ -102,7 +102,7 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
102102
u32 i;
103103
for (i = 0; i != drivers.size(); i++) {
104104
if (!strcasecmp(driverstring.c_str(),
105-
RenderingEngine::getVideoDriverName(drivers[i]))) {
105+
RenderingEngine::getVideoDriverName(drivers[i]))) {
106106
driverType = drivers[i];
107107
break;
108108
}
@@ -139,7 +139,7 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
139139
s_singleton = this;
140140

141141
auto skin = createSkin(m_device->getGUIEnvironment(),
142-
gui::EGST_WINDOWS_METALLIC, driver);
142+
gui::EGST_WINDOWS_METALLIC, driver);
143143
m_device->getGUIEnvironment()->setSkin(skin);
144144
skin->drop();
145145
}

‎src/gui/StyleSpec.h

+63-30
Original file line numberDiff line numberDiff line change
@@ -18,85 +18,118 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1818
*/
1919

2020
#include "irrlichttypes_extrabloated.h"
21+
#include <array>
2122

2223
#pragma once
2324

24-
2525
class StyleSpec
2626
{
2727
public:
28-
enum Property {
29-
NONE = 0,
28+
enum Property
29+
{
3030
TEXTCOLOR,
3131
BGCOLOR,
32-
NUM_PROPERTIES
32+
NOCLIP,
33+
BORDER,
34+
BGIMG,
35+
BGIMG_PRESSED,
36+
ALPHA,
37+
NUM_PROPERTIES,
38+
NONE
3339
};
3440

3541
private:
36-
std::unordered_map<Property, std::string> properties;
42+
std::array<bool, NUM_PROPERTIES> property_set;
43+
std::array<std::string, NUM_PROPERTIES> properties;
3744

3845
public:
39-
static Property GetPropertyByName(const std::string &name) {
46+
static Property GetPropertyByName(const std::string &name)
47+
{
4048
if (name == "textcolor") {
4149
return TEXTCOLOR;
4250
} else if (name == "bgcolor") {
4351
return BGCOLOR;
52+
} else if (name == "noclip") {
53+
return NOCLIP;
54+
} else if (name == "border") {
55+
return BORDER;
56+
} else if (name == "bgimg") {
57+
return BGIMG;
58+
} else if (name == "bgimg_pressed") {
59+
return BGIMG_PRESSED;
60+
} else if (name == "alpha") {
61+
return ALPHA;
4462
} else {
4563
return NONE;
4664
}
4765
}
4866

49-
std::string get(Property prop, std::string def) const {
50-
auto it = properties.find(prop);
51-
if (it == properties.end()) {
52-
return def;
53-
}
54-
55-
return it->second;
67+
std::string get(Property prop, std::string def) const
68+
{
69+
const auto &val = properties[prop];
70+
return val.empty() ? def : val;
5671
}
5772

58-
void set(Property prop, std::string value) {
59-
properties[prop] = std::move(value);
73+
void set(Property prop, const std::string &value)
74+
{
75+
properties[prop] = value;
76+
property_set[prop] = true;
6077
}
6178

62-
video::SColor getColor(Property prop, video::SColor def) const {
63-
auto it = properties.find(prop);
64-
if (it == properties.end()) {
79+
video::SColor getColor(Property prop, video::SColor def) const
80+
{
81+
const auto &val = properties[prop];
82+
if (val.empty()) {
6583
return def;
6684
}
6785

68-
parseColorString(it->second, def, false, 0xFF);
86+
parseColorString(val, def, false, 0xFF);
6987
return def;
7088
}
7189

72-
video::SColor getColor(Property prop) const {
73-
auto it = properties.find(prop);
74-
FATAL_ERROR_IF(it == properties.end(), "Unexpected missing property");
90+
video::SColor getColor(Property prop) const
91+
{
92+
const auto &val = properties[prop];
93+
FATAL_ERROR_IF(val.empty(), "Unexpected missing property");
7594

7695
video::SColor color;
77-
parseColorString(it->second, color, false, 0xFF);
96+
parseColorString(val, color, false, 0xFF);
7897
return color;
7998
}
8099

81-
bool hasProperty(Property prop) const {
82-
return properties.find(prop) != properties.end();
100+
bool getBool(Property prop, bool def) const
101+
{
102+
const auto &val = properties[prop];
103+
if (val.empty()) {
104+
return def;
105+
}
106+
107+
return is_yes(val);
108+
}
109+
110+
inline bool isNotDefault(Property prop) const
111+
{
112+
return !properties[prop].empty();
83113
}
84114

85-
StyleSpec &operator|=(const StyleSpec &other) {
86-
for (size_t i = 1; i < NUM_PROPERTIES; i++) {
115+
inline bool hasProperty(Property prop) const { return property_set[prop]; }
116+
117+
StyleSpec &operator|=(const StyleSpec &other)
118+
{
119+
for (size_t i = 0; i < NUM_PROPERTIES; i++) {
87120
auto prop = (Property)i;
88121
if (other.hasProperty(prop)) {
89-
properties[prop] = other.get(prop, "");
122+
set(prop, other.get(prop, ""));
90123
}
91124
}
92125

93126
return *this;
94127
}
95128

96-
StyleSpec operator|(const StyleSpec &other) const {
129+
StyleSpec operator|(const StyleSpec &other) const
130+
{
97131
StyleSpec newspec = *this;
98132
newspec |= other;
99133
return newspec;
100134
}
101135
};
102-

0 commit comments

Comments
 (0)
Please sign in to comment.