@@ -7,18 +7,21 @@ title: Theme
77Make sure to check out [ how to register themes] ( ../themes.md ) .
88
99Here we will take a look what the theme file can look like. If you are a mod developer you can directly translate it to
10- your ` JsonBuilder ` .
10+ your ` ThemeBuilder ` .
1111
12- Let's look at an example. This is what the default vanilla theme as a json file would look like.
12+ Let's look at an example. This is what the default vanilla theme as a json file would mostly look like.
1313
1414``` json
1515{
1616 "parent" : " DEFAULT" ,
17+ "defaultWidth" : 18 ,
18+ "defaultHeight" : 18 ,
1719 "background" : null ,
1820 "hoverBackground" : " none" ,
1921 "color" : " #FFFFFFFF" ,
2022 "textColor" : " #FF404040" ,
2123 "textShadow" : false ,
24+ "iconColor" : " #FF404040" ,
2225 "panel" : {
2326 "background" : {
2427 "type" : " texture" ,
@@ -30,13 +33,15 @@ Let's look at an example. This is what the default vanilla theme as a json file
3033 "type" : " texture" ,
3134 "id" : " mc_button"
3235 },
33- "hoverBackground" : {
34- "type" : " texture" ,
35- "id" : " mc_button_hovered"
36- },
3736 "textColor" : " #FFFFFFFF" ,
3837 "textShadow" : true
3938 },
39+ "button:hover" : {
40+ "background" : {
41+ "type" : " texture" ,
42+ "id" : " mc_button_hovered"
43+ }
44+ },
4045 "itemSlot" : {
4146 "background" : {
4247 "type" : " texture" ,
@@ -65,20 +70,22 @@ Let's look at an example. This is what the default vanilla theme as a json file
6570 "type" : " texture" ,
6671 "id" : " mc_button"
6772 },
68- "hoverBackground" : {
69- "type" : " texture" ,
70- "id" : " mc_button_hovered"
71- },
7273 "textColor" : " #FFFFFFFF" ,
7374 "textShadow" : true ,
7475 "selectedBackground" : {
7576 "type" : " texture" ,
7677 "id" : " mc_button_disabled"
7778 },
78- "selectedHoverBackground" : " none" ,
7979 "selectedColor" : " #FFFFFFFF" ,
8080 "selectedTextColor" : " #FFFFFFFF" ,
8181 "selectedTextShadow" : true
82+ },
83+ "toggleButton:hover" : {
84+ "background" : {
85+ "type" : " texture" ,
86+ "id" : " mc_button_hovered"
87+ },
88+ "selectedBackground" : " none"
8289 }
8390}
8491```
@@ -87,38 +94,129 @@ First we have the `parent` property. This defines the parent theme. If a theme d
8794be taken from its parent. If the ` parent ` property is not set, it defaults to ` DEFAULT ` , which is just the vanilla
8895theme.
8996
90- After that we have the ` color ` , ` background ` , ` hoverBackground ` , ` textColor ` and ` textShadow ` properties. These are
91- fallback properties of [ widget themes] ( #widget-themes ) . You can put any properties that any widget theme can have here.
92- If a widget theme does not have said property it will fall back to the top level property if defined.
93- Note that ` "none" ` is used for ` hoverBackground ` so it will be ignored and the widget doesn't suddenly turn invisible.
94- Read more about the difference between ` "none" ` and ` null ` [ here] ( ./drawable.md#empty-drawable )
97+ After that we have the ` defaultWidth ` , ` defaultHeight ` , ` color ` , ` background ` , ` textColor ` ,
98+ ` textShadow ` and ` iconColor ` properties. These are fallback properties of [ widget themes] ( #widget-themes ) . You can put
99+ any properties that any widget theme can have here. If a widget theme does not have said property it will fall back to
100+ the top level property if defined. The ` defaultWidth ` and ` defaultHeight ` properties determine the default widget size
101+ if it isn't specified. Note this won't work on every widget. ` TextWidget ` for example have a default size that is
102+ exactly the size of the text they are displaying.
103+
104+ See [ widget themes] ( theme_ref.md ) to find out what widget themes ModularUI provides and what properties they have.
105+ Addons may add more.
106+
107+ Additionally, you can add a
108+ ``` json
109+ {
110+ "override" : true
111+ }
112+ ```
113+ property to the top level. This will discard any previous defined themes with the same name of other resourcepacks.
114+ Otherwise, they will be merged, where the theme will only override properties it has defined.
115+
116+ :::info Note {id="note"}
117+ All widget themes are optional. You can define as many as you like. Not defined widget themes will be taken from the
118+ parent theme.
119+ All properties of widget themes (and the fallback properties) are optional.
120+ :::
121+
122+ ## Hover widget themes
123+ You may have noticed the widget themes in the example ` "button:hover": {...} ` and ` "toggleButton:hover": {...} ` . This is
124+ because when a widget is hovered with the mouse a separate widget theme will be applied. This hover widget theme has all
125+ the properties of the non hover variant. In terms of property inheritance they behave like
126+ [ sub widget themes] ( #sub-widget-themes ) . If the non hover variant is specified in the current theme, then the properties
127+ will be inherited from there. Otherwise, it will be inherited from the hover widget theme in the parent theme. This also
128+ means that if the none hover variant is specified with any amount of properties, all hover effects from a parent theme
129+ are lost. You will have to re-add them to you current theme.
130+ Unlike sub widget themes, hover widget themes don't need to be registered. Just add the suffix ` :hover ` to any
131+ registered widget theme (yes, even sub widget themes) and it will work.
132+
133+ Note that ` "none" ` is used for ` background ` inside the hover widget theme so it will be ignored
134+ and the widget doesn't suddenly turn invisible when you don't want a separate hover texture. Read more about the
135+ difference between ` "none" ` and ` null ` [ here] ( ./drawable.md#empty-drawable ) .
95136
96- For ` color ` and ` textColor ` see [ color ] ( ./color.md ) . For ` background ` and ` hoverBackground `
97- see [ drawables ] ( ./drawable.md ) .
137+ You might think that ` slotHoverColor ` from item slot and fluid slot would belong in the hover widget theme, however
138+ these are special. Specifying them in the hover widget theme variant has no effect .
98139
99- Next we have objects defined with the property name ` panel ` , ` button ` , ` itemSlot ` , ` fluidSlot ` , ` textField ` and
100- ` toggleButton ` .
101- These are widget themes. These are all widget themes ModularUI provides. Addons may add more.
140+ The ` defaultWidth ` and the ` defaultHeight ` property obviously have no effect in the hover variant.
102141
103- ## Widget themes
142+ ## Inheritance of properties
104143
105- Widgets which don't use one of the existing widget themes use the fallback properties.
144+ All properties will default to the parent themes widget theme properties, except ` color ` , ` textColor ` , ` textShadow ` and
145+ ` iconColor ` . These default first to the fallback properties. You can override this behavior, by adding a ` inherit `
146+ property to a widget theme. The value of the property should either be a string or a list of strings where each string
147+ is the name of the before mentioned properties. Let's look at an example
106148
107- All widget themes have the properties ` color ` , ` background ` , ` hoverBackground ` , ` textColor ` and ` textShadow ` . Which are
108- all mostly self-explanatory. ` color ` is applied additionally to the background (if possible).
149+ Let's say we have a theme A
150+ ``` json
151+ {
152+ "button" : {
153+ "defaultWidth" : 24 ,
154+ "color" : " #FF0000"
155+ }
156+ }
157+ ```
158+ and a theme B which is a child of A
159+ ``` json
160+ {
161+ "parent" : " A" ,
162+ "defaultWidth" : 20 ,
163+ "color" : " #00FF00" ,
164+ "button" : {
165+ }
166+ }
167+ ```
168+ Since ` defaultWidth ` will be inherited from the parents widget theme, the default width of the button is 24 and not 20.
169+ Contrary to ` color ` which uses the fallback value first. This means the button will have a color ` #00FF00 ` and not
170+ ` #FF0000 ` . Sometimes this behavior is not desirable. We could copy the value from the parent, but that's extra work and
171+ doesn't get updated when the parent value changes. Instead, we use the ` inherit ` property:
172+ ``` json
173+ {
174+ "parent" : " A" ,
175+ "defaultWidth" : 20 ,
176+ "color" : " #00FF00" ,
177+ "button" : {
178+ "inherit" : [
179+ " color"
180+ ]
181+ }
182+ }
183+ ```
184+ Now the button color of B will be whatever the parent widget themes values is. In this case it is ` #FF0000 ` . Since we
185+ only have one value in the inherit list, it can be shortened to ` "inherit": "color" ` .
109186
110- The ` itemSlot ` and ` fluidSlot ` also have the ` slotHoverColor ` , which is just the rendered color when the slot is
111- hovered .
112- Don't use full opacity here. Otherwise, you won't be able to see the item.
187+ :::info Note {id="note"}
188+ Note that other mods may add properties which behave similar to ` color ` .
189+ :::
113190
114- The ` textField ` theme has the ` markedColor ` property which is the marked text background and the ` hintColor ` property which is
115- the color of the text that is shown when the field is empty.
191+ ## Sub Widget Themes
192+ Sometimes you want to have different widget themes for the same type of widget. Let's say for example you want to color
193+ the player slots differently than normal slots. In java, we first need to register the sub widget theme with
194+ ``` java
195+ WidgetThemeKey<SlotTheme > ITEM_SLOT_PLAYER = ITEM_SLOT . createSubKey(" player" );
196+ ```
116197
117- The ` toggleButton ` has ` selectedBackground ` , ` selectedHoverBackground ` , ` selectedColor ` , ` selectedTextColor ` and
118- ` selectedTextShadow ` which are all self-explanatory. Note that
198+ Then inside a theme json we can do this.
199+ ``` json
200+ {
201+ "itemSlot:player" : {
202+ "color" : " #FF0000"
203+ }
204+ }
205+ ```
206+ This will color only player slots red. The syntax is ` parentWidgetThemeName:subName ` . Every sub widget theme has to be
207+ defined via a mod. ModularUI currently only has the ` itemSlot:player ` sub widget theme defined. Every sub theme can have
208+ any properties it's parent can have. Sub widget themes can have sub widget themes.
209+
210+ Let's say that we now want to color hotbar slots a different color. We could create a new sub widget theme from
211+ ` ITEM_SLOT ` , but if the hotbar theme is not specified it should inherit the player slot theme. We therefore create a sub
212+ widget theme for the just created sub widget theme.
213+ ``` java
214+ WidgetThemeKey<SlotTheme > ITEM_SLOT_PLAYER_HOTBAR = ITEM_SLOT_PLAYER . createSubKey(" playerHotbar" );
215+ ```
216+ This new widget theme can be accessed with ` "itemSlot:playerHotbar" ` and ** not** ` "itemSlot:player:playerHotbar" ` .
217+ The syntax is ` rootParentWidgetThemeName:subName ` . You can find the sub widget themes ModularUI provides [ here] ( theme_ref.md#sub-widget-themes ) .
119218
120219:::info Note {id="note"}
121- All widget themes are optional. You can define as many as you like. Not defined widget themes will be taken from the
122- parent theme.
123- All properties of widget themes (and the fallback properties) are optional.
220+ This feature is intended for widgets with the same type and not for different widget types which use the same widget
221+ theme class.
124222:::
0 commit comments