editor_theme_manager.cpp 170 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821
  1. /**************************************************************************/
  2. /* editor_theme_manager.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_theme_manager.h"
  31. #include "core/error/error_macros.h"
  32. #include "core/io/resource_loader.h"
  33. #include "editor/editor_settings.h"
  34. #include "editor/editor_string_names.h"
  35. #include "editor/themes/editor_color_map.h"
  36. #include "editor/themes/editor_fonts.h"
  37. #include "editor/themes/editor_icons.h"
  38. #include "editor/themes/editor_scale.h"
  39. #include "editor/themes/editor_theme.h"
  40. #include "scene/gui/graph_edit.h"
  41. #include "scene/resources/image_texture.h"
  42. #include "scene/resources/style_box_flat.h"
  43. #include "scene/resources/style_box_line.h"
  44. #include "scene/resources/style_box_texture.h"
  45. #include "scene/resources/texture.h"
  46. // Theme configuration.
  47. uint32_t EditorThemeManager::ThemeConfiguration::hash() {
  48. uint32_t hash = hash_murmur3_one_float(EDSCALE);
  49. // Basic properties.
  50. hash = hash_murmur3_one_32(preset.hash(), hash);
  51. hash = hash_murmur3_one_32(spacing_preset.hash(), hash);
  52. hash = hash_murmur3_one_32(base_color.to_rgba32(), hash);
  53. hash = hash_murmur3_one_32(accent_color.to_rgba32(), hash);
  54. hash = hash_murmur3_one_float(contrast, hash);
  55. hash = hash_murmur3_one_float(icon_saturation, hash);
  56. // Extra properties.
  57. hash = hash_murmur3_one_32(base_spacing, hash);
  58. hash = hash_murmur3_one_32(extra_spacing, hash);
  59. hash = hash_murmur3_one_32(border_width, hash);
  60. hash = hash_murmur3_one_32(corner_radius, hash);
  61. hash = hash_murmur3_one_32((int)draw_extra_borders, hash);
  62. hash = hash_murmur3_one_float(relationship_line_opacity, hash);
  63. hash = hash_murmur3_one_32(thumb_size, hash);
  64. hash = hash_murmur3_one_32(class_icon_size, hash);
  65. hash = hash_murmur3_one_32((int)increase_scrollbar_touch_area, hash);
  66. hash = hash_murmur3_one_float(gizmo_handle_scale, hash);
  67. hash = hash_murmur3_one_32(color_picker_button_height, hash);
  68. hash = hash_murmur3_one_float(subresource_hue_tint, hash);
  69. hash = hash_murmur3_one_float(default_contrast, hash);
  70. // Generated properties.
  71. hash = hash_murmur3_one_32((int)dark_theme, hash);
  72. return hash;
  73. }
  74. uint32_t EditorThemeManager::ThemeConfiguration::hash_fonts() {
  75. uint32_t hash = hash_murmur3_one_float(EDSCALE);
  76. // TODO: Implement the hash based on what editor_register_fonts() uses.
  77. return hash;
  78. }
  79. uint32_t EditorThemeManager::ThemeConfiguration::hash_icons() {
  80. uint32_t hash = hash_murmur3_one_float(EDSCALE);
  81. hash = hash_murmur3_one_32(accent_color.to_rgba32(), hash);
  82. hash = hash_murmur3_one_float(icon_saturation, hash);
  83. hash = hash_murmur3_one_32(thumb_size, hash);
  84. hash = hash_murmur3_one_float(gizmo_handle_scale, hash);
  85. hash = hash_murmur3_one_32((int)dark_theme, hash);
  86. return hash;
  87. }
  88. // Benchmarks.
  89. int EditorThemeManager::benchmark_run = 0;
  90. String EditorThemeManager::get_benchmark_key() {
  91. if (benchmark_run == 0) {
  92. return "EditorTheme (Startup)";
  93. }
  94. return vformat("EditorTheme (Run %d)", benchmark_run);
  95. }
  96. // Generation helper methods.
  97. Ref<StyleBoxTexture> make_stylebox(Ref<Texture2D> p_texture, float p_left, float p_top, float p_right, float p_bottom, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1, bool p_draw_center = true) {
  98. Ref<StyleBoxTexture> style(memnew(StyleBoxTexture));
  99. style->set_texture(p_texture);
  100. style->set_texture_margin_individual(p_left * EDSCALE, p_top * EDSCALE, p_right * EDSCALE, p_bottom * EDSCALE);
  101. style->set_content_margin_individual((p_left + p_margin_left) * EDSCALE, (p_top + p_margin_top) * EDSCALE, (p_right + p_margin_right) * EDSCALE, (p_bottom + p_margin_bottom) * EDSCALE);
  102. style->set_draw_center(p_draw_center);
  103. return style;
  104. }
  105. Ref<StyleBoxEmpty> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) {
  106. Ref<StyleBoxEmpty> style(memnew(StyleBoxEmpty));
  107. style->set_content_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE);
  108. return style;
  109. }
  110. Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1, int p_corner_width = 0) {
  111. Ref<StyleBoxFlat> style(memnew(StyleBoxFlat));
  112. style->set_bg_color(p_color);
  113. // Adjust level of detail based on the corners' effective sizes.
  114. style->set_corner_detail(Math::ceil(0.8 * p_corner_width * EDSCALE));
  115. style->set_corner_radius_all(p_corner_width * EDSCALE);
  116. style->set_content_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE);
  117. // Work around issue about antialiased edges being blurrier (GH-35279).
  118. style->set_anti_aliased(false);
  119. return style;
  120. }
  121. Ref<StyleBoxLine> make_line_stylebox(Color p_color, int p_thickness = 1, float p_grow_begin = 1, float p_grow_end = 1, bool p_vertical = false) {
  122. Ref<StyleBoxLine> style(memnew(StyleBoxLine));
  123. style->set_color(p_color);
  124. style->set_grow_begin(p_grow_begin);
  125. style->set_grow_end(p_grow_end);
  126. style->set_thickness(p_thickness);
  127. style->set_vertical(p_vertical);
  128. return style;
  129. }
  130. // Theme generation and population routines.
  131. Ref<EditorTheme> EditorThemeManager::_create_base_theme(const Ref<EditorTheme> &p_old_theme) {
  132. OS::get_singleton()->benchmark_begin_measure(get_benchmark_key(), "Create Base Theme");
  133. Ref<EditorTheme> theme = memnew(EditorTheme);
  134. ThemeConfiguration config = _create_theme_config(theme);
  135. theme->set_generated_hash(config.hash());
  136. theme->set_generated_fonts_hash(config.hash_fonts());
  137. theme->set_generated_icons_hash(config.hash_icons());
  138. print_verbose(vformat("EditorTheme: Generating new theme for the config '%d'.", theme->get_generated_hash()));
  139. _create_shared_styles(theme, config);
  140. // Register icons.
  141. {
  142. OS::get_singleton()->benchmark_begin_measure(get_benchmark_key(), "Register Icons");
  143. // External functions, see editor_icons.cpp.
  144. editor_configure_icons(config.dark_theme);
  145. // If settings are comparable to the old theme, then just copy existing icons over.
  146. // Otherwise, regenerate them.
  147. bool keep_old_icons = (p_old_theme.is_valid() && theme->get_generated_icons_hash() == p_old_theme->get_generated_icons_hash());
  148. if (keep_old_icons) {
  149. print_verbose("EditorTheme: Can keep old icons, copying.");
  150. editor_copy_icons(theme, p_old_theme);
  151. } else {
  152. print_verbose("EditorTheme: Generating new icons.");
  153. editor_register_icons(theme, config.dark_theme, config.icon_saturation, config.thumb_size, config.gizmo_handle_scale);
  154. }
  155. OS::get_singleton()->benchmark_end_measure(get_benchmark_key(), "Register Icons");
  156. }
  157. // Register fonts.
  158. {
  159. OS::get_singleton()->benchmark_begin_measure(get_benchmark_key(), "Register Fonts");
  160. // TODO: Check if existing font definitions from the old theme are usable and copy them.
  161. // External function, see editor_fonts.cpp.
  162. print_verbose("EditorTheme: Generating new fonts.");
  163. editor_register_fonts(theme);
  164. OS::get_singleton()->benchmark_end_measure(get_benchmark_key(), "Register Fonts");
  165. }
  166. // TODO: Check if existing style definitions from the old theme are usable and copy them.
  167. print_verbose("EditorTheme: Generating new styles.");
  168. _populate_standard_styles(theme, config);
  169. _populate_editor_styles(theme, config);
  170. _populate_text_editor_styles(theme, config);
  171. _populate_visual_shader_styles(theme, config);
  172. OS::get_singleton()->benchmark_end_measure(get_benchmark_key(), "Create Base Theme");
  173. return theme;
  174. }
  175. EditorThemeManager::ThemeConfiguration EditorThemeManager::_create_theme_config(const Ref<EditorTheme> &p_theme) {
  176. ThemeConfiguration config;
  177. // Basic properties.
  178. config.preset = EDITOR_GET("interface/theme/preset");
  179. config.spacing_preset = EDITOR_GET("interface/theme/spacing_preset");
  180. config.base_color = EDITOR_GET("interface/theme/base_color");
  181. config.accent_color = EDITOR_GET("interface/theme/accent_color");
  182. config.contrast = EDITOR_GET("interface/theme/contrast");
  183. config.icon_saturation = EDITOR_GET("interface/theme/icon_saturation");
  184. // Extra properties.
  185. config.base_spacing = EDITOR_GET("interface/theme/base_spacing");
  186. config.extra_spacing = EDITOR_GET("interface/theme/additional_spacing");
  187. // Ensure borders are visible when using an editor scale below 100%.
  188. config.border_width = CLAMP((int)EDITOR_GET("interface/theme/border_size"), 0, 2) * MAX(1, EDSCALE);
  189. config.corner_radius = CLAMP((int)EDITOR_GET("interface/theme/corner_radius"), 0, 6);
  190. config.draw_extra_borders = EDITOR_GET("interface/theme/draw_extra_borders");
  191. config.relationship_line_opacity = EDITOR_GET("interface/theme/relationship_line_opacity");
  192. config.thumb_size = EDITOR_GET("filesystem/file_dialog/thumbnail_size");
  193. config.class_icon_size = 16 * EDSCALE;
  194. config.increase_scrollbar_touch_area = EDITOR_GET("interface/touchscreen/increase_scrollbar_touch_area");
  195. config.gizmo_handle_scale = EDITOR_GET("interface/touchscreen/scale_gizmo_handles");
  196. config.color_picker_button_height = 28 * EDSCALE;
  197. config.subresource_hue_tint = EDITOR_GET("docks/property_editor/subresource_hue_tint");
  198. config.default_contrast = 0.3; // Make sure to keep this in sync with the editor settings definition.
  199. // Handle main theme preset.
  200. {
  201. const bool follow_system_theme = EDITOR_GET("interface/theme/follow_system_theme");
  202. const bool use_system_accent_color = EDITOR_GET("interface/theme/use_system_accent_color");
  203. DisplayServer *display_server = DisplayServer::get_singleton();
  204. Color system_base_color = display_server->get_base_color();
  205. Color system_accent_color = display_server->get_accent_color();
  206. if (follow_system_theme) {
  207. String dark_theme = "Default";
  208. String light_theme = "Light";
  209. config.preset = light_theme; // Assume light theme if we can't detect system theme attributes.
  210. if (system_base_color == Color(0, 0, 0, 0)) {
  211. if (display_server->is_dark_mode_supported() && display_server->is_dark_mode()) {
  212. config.preset = dark_theme;
  213. }
  214. } else {
  215. if (system_base_color.get_luminance() < 0.5) {
  216. config.preset = dark_theme;
  217. }
  218. }
  219. }
  220. if (config.preset != "Custom") {
  221. Color preset_accent_color;
  222. Color preset_base_color;
  223. float preset_contrast = 0;
  224. bool preset_draw_extra_borders = false;
  225. // Please use alphabetical order if you're adding a new theme here.
  226. if (config.preset == "Breeze Dark") {
  227. preset_accent_color = Color(0.26, 0.76, 1.00);
  228. preset_base_color = Color(0.24, 0.26, 0.28);
  229. preset_contrast = config.default_contrast;
  230. } else if (config.preset == "Godot 2") {
  231. preset_accent_color = Color(0.53, 0.67, 0.89);
  232. preset_base_color = Color(0.24, 0.23, 0.27);
  233. preset_contrast = config.default_contrast;
  234. } else if (config.preset == "Gray") {
  235. preset_accent_color = Color(0.44, 0.73, 0.98);
  236. preset_base_color = Color(0.24, 0.24, 0.24);
  237. preset_contrast = config.default_contrast;
  238. } else if (config.preset == "Light") {
  239. preset_accent_color = Color(0.18, 0.50, 1.00);
  240. preset_base_color = Color(0.9, 0.9, 0.9);
  241. // A negative contrast rate looks better for light themes, since it better follows the natural order of UI "elevation".
  242. preset_contrast = -0.06;
  243. } else if (config.preset == "Solarized (Dark)") {
  244. preset_accent_color = Color(0.15, 0.55, 0.82);
  245. preset_base_color = Color(0.04, 0.23, 0.27);
  246. preset_contrast = config.default_contrast;
  247. } else if (config.preset == "Solarized (Light)") {
  248. preset_accent_color = Color(0.15, 0.55, 0.82);
  249. preset_base_color = Color(0.89, 0.86, 0.79);
  250. // A negative contrast rate looks better for light themes, since it better follows the natural order of UI "elevation".
  251. preset_contrast = -0.06;
  252. } else if (config.preset == "Black (OLED)") {
  253. preset_accent_color = Color(0.45, 0.75, 1.0);
  254. preset_base_color = Color(0, 0, 0);
  255. // The contrast rate value is irrelevant on a fully black theme.
  256. preset_contrast = 0.0;
  257. preset_draw_extra_borders = true;
  258. } else { // Default
  259. preset_accent_color = Color(0.44, 0.73, 0.98);
  260. preset_base_color = Color(0.21, 0.24, 0.29);
  261. preset_contrast = config.default_contrast;
  262. }
  263. config.accent_color = preset_accent_color;
  264. config.base_color = preset_base_color;
  265. config.contrast = preset_contrast;
  266. config.draw_extra_borders = preset_draw_extra_borders;
  267. EditorSettings::get_singleton()->set_initial_value("interface/theme/accent_color", config.accent_color);
  268. EditorSettings::get_singleton()->set_initial_value("interface/theme/base_color", config.base_color);
  269. EditorSettings::get_singleton()->set_initial_value("interface/theme/contrast", config.contrast);
  270. EditorSettings::get_singleton()->set_initial_value("interface/theme/draw_extra_borders", config.draw_extra_borders);
  271. }
  272. if (follow_system_theme && system_base_color != Color(0, 0, 0, 0)) {
  273. config.base_color = system_base_color;
  274. config.preset = "Custom";
  275. }
  276. if (use_system_accent_color && system_accent_color != Color(0, 0, 0, 0)) {
  277. config.accent_color = system_accent_color;
  278. config.preset = "Custom";
  279. }
  280. // Enforce values in case they were adjusted or overridden.
  281. EditorSettings::get_singleton()->set_manually("interface/theme/preset", config.preset);
  282. EditorSettings::get_singleton()->set_manually("interface/theme/accent_color", config.accent_color);
  283. EditorSettings::get_singleton()->set_manually("interface/theme/base_color", config.base_color);
  284. EditorSettings::get_singleton()->set_manually("interface/theme/contrast", config.contrast);
  285. EditorSettings::get_singleton()->set_manually("interface/theme/draw_extra_borders", config.draw_extra_borders);
  286. }
  287. // Handle theme spacing preset.
  288. {
  289. if (config.spacing_preset != "Custom") {
  290. int preset_base_spacing = 0;
  291. int preset_extra_spacing = 0;
  292. Size2 preset_dialogs_buttons_min_size;
  293. if (config.spacing_preset == "Compact") {
  294. preset_base_spacing = 0;
  295. preset_extra_spacing = 4;
  296. preset_dialogs_buttons_min_size = Size2(90, 26);
  297. } else if (config.spacing_preset == "Spacious") {
  298. preset_base_spacing = 6;
  299. preset_extra_spacing = 2;
  300. preset_dialogs_buttons_min_size = Size2(112, 36);
  301. } else { // Default
  302. preset_base_spacing = 4;
  303. preset_extra_spacing = 0;
  304. preset_dialogs_buttons_min_size = Size2(105, 34);
  305. }
  306. config.base_spacing = preset_base_spacing;
  307. config.extra_spacing = preset_extra_spacing;
  308. config.dialogs_buttons_min_size = preset_dialogs_buttons_min_size;
  309. EditorSettings::get_singleton()->set_initial_value("interface/theme/base_spacing", config.base_spacing);
  310. EditorSettings::get_singleton()->set_initial_value("interface/theme/additional_spacing", config.extra_spacing);
  311. }
  312. // Enforce values in case they were adjusted or overridden.
  313. EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", config.spacing_preset);
  314. EditorSettings::get_singleton()->set_manually("interface/theme/base_spacing", config.base_spacing);
  315. EditorSettings::get_singleton()->set_manually("interface/theme/additional_spacing", config.extra_spacing);
  316. }
  317. // Generated properties.
  318. config.dark_theme = is_dark_theme();
  319. config.base_margin = config.base_spacing;
  320. config.increased_margin = config.base_spacing + config.extra_spacing;
  321. config.separation_margin = (config.base_spacing + config.extra_spacing / 2) * EDSCALE;
  322. config.popup_margin = config.base_margin * 2.4 * EDSCALE;
  323. // Make sure content doesn't stick to window decorations; this can be fixed in future with layout changes.
  324. config.window_border_margin = MAX(1, config.base_margin * 2);
  325. config.top_bar_separation = config.base_margin * 2 * EDSCALE;
  326. // Force the v_separation to be even so that the spacing on top and bottom is even.
  327. // If the vsep is odd and cannot be split into 2 even groups (of pixels), then it will be lopsided.
  328. // We add 2 to the vsep to give it some extra spacing which looks a bit more modern (see Windows, for example).
  329. const int separation_base = config.increased_margin + 6;
  330. config.forced_even_separation = separation_base + (separation_base % 2);
  331. return config;
  332. }
  333. void EditorThemeManager::_create_shared_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config) {
  334. // Colors.
  335. {
  336. // Base colors.
  337. p_theme->set_color("base_color", EditorStringName(Editor), p_config.base_color);
  338. p_theme->set_color("accent_color", EditorStringName(Editor), p_config.accent_color);
  339. // White (dark theme) or black (light theme), will be used to generate the rest of the colors
  340. p_config.mono_color = p_config.dark_theme ? Color(1, 1, 1) : Color(0, 0, 0);
  341. // Ensure base colors are in the 0..1 luminance range to avoid 8-bit integer overflow or text rendering issues.
  342. // Some places in the editor use 8-bit integer colors.
  343. p_config.dark_color_1 = p_config.base_color.lerp(Color(0, 0, 0, 1), p_config.contrast).clamp();
  344. p_config.dark_color_2 = p_config.base_color.lerp(Color(0, 0, 0, 1), p_config.contrast * 1.5).clamp();
  345. p_config.dark_color_3 = p_config.base_color.lerp(Color(0, 0, 0, 1), p_config.contrast * 2).clamp();
  346. p_config.contrast_color_1 = p_config.base_color.lerp(p_config.mono_color, MAX(p_config.contrast, p_config.default_contrast));
  347. p_config.contrast_color_2 = p_config.base_color.lerp(p_config.mono_color, MAX(p_config.contrast * 1.5, p_config.default_contrast * 1.5));
  348. p_config.highlight_color = Color(p_config.accent_color.r, p_config.accent_color.g, p_config.accent_color.b, 0.275);
  349. p_config.highlight_disabled_color = p_config.highlight_color.lerp(p_config.dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.5);
  350. p_config.success_color = Color(0.45, 0.95, 0.5);
  351. p_config.warning_color = Color(1, 0.87, 0.4);
  352. p_config.error_color = Color(1, 0.47, 0.42);
  353. if (!p_config.dark_theme) {
  354. // Darken some colors to be readable on a light background.
  355. p_config.success_color = p_config.success_color.lerp(p_config.mono_color, 0.35);
  356. p_config.warning_color = Color(0.82, 0.56, 0.1);
  357. p_config.error_color = Color(0.8, 0.22, 0.22);
  358. }
  359. p_theme->set_color("mono_color", EditorStringName(Editor), p_config.mono_color);
  360. p_theme->set_color("dark_color_1", EditorStringName(Editor), p_config.dark_color_1);
  361. p_theme->set_color("dark_color_2", EditorStringName(Editor), p_config.dark_color_2);
  362. p_theme->set_color("dark_color_3", EditorStringName(Editor), p_config.dark_color_3);
  363. p_theme->set_color("contrast_color_1", EditorStringName(Editor), p_config.contrast_color_1);
  364. p_theme->set_color("contrast_color_2", EditorStringName(Editor), p_config.contrast_color_2);
  365. p_theme->set_color("highlight_color", EditorStringName(Editor), p_config.highlight_color);
  366. p_theme->set_color("highlight_disabled_color", EditorStringName(Editor), p_config.highlight_disabled_color);
  367. p_theme->set_color("success_color", EditorStringName(Editor), p_config.success_color);
  368. p_theme->set_color("warning_color", EditorStringName(Editor), p_config.warning_color);
  369. p_theme->set_color("error_color", EditorStringName(Editor), p_config.error_color);
  370. #ifndef DISABLE_DEPRECATED // Used before 4.3.
  371. p_theme->set_color("disabled_highlight_color", EditorStringName(Editor), p_config.highlight_disabled_color);
  372. #endif
  373. // Only used when the Draw Extra Borders editor setting is enabled.
  374. p_config.extra_border_color_1 = Color(0.5, 0.5, 0.5);
  375. p_config.extra_border_color_2 = p_config.dark_theme ? Color(0.3, 0.3, 0.3) : Color(0.7, 0.7, 0.7);
  376. p_theme->set_color("extra_border_color_1", EditorStringName(Editor), p_config.extra_border_color_1);
  377. p_theme->set_color("extra_border_color_2", EditorStringName(Editor), p_config.extra_border_color_2);
  378. // Font colors.
  379. p_config.font_color = p_config.mono_color.lerp(p_config.base_color, 0.25);
  380. p_config.font_focus_color = p_config.mono_color.lerp(p_config.base_color, 0.125);
  381. p_config.font_hover_color = p_config.mono_color.lerp(p_config.base_color, 0.125);
  382. p_config.font_pressed_color = p_config.accent_color;
  383. p_config.font_hover_pressed_color = p_config.font_hover_color.lerp(p_config.accent_color, 0.74);
  384. p_config.font_disabled_color = Color(p_config.mono_color.r, p_config.mono_color.g, p_config.mono_color.b, 0.35);
  385. p_config.font_readonly_color = Color(p_config.mono_color.r, p_config.mono_color.g, p_config.mono_color.b, 0.65);
  386. p_config.font_placeholder_color = Color(p_config.mono_color.r, p_config.mono_color.g, p_config.mono_color.b, 0.6);
  387. p_config.font_outline_color = Color(0, 0, 0, 0);
  388. p_theme->set_color(SceneStringName(font_color), EditorStringName(Editor), p_config.font_color);
  389. p_theme->set_color("font_focus_color", EditorStringName(Editor), p_config.font_focus_color);
  390. p_theme->set_color("font_hover_color", EditorStringName(Editor), p_config.font_hover_color);
  391. p_theme->set_color("font_pressed_color", EditorStringName(Editor), p_config.font_pressed_color);
  392. p_theme->set_color("font_hover_pressed_color", EditorStringName(Editor), p_config.font_hover_pressed_color);
  393. p_theme->set_color("font_disabled_color", EditorStringName(Editor), p_config.font_disabled_color);
  394. p_theme->set_color("font_readonly_color", EditorStringName(Editor), p_config.font_readonly_color);
  395. p_theme->set_color("font_placeholder_color", EditorStringName(Editor), p_config.font_placeholder_color);
  396. p_theme->set_color("font_outline_color", EditorStringName(Editor), p_config.font_outline_color);
  397. #ifndef DISABLE_DEPRECATED // Used before 4.3.
  398. p_theme->set_color("readonly_font_color", EditorStringName(Editor), p_config.font_readonly_color);
  399. p_theme->set_color("disabled_font_color", EditorStringName(Editor), p_config.font_disabled_color);
  400. p_theme->set_color("readonly_color", EditorStringName(Editor), p_config.font_readonly_color);
  401. p_theme->set_color("highlighted_font_color", EditorStringName(Editor), p_config.font_hover_color); // Closest equivalent.
  402. #endif
  403. // Icon colors.
  404. p_config.icon_normal_color = Color(1, 1, 1);
  405. p_config.icon_focus_color = p_config.icon_normal_color * (p_config.dark_theme ? 1.15 : 1.45);
  406. p_config.icon_focus_color.a = 1.0;
  407. p_config.icon_hover_color = p_config.icon_focus_color;
  408. // Make the pressed icon color overbright because icons are not completely white on a dark theme.
  409. // On a light theme, icons are dark, so we need to modulate them with an even brighter color.
  410. p_config.icon_pressed_color = p_config.accent_color * (p_config.dark_theme ? 1.15 : 3.5);
  411. p_config.icon_pressed_color.a = 1.0;
  412. p_config.icon_disabled_color = Color(p_config.icon_normal_color, 0.4);
  413. p_theme->set_color("icon_normal_color", EditorStringName(Editor), p_config.icon_normal_color);
  414. p_theme->set_color("icon_focus_color", EditorStringName(Editor), p_config.icon_focus_color);
  415. p_theme->set_color("icon_hover_color", EditorStringName(Editor), p_config.icon_hover_color);
  416. p_theme->set_color("icon_pressed_color", EditorStringName(Editor), p_config.icon_pressed_color);
  417. p_theme->set_color("icon_disabled_color", EditorStringName(Editor), p_config.icon_disabled_color);
  418. // Additional GUI colors.
  419. p_config.shadow_color = Color(0, 0, 0, p_config.dark_theme ? 0.3 : 0.1);
  420. p_config.selection_color = p_config.accent_color * Color(1, 1, 1, 0.4);
  421. p_config.disabled_border_color = p_config.mono_color.inverted().lerp(p_config.base_color, 0.7);
  422. p_config.disabled_bg_color = p_config.mono_color.inverted().lerp(p_config.base_color, 0.9);
  423. p_config.separator_color = Color(p_config.mono_color.r, p_config.mono_color.g, p_config.mono_color.b, 0.1);
  424. p_theme->set_color("selection_color", EditorStringName(Editor), p_config.selection_color);
  425. p_theme->set_color("disabled_border_color", EditorStringName(Editor), p_config.disabled_border_color);
  426. p_theme->set_color("disabled_bg_color", EditorStringName(Editor), p_config.disabled_bg_color);
  427. p_theme->set_color("separator_color", EditorStringName(Editor), p_config.separator_color);
  428. // Additional editor colors.
  429. p_theme->set_color("box_selection_fill_color", EditorStringName(Editor), p_config.accent_color * Color(1, 1, 1, 0.3));
  430. p_theme->set_color("box_selection_stroke_color", EditorStringName(Editor), p_config.accent_color * Color(1, 1, 1, 0.8));
  431. p_theme->set_color("axis_x_color", EditorStringName(Editor), Color(0.96, 0.20, 0.32));
  432. p_theme->set_color("axis_y_color", EditorStringName(Editor), Color(0.53, 0.84, 0.01));
  433. p_theme->set_color("axis_z_color", EditorStringName(Editor), Color(0.16, 0.55, 0.96));
  434. p_theme->set_color("axis_w_color", EditorStringName(Editor), Color(0.55, 0.55, 0.55));
  435. const float prop_color_saturation = p_config.accent_color.get_s() * 0.75;
  436. const float prop_color_value = p_config.accent_color.get_v();
  437. p_theme->set_color("property_color_x", EditorStringName(Editor), Color().from_hsv(0.0 / 3.0 + 0.05, prop_color_saturation, prop_color_value));
  438. p_theme->set_color("property_color_y", EditorStringName(Editor), Color().from_hsv(1.0 / 3.0 + 0.05, prop_color_saturation, prop_color_value));
  439. p_theme->set_color("property_color_z", EditorStringName(Editor), Color().from_hsv(2.0 / 3.0 + 0.05, prop_color_saturation, prop_color_value));
  440. p_theme->set_color("property_color_w", EditorStringName(Editor), Color().from_hsv(1.5 / 3.0 + 0.05, prop_color_saturation, prop_color_value));
  441. // Special colors for rendering methods.
  442. p_theme->set_color("forward_plus_color", EditorStringName(Editor), Color::hex(0x5d8c3fff));
  443. p_theme->set_color("mobile_color", EditorStringName(Editor), Color::hex(0xa5557dff));
  444. p_theme->set_color("gl_compatibility_color", EditorStringName(Editor), Color::hex(0x5586a4ff));
  445. if (p_config.dark_theme) {
  446. p_theme->set_color("highend_color", EditorStringName(Editor), Color(1.0, 0.0, 0.0));
  447. } else {
  448. p_theme->set_color("highend_color", EditorStringName(Editor), Color::hex(0xad1128ff));
  449. }
  450. }
  451. // Constants.
  452. {
  453. // Can't save single float in theme, so using Color.
  454. p_theme->set_color("icon_saturation", EditorStringName(Editor), Color(p_config.icon_saturation, p_config.icon_saturation, p_config.icon_saturation));
  455. // Controls may rely on the scale for their internal drawing logic.
  456. p_theme->set_default_base_scale(EDSCALE);
  457. p_theme->set_constant("scale", EditorStringName(Editor), EDSCALE);
  458. p_theme->set_constant("thumb_size", EditorStringName(Editor), p_config.thumb_size);
  459. p_theme->set_constant("class_icon_size", EditorStringName(Editor), p_config.class_icon_size);
  460. p_theme->set_constant("color_picker_button_height", EditorStringName(Editor), p_config.color_picker_button_height);
  461. p_theme->set_constant("gizmo_handle_scale", EditorStringName(Editor), p_config.gizmo_handle_scale);
  462. p_theme->set_constant("base_margin", EditorStringName(Editor), p_config.base_margin);
  463. p_theme->set_constant("increased_margin", EditorStringName(Editor), p_config.increased_margin);
  464. p_theme->set_constant("window_border_margin", EditorStringName(Editor), p_config.window_border_margin);
  465. p_theme->set_constant("top_bar_separation", EditorStringName(Editor), p_config.top_bar_separation);
  466. p_theme->set_constant("dark_theme", EditorStringName(Editor), p_config.dark_theme);
  467. }
  468. // Styleboxes.
  469. {
  470. // This is the basic stylebox, used as a base for most other styleboxes (through `duplicate()`).
  471. p_config.base_style = make_flat_stylebox(p_config.base_color, p_config.base_margin, p_config.base_margin, p_config.base_margin, p_config.base_margin, p_config.corner_radius);
  472. p_config.base_style->set_border_width_all(p_config.border_width);
  473. p_config.base_style->set_border_color(p_config.base_color);
  474. p_config.base_empty_style = make_empty_stylebox(p_config.base_margin, p_config.base_margin, p_config.base_margin, p_config.base_margin);
  475. // Button styles.
  476. {
  477. p_config.widget_margin = Vector2(p_config.increased_margin + 2, p_config.increased_margin + 1) * EDSCALE;
  478. p_config.button_style = p_config.base_style->duplicate();
  479. p_config.button_style->set_content_margin_individual(p_config.widget_margin.x, p_config.widget_margin.y, p_config.widget_margin.x, p_config.widget_margin.y);
  480. p_config.button_style->set_bg_color(p_config.dark_color_1);
  481. if (p_config.draw_extra_borders) {
  482. p_config.button_style->set_border_width_all(Math::round(EDSCALE));
  483. p_config.button_style->set_border_color(p_config.extra_border_color_1);
  484. } else {
  485. p_config.button_style->set_border_color(p_config.dark_color_2);
  486. }
  487. p_config.button_style_disabled = p_config.button_style->duplicate();
  488. p_config.button_style_disabled->set_bg_color(p_config.disabled_bg_color);
  489. if (p_config.draw_extra_borders) {
  490. p_config.button_style_disabled->set_border_color(p_config.extra_border_color_2);
  491. } else {
  492. p_config.button_style_disabled->set_border_color(p_config.disabled_border_color);
  493. }
  494. p_config.button_style_focus = p_config.button_style->duplicate();
  495. p_config.button_style_focus->set_draw_center(false);
  496. p_config.button_style_focus->set_border_width_all(Math::round(2 * MAX(1, EDSCALE)));
  497. p_config.button_style_focus->set_border_color(p_config.accent_color);
  498. p_config.button_style_pressed = p_config.button_style->duplicate();
  499. p_config.button_style_pressed->set_bg_color(p_config.dark_color_1.darkened(0.125));
  500. p_config.button_style_hover = p_config.button_style->duplicate();
  501. p_config.button_style_hover->set_bg_color(p_config.mono_color * Color(1, 1, 1, 0.11));
  502. if (p_config.draw_extra_borders) {
  503. p_config.button_style_hover->set_border_color(p_config.extra_border_color_1);
  504. } else {
  505. p_config.button_style_hover->set_border_color(p_config.mono_color * Color(1, 1, 1, 0.05));
  506. }
  507. }
  508. // Windows and popups.
  509. {
  510. p_config.popup_style = p_config.base_style->duplicate();
  511. p_config.popup_style->set_content_margin_all(p_config.popup_margin);
  512. p_config.popup_style->set_border_color(p_config.contrast_color_1);
  513. p_config.popup_style->set_shadow_color(p_config.shadow_color);
  514. p_config.popup_style->set_shadow_size(4 * EDSCALE);
  515. // Popups are separate windows by default in the editor. Windows currently don't support per-pixel transparency
  516. // in 4.0, and even if it was, it may not always work in practice (e.g. running with compositing disabled).
  517. p_config.popup_style->set_corner_radius_all(0);
  518. p_config.popup_border_style = p_config.popup_style->duplicate();
  519. p_config.popup_border_style->set_content_margin_all(MAX(Math::round(EDSCALE), p_config.border_width) + 2 + (p_config.base_margin * 1.5) * EDSCALE);
  520. // Always display a border for popups like PopupMenus so they can be distinguished from their background.
  521. p_config.popup_border_style->set_border_width_all(MAX(Math::round(EDSCALE), p_config.border_width));
  522. if (p_config.draw_extra_borders) {
  523. p_config.popup_border_style->set_border_color(p_config.extra_border_color_2);
  524. } else {
  525. p_config.popup_border_style->set_border_color(p_config.dark_color_2);
  526. }
  527. p_config.window_style = p_config.popup_style->duplicate();
  528. p_config.window_style->set_border_color(p_config.base_color);
  529. p_config.window_style->set_border_width(SIDE_TOP, 24 * EDSCALE);
  530. p_config.window_style->set_expand_margin(SIDE_TOP, 24 * EDSCALE);
  531. // Prevent corner artifacts between window title and body.
  532. p_config.dialog_style = p_config.base_style->duplicate();
  533. p_config.dialog_style->set_corner_radius(CORNER_TOP_LEFT, 0);
  534. p_config.dialog_style->set_corner_radius(CORNER_TOP_RIGHT, 0);
  535. p_config.dialog_style->set_content_margin_all(p_config.popup_margin);
  536. // Prevent visible line between window title and body.
  537. p_config.dialog_style->set_expand_margin(SIDE_BOTTOM, 2 * EDSCALE);
  538. }
  539. // Panels.
  540. {
  541. p_config.panel_container_style = p_config.button_style->duplicate();
  542. p_config.panel_container_style->set_draw_center(false);
  543. p_config.panel_container_style->set_border_width_all(0);
  544. // Content panel for tabs and similar containers.
  545. // Compensate for the border.
  546. const int content_panel_margin = p_config.base_margin * EDSCALE + p_config.border_width;
  547. p_config.content_panel_style = p_config.base_style->duplicate();
  548. p_config.content_panel_style->set_border_color(p_config.dark_color_3);
  549. p_config.content_panel_style->set_border_width_all(p_config.border_width);
  550. p_config.content_panel_style->set_border_width(Side::SIDE_TOP, 0);
  551. p_config.content_panel_style->set_corner_radius(CORNER_TOP_LEFT, 0);
  552. p_config.content_panel_style->set_corner_radius(CORNER_TOP_RIGHT, 0);
  553. p_config.content_panel_style->set_content_margin_individual(content_panel_margin, 2 * EDSCALE + content_panel_margin, content_panel_margin, content_panel_margin);
  554. // Trees and similarly inset panels.
  555. p_config.tree_panel_style = p_config.base_style->duplicate();
  556. // Make Trees easier to distinguish from other controls by using a darker background color.
  557. p_config.tree_panel_style->set_bg_color(p_config.dark_color_1.lerp(p_config.dark_color_2, 0.5));
  558. if (p_config.draw_extra_borders) {
  559. p_config.tree_panel_style->set_border_width_all(Math::round(EDSCALE));
  560. p_config.tree_panel_style->set_border_color(p_config.extra_border_color_2);
  561. } else {
  562. p_config.tree_panel_style->set_border_color(p_config.dark_color_3);
  563. }
  564. }
  565. }
  566. }
  567. void EditorThemeManager::_populate_standard_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config) {
  568. // Panels.
  569. {
  570. // Panel.
  571. p_theme->set_stylebox(SceneStringName(panel), "Panel", make_flat_stylebox(p_config.dark_color_1, 6, 4, 6, 4, p_config.corner_radius));
  572. // PanelContainer.
  573. p_theme->set_stylebox(SceneStringName(panel), "PanelContainer", p_config.panel_container_style);
  574. // TooltipPanel & TooltipLabel.
  575. {
  576. // TooltipPanel is also used for custom tooltips, while TooltipLabel
  577. // is only relevant for default tooltips.
  578. p_theme->set_color(SceneStringName(font_color), "TooltipLabel", p_config.font_hover_color);
  579. p_theme->set_color("font_shadow_color", "TooltipLabel", Color(0, 0, 0, 0));
  580. Ref<StyleBoxFlat> style_tooltip = p_config.popup_style->duplicate();
  581. style_tooltip->set_shadow_size(0);
  582. style_tooltip->set_content_margin_all(p_config.base_margin * EDSCALE * 0.5);
  583. style_tooltip->set_bg_color(p_config.dark_color_3 * Color(0.8, 0.8, 0.8, 0.9));
  584. style_tooltip->set_border_width_all(0);
  585. p_theme->set_stylebox(SceneStringName(panel), "TooltipPanel", style_tooltip);
  586. }
  587. // PopupPanel
  588. p_theme->set_stylebox(SceneStringName(panel), "PopupPanel", p_config.popup_border_style);
  589. }
  590. // Buttons.
  591. {
  592. // Button.
  593. p_theme->set_stylebox(CoreStringName(normal), "Button", p_config.button_style);
  594. p_theme->set_stylebox(SceneStringName(hover), "Button", p_config.button_style_hover);
  595. p_theme->set_stylebox(SceneStringName(pressed), "Button", p_config.button_style_pressed);
  596. p_theme->set_stylebox("focus", "Button", p_config.button_style_focus);
  597. p_theme->set_stylebox("disabled", "Button", p_config.button_style_disabled);
  598. p_theme->set_color(SceneStringName(font_color), "Button", p_config.font_color);
  599. p_theme->set_color("font_hover_color", "Button", p_config.font_hover_color);
  600. p_theme->set_color("font_hover_pressed_color", "Button", p_config.font_hover_pressed_color);
  601. p_theme->set_color("font_focus_color", "Button", p_config.font_focus_color);
  602. p_theme->set_color("font_pressed_color", "Button", p_config.font_pressed_color);
  603. p_theme->set_color("font_disabled_color", "Button", p_config.font_disabled_color);
  604. p_theme->set_color("font_outline_color", "Button", p_config.font_outline_color);
  605. p_theme->set_color("icon_normal_color", "Button", p_config.icon_normal_color);
  606. p_theme->set_color("icon_hover_color", "Button", p_config.icon_hover_color);
  607. p_theme->set_color("icon_focus_color", "Button", p_config.icon_focus_color);
  608. p_theme->set_color("icon_hover_pressed_color", "Button", p_config.icon_pressed_color);
  609. p_theme->set_color("icon_pressed_color", "Button", p_config.icon_pressed_color);
  610. p_theme->set_color("icon_disabled_color", "Button", p_config.icon_disabled_color);
  611. p_theme->set_constant("h_separation", "Button", 4 * EDSCALE);
  612. p_theme->set_constant("outline_size", "Button", 0);
  613. p_theme->set_constant("align_to_largest_stylebox", "Button", 1); // Enabled.
  614. // MenuButton.
  615. p_theme->set_stylebox(CoreStringName(normal), "MenuButton", p_config.panel_container_style);
  616. p_theme->set_stylebox(SceneStringName(hover), "MenuButton", p_config.button_style_hover);
  617. p_theme->set_stylebox(SceneStringName(pressed), "MenuButton", p_config.panel_container_style);
  618. p_theme->set_stylebox("focus", "MenuButton", p_config.panel_container_style);
  619. p_theme->set_stylebox("disabled", "MenuButton", p_config.panel_container_style);
  620. p_theme->set_color(SceneStringName(font_color), "MenuButton", p_config.font_color);
  621. p_theme->set_color("font_hover_color", "MenuButton", p_config.font_hover_color);
  622. p_theme->set_color("font_hover_pressed_color", "MenuButton", p_config.font_hover_pressed_color);
  623. p_theme->set_color("font_focus_color", "MenuButton", p_config.font_focus_color);
  624. p_theme->set_color("font_outline_color", "MenuButton", p_config.font_outline_color);
  625. p_theme->set_constant("outline_size", "MenuButton", 0);
  626. // MenuBar.
  627. p_theme->set_stylebox(CoreStringName(normal), "MenuBar", p_config.button_style);
  628. p_theme->set_stylebox(SceneStringName(hover), "MenuBar", p_config.button_style_hover);
  629. p_theme->set_stylebox(SceneStringName(pressed), "MenuBar", p_config.button_style_pressed);
  630. p_theme->set_stylebox("disabled", "MenuBar", p_config.button_style_disabled);
  631. p_theme->set_color(SceneStringName(font_color), "MenuBar", p_config.font_color);
  632. p_theme->set_color("font_hover_color", "MenuBar", p_config.font_hover_color);
  633. p_theme->set_color("font_hover_pressed_color", "MenuBar", p_config.font_hover_pressed_color);
  634. p_theme->set_color("font_focus_color", "MenuBar", p_config.font_focus_color);
  635. p_theme->set_color("font_pressed_color", "MenuBar", p_config.font_pressed_color);
  636. p_theme->set_color("font_disabled_color", "MenuBar", p_config.font_disabled_color);
  637. p_theme->set_color("font_outline_color", "MenuBar", p_config.font_outline_color);
  638. p_theme->set_color("icon_normal_color", "MenuBar", p_config.icon_normal_color);
  639. p_theme->set_color("icon_hover_color", "MenuBar", p_config.icon_hover_color);
  640. p_theme->set_color("icon_focus_color", "MenuBar", p_config.icon_focus_color);
  641. p_theme->set_color("icon_pressed_color", "MenuBar", p_config.icon_pressed_color);
  642. p_theme->set_color("icon_disabled_color", "MenuBar", p_config.icon_disabled_color);
  643. p_theme->set_constant("h_separation", "MenuBar", 4 * EDSCALE);
  644. p_theme->set_constant("outline_size", "MenuBar", 0);
  645. // OptionButton.
  646. {
  647. Ref<StyleBoxFlat> option_button_focus_style = p_config.button_style_focus->duplicate();
  648. Ref<StyleBoxFlat> option_button_normal_style = p_config.button_style->duplicate();
  649. Ref<StyleBoxFlat> option_button_hover_style = p_config.button_style_hover->duplicate();
  650. Ref<StyleBoxFlat> option_button_pressed_style = p_config.button_style_pressed->duplicate();
  651. Ref<StyleBoxFlat> option_button_disabled_style = p_config.button_style_disabled->duplicate();
  652. option_button_focus_style->set_content_margin(SIDE_RIGHT, 4 * EDSCALE);
  653. option_button_normal_style->set_content_margin(SIDE_RIGHT, 4 * EDSCALE);
  654. option_button_hover_style->set_content_margin(SIDE_RIGHT, 4 * EDSCALE);
  655. option_button_pressed_style->set_content_margin(SIDE_RIGHT, 4 * EDSCALE);
  656. option_button_disabled_style->set_content_margin(SIDE_RIGHT, 4 * EDSCALE);
  657. p_theme->set_stylebox("focus", "OptionButton", option_button_focus_style);
  658. p_theme->set_stylebox(CoreStringName(normal), "OptionButton", p_config.button_style);
  659. p_theme->set_stylebox(SceneStringName(hover), "OptionButton", p_config.button_style_hover);
  660. p_theme->set_stylebox(SceneStringName(pressed), "OptionButton", p_config.button_style_pressed);
  661. p_theme->set_stylebox("disabled", "OptionButton", p_config.button_style_disabled);
  662. p_theme->set_stylebox("normal_mirrored", "OptionButton", option_button_normal_style);
  663. p_theme->set_stylebox("hover_mirrored", "OptionButton", option_button_hover_style);
  664. p_theme->set_stylebox("pressed_mirrored", "OptionButton", option_button_pressed_style);
  665. p_theme->set_stylebox("disabled_mirrored", "OptionButton", option_button_disabled_style);
  666. p_theme->set_color(SceneStringName(font_color), "OptionButton", p_config.font_color);
  667. p_theme->set_color("font_hover_color", "OptionButton", p_config.font_hover_color);
  668. p_theme->set_color("font_hover_pressed_color", "OptionButton", p_config.font_hover_pressed_color);
  669. p_theme->set_color("font_focus_color", "OptionButton", p_config.font_focus_color);
  670. p_theme->set_color("font_pressed_color", "OptionButton", p_config.font_pressed_color);
  671. p_theme->set_color("font_disabled_color", "OptionButton", p_config.font_disabled_color);
  672. p_theme->set_color("font_outline_color", "OptionButton", p_config.font_outline_color);
  673. p_theme->set_color("icon_normal_color", "OptionButton", p_config.icon_normal_color);
  674. p_theme->set_color("icon_hover_color", "OptionButton", p_config.icon_hover_color);
  675. p_theme->set_color("icon_focus_color", "OptionButton", p_config.icon_focus_color);
  676. p_theme->set_color("icon_pressed_color", "OptionButton", p_config.icon_pressed_color);
  677. p_theme->set_color("icon_disabled_color", "OptionButton", p_config.icon_disabled_color);
  678. p_theme->set_icon("arrow", "OptionButton", p_theme->get_icon(SNAME("GuiOptionArrow"), EditorStringName(EditorIcons)));
  679. p_theme->set_constant("arrow_margin", "OptionButton", p_config.widget_margin.x - 2 * EDSCALE);
  680. p_theme->set_constant("modulate_arrow", "OptionButton", true);
  681. p_theme->set_constant("h_separation", "OptionButton", 4 * EDSCALE);
  682. p_theme->set_constant("outline_size", "OptionButton", 0);
  683. }
  684. // CheckButton.
  685. p_theme->set_stylebox(CoreStringName(normal), "CheckButton", p_config.panel_container_style);
  686. p_theme->set_stylebox(SceneStringName(pressed), "CheckButton", p_config.panel_container_style);
  687. p_theme->set_stylebox("disabled", "CheckButton", p_config.panel_container_style);
  688. p_theme->set_stylebox(SceneStringName(hover), "CheckButton", p_config.panel_container_style);
  689. p_theme->set_stylebox("hover_pressed", "CheckButton", p_config.panel_container_style);
  690. p_theme->set_icon("checked", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOn"), EditorStringName(EditorIcons)));
  691. p_theme->set_icon("checked_disabled", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOnDisabled"), EditorStringName(EditorIcons)));
  692. p_theme->set_icon("unchecked", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOff"), EditorStringName(EditorIcons)));
  693. p_theme->set_icon("unchecked_disabled", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOffDisabled"), EditorStringName(EditorIcons)));
  694. p_theme->set_icon("checked_mirrored", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOnMirrored"), EditorStringName(EditorIcons)));
  695. p_theme->set_icon("checked_disabled_mirrored", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOnDisabledMirrored"), EditorStringName(EditorIcons)));
  696. p_theme->set_icon("unchecked_mirrored", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOffMirrored"), EditorStringName(EditorIcons)));
  697. p_theme->set_icon("unchecked_disabled_mirrored", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOffDisabledMirrored"), EditorStringName(EditorIcons)));
  698. p_theme->set_color(SceneStringName(font_color), "CheckButton", p_config.font_color);
  699. p_theme->set_color("font_hover_color", "CheckButton", p_config.font_hover_color);
  700. p_theme->set_color("font_hover_pressed_color", "CheckButton", p_config.font_hover_pressed_color);
  701. p_theme->set_color("font_focus_color", "CheckButton", p_config.font_focus_color);
  702. p_theme->set_color("font_pressed_color", "CheckButton", p_config.font_pressed_color);
  703. p_theme->set_color("font_disabled_color", "CheckButton", p_config.font_disabled_color);
  704. p_theme->set_color("font_outline_color", "CheckButton", p_config.font_outline_color);
  705. p_theme->set_color("icon_normal_color", "CheckButton", p_config.icon_normal_color);
  706. p_theme->set_color("icon_hover_color", "CheckButton", p_config.icon_hover_color);
  707. p_theme->set_color("icon_focus_color", "CheckButton", p_config.icon_focus_color);
  708. p_theme->set_color("icon_pressed_color", "CheckButton", p_config.icon_pressed_color);
  709. p_theme->set_color("icon_disabled_color", "CheckButton", p_config.icon_disabled_color);
  710. p_theme->set_constant("h_separation", "CheckButton", 8 * EDSCALE);
  711. p_theme->set_constant("check_v_offset", "CheckButton", 0);
  712. p_theme->set_constant("outline_size", "CheckButton", 0);
  713. // CheckBox.
  714. {
  715. Ref<StyleBoxFlat> checkbox_style = p_config.panel_container_style->duplicate();
  716. p_theme->set_stylebox(CoreStringName(normal), "CheckBox", checkbox_style);
  717. p_theme->set_stylebox(SceneStringName(pressed), "CheckBox", checkbox_style);
  718. p_theme->set_stylebox("disabled", "CheckBox", checkbox_style);
  719. p_theme->set_stylebox(SceneStringName(hover), "CheckBox", checkbox_style);
  720. p_theme->set_stylebox("hover_pressed", "CheckBox", checkbox_style);
  721. p_theme->set_icon("checked", "CheckBox", p_theme->get_icon(SNAME("GuiChecked"), EditorStringName(EditorIcons)));
  722. p_theme->set_icon("unchecked", "CheckBox", p_theme->get_icon(SNAME("GuiUnchecked"), EditorStringName(EditorIcons)));
  723. p_theme->set_icon("radio_checked", "CheckBox", p_theme->get_icon(SNAME("GuiRadioChecked"), EditorStringName(EditorIcons)));
  724. p_theme->set_icon("radio_unchecked", "CheckBox", p_theme->get_icon(SNAME("GuiRadioUnchecked"), EditorStringName(EditorIcons)));
  725. p_theme->set_icon("checked_disabled", "CheckBox", p_theme->get_icon(SNAME("GuiCheckedDisabled"), EditorStringName(EditorIcons)));
  726. p_theme->set_icon("unchecked_disabled", "CheckBox", p_theme->get_icon(SNAME("GuiUncheckedDisabled"), EditorStringName(EditorIcons)));
  727. p_theme->set_icon("radio_checked_disabled", "CheckBox", p_theme->get_icon(SNAME("GuiRadioCheckedDisabled"), EditorStringName(EditorIcons)));
  728. p_theme->set_icon("radio_unchecked_disabled", "CheckBox", p_theme->get_icon(SNAME("GuiRadioUncheckedDisabled"), EditorStringName(EditorIcons)));
  729. p_theme->set_color(SceneStringName(font_color), "CheckBox", p_config.font_color);
  730. p_theme->set_color("font_hover_color", "CheckBox", p_config.font_hover_color);
  731. p_theme->set_color("font_hover_pressed_color", "CheckBox", p_config.font_hover_pressed_color);
  732. p_theme->set_color("font_focus_color", "CheckBox", p_config.font_focus_color);
  733. p_theme->set_color("font_pressed_color", "CheckBox", p_config.font_pressed_color);
  734. p_theme->set_color("font_disabled_color", "CheckBox", p_config.font_disabled_color);
  735. p_theme->set_color("font_outline_color", "CheckBox", p_config.font_outline_color);
  736. p_theme->set_color("icon_normal_color", "CheckBox", p_config.icon_normal_color);
  737. p_theme->set_color("icon_hover_color", "CheckBox", p_config.icon_hover_color);
  738. p_theme->set_color("icon_focus_color", "CheckBox", p_config.icon_focus_color);
  739. p_theme->set_color("icon_pressed_color", "CheckBox", p_config.icon_pressed_color);
  740. p_theme->set_color("icon_disabled_color", "CheckBox", p_config.icon_disabled_color);
  741. p_theme->set_constant("h_separation", "CheckBox", 8 * EDSCALE);
  742. p_theme->set_constant("check_v_offset", "CheckBox", 0);
  743. p_theme->set_constant("outline_size", "CheckBox", 0);
  744. }
  745. // LinkButton.
  746. p_theme->set_stylebox("focus", "LinkButton", p_config.base_empty_style);
  747. p_theme->set_color(SceneStringName(font_color), "LinkButton", p_config.font_color);
  748. p_theme->set_color("font_hover_color", "LinkButton", p_config.font_hover_color);
  749. p_theme->set_color("font_hover_pressed_color", "LinkButton", p_config.font_hover_pressed_color);
  750. p_theme->set_color("font_focus_color", "LinkButton", p_config.font_focus_color);
  751. p_theme->set_color("font_pressed_color", "LinkButton", p_config.font_pressed_color);
  752. p_theme->set_color("font_disabled_color", "LinkButton", p_config.font_disabled_color);
  753. p_theme->set_color("font_outline_color", "LinkButton", p_config.font_outline_color);
  754. p_theme->set_constant("outline_size", "LinkButton", 0);
  755. }
  756. // Tree & ItemList.
  757. {
  758. Ref<StyleBoxFlat> style_tree_focus = p_config.base_style->duplicate();
  759. style_tree_focus->set_bg_color(p_config.highlight_color);
  760. style_tree_focus->set_border_width_all(0);
  761. Ref<StyleBoxFlat> style_tree_selected = style_tree_focus->duplicate();
  762. const Color guide_color = p_config.mono_color * Color(1, 1, 1, 0.05);
  763. // Tree.
  764. {
  765. p_theme->set_icon("checked", "Tree", p_theme->get_icon(SNAME("GuiChecked"), EditorStringName(EditorIcons)));
  766. p_theme->set_icon("checked_disabled", "Tree", p_theme->get_icon(SNAME("GuiCheckedDisabled"), EditorStringName(EditorIcons)));
  767. p_theme->set_icon("indeterminate", "Tree", p_theme->get_icon(SNAME("GuiIndeterminate"), EditorStringName(EditorIcons)));
  768. p_theme->set_icon("indeterminate_disabled", "Tree", p_theme->get_icon(SNAME("GuiIndeterminateDisabled"), EditorStringName(EditorIcons)));
  769. p_theme->set_icon("unchecked", "Tree", p_theme->get_icon(SNAME("GuiUnchecked"), EditorStringName(EditorIcons)));
  770. p_theme->set_icon("unchecked_disabled", "Tree", p_theme->get_icon(SNAME("GuiUncheckedDisabled"), EditorStringName(EditorIcons)));
  771. p_theme->set_icon("arrow", "Tree", p_theme->get_icon(SNAME("GuiTreeArrowDown"), EditorStringName(EditorIcons)));
  772. p_theme->set_icon("arrow_collapsed", "Tree", p_theme->get_icon(SNAME("GuiTreeArrowRight"), EditorStringName(EditorIcons)));
  773. p_theme->set_icon("arrow_collapsed_mirrored", "Tree", p_theme->get_icon(SNAME("GuiTreeArrowLeft"), EditorStringName(EditorIcons)));
  774. p_theme->set_icon("updown", "Tree", p_theme->get_icon(SNAME("GuiTreeUpdown"), EditorStringName(EditorIcons)));
  775. p_theme->set_icon("select_arrow", "Tree", p_theme->get_icon(SNAME("GuiDropdown"), EditorStringName(EditorIcons)));
  776. p_theme->set_stylebox(SceneStringName(panel), "Tree", p_config.tree_panel_style);
  777. p_theme->set_stylebox("focus", "Tree", p_config.button_style_focus);
  778. p_theme->set_stylebox("custom_button", "Tree", make_empty_stylebox());
  779. p_theme->set_stylebox("custom_button_pressed", "Tree", make_empty_stylebox());
  780. p_theme->set_stylebox("custom_button_hover", "Tree", p_config.button_style);
  781. p_theme->set_color("custom_button_font_highlight", "Tree", p_config.font_hover_color);
  782. p_theme->set_color(SceneStringName(font_color), "Tree", p_config.font_color);
  783. p_theme->set_color("font_hovered_color", "Tree", p_config.mono_color);
  784. p_theme->set_color("font_hovered_dimmed_color", "Tree", p_config.font_color);
  785. p_theme->set_color("font_selected_color", "Tree", p_config.mono_color);
  786. p_theme->set_color("font_disabled_color", "Tree", p_config.font_disabled_color);
  787. p_theme->set_color("font_outline_color", "Tree", p_config.font_outline_color);
  788. p_theme->set_color("title_button_color", "Tree", p_config.font_color);
  789. p_theme->set_color("drop_position_color", "Tree", p_config.accent_color);
  790. p_theme->set_constant("v_separation", "Tree", p_config.separation_margin);
  791. p_theme->set_constant("h_separation", "Tree", (p_config.increased_margin + 2) * EDSCALE);
  792. p_theme->set_constant("guide_width", "Tree", p_config.border_width);
  793. p_theme->set_constant("item_margin", "Tree", 3 * p_config.increased_margin * EDSCALE);
  794. p_theme->set_constant("inner_item_margin_top", "Tree", p_config.separation_margin);
  795. p_theme->set_constant("inner_item_margin_bottom", "Tree", p_config.separation_margin);
  796. p_theme->set_constant("inner_item_margin_left", "Tree", p_config.increased_margin * EDSCALE);
  797. p_theme->set_constant("inner_item_margin_right", "Tree", p_config.increased_margin * EDSCALE);
  798. p_theme->set_constant("button_margin", "Tree", p_config.base_margin * EDSCALE);
  799. p_theme->set_constant("scroll_border", "Tree", 40 * EDSCALE);
  800. p_theme->set_constant("scroll_speed", "Tree", 12);
  801. p_theme->set_constant("outline_size", "Tree", 0);
  802. p_theme->set_constant("scrollbar_margin_left", "Tree", 0);
  803. p_theme->set_constant("scrollbar_margin_top", "Tree", 0);
  804. p_theme->set_constant("scrollbar_margin_right", "Tree", 0);
  805. p_theme->set_constant("scrollbar_margin_bottom", "Tree", 0);
  806. p_theme->set_constant("scrollbar_h_separation", "Tree", 1 * EDSCALE);
  807. p_theme->set_constant("scrollbar_v_separation", "Tree", 1 * EDSCALE);
  808. Color relationship_line_color = p_config.mono_color * Color(1, 1, 1, p_config.relationship_line_opacity);
  809. p_theme->set_constant("draw_guides", "Tree", p_config.relationship_line_opacity < 0.01);
  810. p_theme->set_color("guide_color", "Tree", guide_color);
  811. int relationship_line_width = 1;
  812. Color parent_line_color = p_config.mono_color * Color(1, 1, 1, CLAMP(p_config.relationship_line_opacity + 0.45, 0.0, 1.0));
  813. Color children_line_color = p_config.mono_color * Color(1, 1, 1, CLAMP(p_config.relationship_line_opacity + 0.25, 0.0, 1.0));
  814. p_theme->set_constant("draw_relationship_lines", "Tree", p_config.relationship_line_opacity >= 0.01);
  815. p_theme->set_constant("relationship_line_width", "Tree", relationship_line_width);
  816. p_theme->set_constant("parent_hl_line_width", "Tree", relationship_line_width * 2);
  817. p_theme->set_constant("children_hl_line_width", "Tree", relationship_line_width);
  818. p_theme->set_constant("parent_hl_line_margin", "Tree", relationship_line_width * 3);
  819. p_theme->set_color("relationship_line_color", "Tree", relationship_line_color);
  820. p_theme->set_color("parent_hl_line_color", "Tree", parent_line_color);
  821. p_theme->set_color("children_hl_line_color", "Tree", children_line_color);
  822. p_theme->set_color("drop_position_color", "Tree", p_config.accent_color);
  823. Ref<StyleBoxFlat> style_tree_btn = p_config.base_style->duplicate();
  824. style_tree_btn->set_bg_color(p_config.highlight_color);
  825. style_tree_btn->set_border_width_all(0);
  826. p_theme->set_stylebox("button_pressed", "Tree", style_tree_btn);
  827. Ref<StyleBoxFlat> style_tree_hover = p_config.base_style->duplicate();
  828. style_tree_hover->set_bg_color(p_config.highlight_color * Color(1, 1, 1, 0.4));
  829. style_tree_hover->set_border_width_all(0);
  830. p_theme->set_stylebox("hovered", "Tree", style_tree_hover);
  831. p_theme->set_stylebox("button_hover", "Tree", style_tree_hover);
  832. Ref<StyleBoxFlat> style_tree_hover_dimmed = p_config.base_style->duplicate();
  833. style_tree_hover_dimmed->set_bg_color(p_config.highlight_color * Color(1, 1, 1, 0.2));
  834. style_tree_hover_dimmed->set_border_width_all(0);
  835. p_theme->set_stylebox("hovered_dimmed", "Tree", style_tree_hover_dimmed);
  836. p_theme->set_stylebox("selected_focus", "Tree", style_tree_focus);
  837. p_theme->set_stylebox("selected", "Tree", style_tree_selected);
  838. Ref<StyleBoxFlat> style_tree_cursor = p_config.base_style->duplicate();
  839. style_tree_cursor->set_draw_center(false);
  840. style_tree_cursor->set_border_width_all(MAX(1, p_config.border_width));
  841. style_tree_cursor->set_border_color(p_config.contrast_color_1);
  842. Ref<StyleBoxFlat> style_tree_title = p_config.base_style->duplicate();
  843. style_tree_title->set_bg_color(p_config.dark_color_3);
  844. style_tree_title->set_border_width_all(0);
  845. p_theme->set_stylebox("cursor", "Tree", style_tree_cursor);
  846. p_theme->set_stylebox("cursor_unfocused", "Tree", style_tree_cursor);
  847. p_theme->set_stylebox("title_button_normal", "Tree", style_tree_title);
  848. p_theme->set_stylebox("title_button_hover", "Tree", style_tree_title);
  849. p_theme->set_stylebox("title_button_pressed", "Tree", style_tree_title);
  850. }
  851. // ItemList.
  852. {
  853. Ref<StyleBoxFlat> style_itemlist_bg = p_config.base_style->duplicate();
  854. style_itemlist_bg->set_content_margin_all(p_config.separation_margin);
  855. style_itemlist_bg->set_bg_color(p_config.dark_color_1);
  856. if (p_config.draw_extra_borders) {
  857. style_itemlist_bg->set_border_width_all(Math::round(EDSCALE));
  858. style_itemlist_bg->set_border_color(p_config.extra_border_color_2);
  859. } else {
  860. style_itemlist_bg->set_border_width_all(p_config.border_width);
  861. style_itemlist_bg->set_border_color(p_config.dark_color_3);
  862. }
  863. Ref<StyleBoxFlat> style_itemlist_cursor = p_config.base_style->duplicate();
  864. style_itemlist_cursor->set_draw_center(false);
  865. style_itemlist_cursor->set_border_width_all(p_config.border_width);
  866. style_itemlist_cursor->set_border_color(p_config.highlight_color);
  867. Ref<StyleBoxFlat> style_itemlist_hover = style_tree_selected->duplicate();
  868. style_itemlist_hover->set_bg_color(p_config.highlight_color * Color(1, 1, 1, 0.3));
  869. style_itemlist_hover->set_border_width_all(0);
  870. p_theme->set_stylebox(SceneStringName(panel), "ItemList", style_itemlist_bg);
  871. p_theme->set_stylebox("focus", "ItemList", p_config.button_style_focus);
  872. p_theme->set_stylebox("cursor", "ItemList", style_itemlist_cursor);
  873. p_theme->set_stylebox("cursor_unfocused", "ItemList", style_itemlist_cursor);
  874. p_theme->set_stylebox("selected_focus", "ItemList", style_tree_focus);
  875. p_theme->set_stylebox("selected", "ItemList", style_tree_selected);
  876. p_theme->set_stylebox("hovered", "ItemList", style_itemlist_hover);
  877. p_theme->set_color(SceneStringName(font_color), "ItemList", p_config.font_color);
  878. p_theme->set_color("font_hovered_color", "ItemList", p_config.mono_color);
  879. p_theme->set_color("font_selected_color", "ItemList", p_config.mono_color);
  880. p_theme->set_color("font_outline_color", "ItemList", p_config.font_outline_color);
  881. p_theme->set_color("guide_color", "ItemList", Color(1, 1, 1, 0));
  882. p_theme->set_constant("v_separation", "ItemList", p_config.forced_even_separation * EDSCALE);
  883. p_theme->set_constant("h_separation", "ItemList", (p_config.increased_margin + 2) * EDSCALE);
  884. p_theme->set_constant("icon_margin", "ItemList", (p_config.increased_margin + 2) * EDSCALE);
  885. p_theme->set_constant(SceneStringName(line_separation), "ItemList", p_config.separation_margin);
  886. p_theme->set_constant("outline_size", "ItemList", 0);
  887. }
  888. }
  889. // TabBar & TabContainer.
  890. {
  891. Ref<StyleBoxFlat> style_tab_base = p_config.button_style->duplicate();
  892. style_tab_base->set_border_width_all(0);
  893. // Don't round the top corners to avoid creating a small blank space between the tabs and the main panel.
  894. // This also makes the top highlight look better.
  895. style_tab_base->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
  896. style_tab_base->set_corner_radius(CORNER_BOTTOM_RIGHT, 0);
  897. // When using a border width greater than 0, visually line up the left of the selected tab with the underlying panel.
  898. style_tab_base->set_expand_margin(SIDE_LEFT, -p_config.border_width);
  899. style_tab_base->set_content_margin(SIDE_LEFT, p_config.widget_margin.x + 5 * EDSCALE);
  900. style_tab_base->set_content_margin(SIDE_RIGHT, p_config.widget_margin.x + 5 * EDSCALE);
  901. style_tab_base->set_content_margin(SIDE_BOTTOM, p_config.widget_margin.y);
  902. style_tab_base->set_content_margin(SIDE_TOP, p_config.widget_margin.y);
  903. Ref<StyleBoxFlat> style_tab_selected = style_tab_base->duplicate();
  904. style_tab_selected->set_bg_color(p_config.base_color);
  905. // Add a highlight line at the top of the selected tab.
  906. style_tab_selected->set_border_width(SIDE_TOP, Math::round(2 * EDSCALE));
  907. // Make the highlight line prominent, but not too prominent as to not be distracting.
  908. Color tab_highlight = p_config.dark_color_2.lerp(p_config.accent_color, 0.75);
  909. style_tab_selected->set_border_color(tab_highlight);
  910. style_tab_selected->set_corner_radius_all(0);
  911. Ref<StyleBoxFlat> style_tab_hovered = style_tab_base->duplicate();
  912. style_tab_hovered->set_bg_color(p_config.dark_color_1.lerp(p_config.base_color, 0.4));
  913. // Hovered tab has a subtle highlight between normal and selected states.
  914. style_tab_hovered->set_corner_radius_all(0);
  915. Ref<StyleBoxFlat> style_tab_unselected = style_tab_base->duplicate();
  916. style_tab_unselected->set_expand_margin(SIDE_BOTTOM, 0);
  917. style_tab_unselected->set_bg_color(p_config.dark_color_1);
  918. // Add some spacing between unselected tabs to make them easier to distinguish from each other
  919. style_tab_unselected->set_border_color(Color(0, 0, 0, 0));
  920. Ref<StyleBoxFlat> style_tab_disabled = style_tab_base->duplicate();
  921. style_tab_disabled->set_expand_margin(SIDE_BOTTOM, 0);
  922. style_tab_disabled->set_bg_color(p_config.disabled_bg_color);
  923. style_tab_disabled->set_border_color(p_config.disabled_bg_color);
  924. Ref<StyleBoxFlat> style_tab_focus = p_config.button_style_focus->duplicate();
  925. Ref<StyleBoxFlat> style_tabbar_background = make_flat_stylebox(p_config.dark_color_1, 0, 0, 0, 0, p_config.corner_radius * EDSCALE);
  926. style_tabbar_background->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
  927. style_tabbar_background->set_corner_radius(CORNER_BOTTOM_RIGHT, 0);
  928. p_theme->set_stylebox("tabbar_background", "TabContainer", style_tabbar_background);
  929. p_theme->set_stylebox(SceneStringName(panel), "TabContainer", p_config.content_panel_style);
  930. p_theme->set_stylebox("tab_selected", "TabContainer", style_tab_selected);
  931. p_theme->set_stylebox("tab_hovered", "TabContainer", style_tab_hovered);
  932. p_theme->set_stylebox("tab_unselected", "TabContainer", style_tab_unselected);
  933. p_theme->set_stylebox("tab_disabled", "TabContainer", style_tab_disabled);
  934. p_theme->set_stylebox("tab_focus", "TabContainer", style_tab_focus);
  935. p_theme->set_stylebox("tab_selected", "TabBar", style_tab_selected);
  936. p_theme->set_stylebox("tab_hovered", "TabBar", style_tab_hovered);
  937. p_theme->set_stylebox("tab_unselected", "TabBar", style_tab_unselected);
  938. p_theme->set_stylebox("tab_disabled", "TabBar", style_tab_disabled);
  939. p_theme->set_stylebox("tab_focus", "TabBar", style_tab_focus);
  940. p_theme->set_stylebox("button_pressed", "TabBar", p_config.panel_container_style);
  941. p_theme->set_stylebox("button_highlight", "TabBar", p_config.panel_container_style);
  942. p_theme->set_color("font_selected_color", "TabContainer", p_config.font_color);
  943. p_theme->set_color("font_hovered_color", "TabContainer", p_config.font_color);
  944. p_theme->set_color("font_unselected_color", "TabContainer", p_config.font_disabled_color);
  945. p_theme->set_color("font_outline_color", "TabContainer", p_config.font_outline_color);
  946. p_theme->set_color("font_selected_color", "TabBar", p_config.font_color);
  947. p_theme->set_color("font_hovered_color", "TabBar", p_config.font_color);
  948. p_theme->set_color("font_unselected_color", "TabBar", p_config.font_disabled_color);
  949. p_theme->set_color("font_outline_color", "TabBar", p_config.font_outline_color);
  950. p_theme->set_color("drop_mark_color", "TabContainer", tab_highlight);
  951. p_theme->set_color("drop_mark_color", "TabBar", tab_highlight);
  952. p_theme->set_icon("menu", "TabContainer", p_theme->get_icon(SNAME("GuiTabMenu"), EditorStringName(EditorIcons)));
  953. p_theme->set_icon("menu_highlight", "TabContainer", p_theme->get_icon(SNAME("GuiTabMenuHl"), EditorStringName(EditorIcons)));
  954. p_theme->set_icon("close", "TabBar", p_theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons)));
  955. p_theme->set_icon("increment", "TabContainer", p_theme->get_icon(SNAME("GuiScrollArrowRight"), EditorStringName(EditorIcons)));
  956. p_theme->set_icon("decrement", "TabContainer", p_theme->get_icon(SNAME("GuiScrollArrowLeft"), EditorStringName(EditorIcons)));
  957. p_theme->set_icon("increment", "TabBar", p_theme->get_icon(SNAME("GuiScrollArrowRight"), EditorStringName(EditorIcons)));
  958. p_theme->set_icon("decrement", "TabBar", p_theme->get_icon(SNAME("GuiScrollArrowLeft"), EditorStringName(EditorIcons)));
  959. p_theme->set_icon("increment_highlight", "TabBar", p_theme->get_icon(SNAME("GuiScrollArrowRightHl"), EditorStringName(EditorIcons)));
  960. p_theme->set_icon("decrement_highlight", "TabBar", p_theme->get_icon(SNAME("GuiScrollArrowLeftHl"), EditorStringName(EditorIcons)));
  961. p_theme->set_icon("increment_highlight", "TabContainer", p_theme->get_icon(SNAME("GuiScrollArrowRightHl"), EditorStringName(EditorIcons)));
  962. p_theme->set_icon("decrement_highlight", "TabContainer", p_theme->get_icon(SNAME("GuiScrollArrowLeftHl"), EditorStringName(EditorIcons)));
  963. p_theme->set_icon("drop_mark", "TabContainer", p_theme->get_icon(SNAME("GuiTabDropMark"), EditorStringName(EditorIcons)));
  964. p_theme->set_icon("drop_mark", "TabBar", p_theme->get_icon(SNAME("GuiTabDropMark"), EditorStringName(EditorIcons)));
  965. p_theme->set_constant("side_margin", "TabContainer", 0);
  966. p_theme->set_constant("outline_size", "TabContainer", 0);
  967. p_theme->set_constant("h_separation", "TabBar", 4 * EDSCALE);
  968. p_theme->set_constant("outline_size", "TabBar", 0);
  969. }
  970. // Separators.
  971. p_theme->set_stylebox("separator", "HSeparator", make_line_stylebox(p_config.separator_color, MAX(Math::round(EDSCALE), p_config.border_width)));
  972. p_theme->set_stylebox("separator", "VSeparator", make_line_stylebox(p_config.separator_color, MAX(Math::round(EDSCALE), p_config.border_width), 0, 0, true));
  973. // LineEdit & TextEdit.
  974. {
  975. Ref<StyleBoxFlat> text_editor_style = p_config.button_style->duplicate();
  976. // Don't round the bottom corners to make the line look sharper.
  977. text_editor_style->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
  978. text_editor_style->set_corner_radius(CORNER_BOTTOM_RIGHT, 0);
  979. if (p_config.draw_extra_borders) {
  980. text_editor_style->set_border_width_all(Math::round(EDSCALE));
  981. text_editor_style->set_border_color(p_config.extra_border_color_1);
  982. } else {
  983. // Add a bottom line to make LineEdits more visible, especially in sectioned inspectors
  984. // such as the Project Settings.
  985. text_editor_style->set_border_width(SIDE_BOTTOM, Math::round(2 * EDSCALE));
  986. text_editor_style->set_border_color(p_config.dark_color_2);
  987. }
  988. Ref<StyleBoxFlat> text_editor_disabled_style = text_editor_style->duplicate();
  989. text_editor_disabled_style->set_border_color(p_config.disabled_border_color);
  990. text_editor_disabled_style->set_bg_color(p_config.disabled_bg_color);
  991. // LineEdit.
  992. p_theme->set_stylebox(CoreStringName(normal), "LineEdit", text_editor_style);
  993. p_theme->set_stylebox("focus", "LineEdit", p_config.button_style_focus);
  994. p_theme->set_stylebox("read_only", "LineEdit", text_editor_disabled_style);
  995. p_theme->set_icon("clear", "LineEdit", p_theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons)));
  996. p_theme->set_color(SceneStringName(font_color), "LineEdit", p_config.font_color);
  997. p_theme->set_color("font_selected_color", "LineEdit", p_config.mono_color);
  998. p_theme->set_color("font_uneditable_color", "LineEdit", p_config.font_readonly_color);
  999. p_theme->set_color("font_placeholder_color", "LineEdit", p_config.font_placeholder_color);
  1000. p_theme->set_color("font_outline_color", "LineEdit", p_config.font_outline_color);
  1001. p_theme->set_color("caret_color", "LineEdit", p_config.font_color);
  1002. p_theme->set_color("selection_color", "LineEdit", p_config.selection_color);
  1003. p_theme->set_color("clear_button_color", "LineEdit", p_config.font_color);
  1004. p_theme->set_color("clear_button_color_pressed", "LineEdit", p_config.accent_color);
  1005. p_theme->set_constant("minimum_character_width", "LineEdit", 4);
  1006. p_theme->set_constant("outline_size", "LineEdit", 0);
  1007. p_theme->set_constant("caret_width", "LineEdit", 1);
  1008. // TextEdit.
  1009. p_theme->set_stylebox(CoreStringName(normal), "TextEdit", text_editor_style);
  1010. p_theme->set_stylebox("focus", "TextEdit", p_config.button_style_focus);
  1011. p_theme->set_stylebox("read_only", "TextEdit", text_editor_disabled_style);
  1012. p_theme->set_icon("tab", "TextEdit", p_theme->get_icon(SNAME("GuiTab"), EditorStringName(EditorIcons)));
  1013. p_theme->set_icon("space", "TextEdit", p_theme->get_icon(SNAME("GuiSpace"), EditorStringName(EditorIcons)));
  1014. p_theme->set_color(SceneStringName(font_color), "TextEdit", p_config.font_color);
  1015. p_theme->set_color("font_readonly_color", "TextEdit", p_config.font_readonly_color);
  1016. p_theme->set_color("font_placeholder_color", "TextEdit", p_config.font_placeholder_color);
  1017. p_theme->set_color("font_outline_color", "TextEdit", p_config.font_outline_color);
  1018. p_theme->set_color("caret_color", "TextEdit", p_config.font_color);
  1019. p_theme->set_color("selection_color", "TextEdit", p_config.selection_color);
  1020. p_theme->set_color("background_color", "TextEdit", Color(0, 0, 0, 0));
  1021. p_theme->set_constant("line_spacing", "TextEdit", 4 * EDSCALE);
  1022. p_theme->set_constant("outline_size", "TextEdit", 0);
  1023. p_theme->set_constant("caret_width", "TextEdit", 1);
  1024. }
  1025. // Containers.
  1026. {
  1027. p_theme->set_constant("separation", "BoxContainer", p_config.separation_margin);
  1028. p_theme->set_constant("separation", "HBoxContainer", p_config.separation_margin);
  1029. p_theme->set_constant("separation", "VBoxContainer", p_config.separation_margin);
  1030. p_theme->set_constant("margin_left", "MarginContainer", 0);
  1031. p_theme->set_constant("margin_top", "MarginContainer", 0);
  1032. p_theme->set_constant("margin_right", "MarginContainer", 0);
  1033. p_theme->set_constant("margin_bottom", "MarginContainer", 0);
  1034. p_theme->set_constant("h_separation", "GridContainer", p_config.separation_margin);
  1035. p_theme->set_constant("v_separation", "GridContainer", p_config.separation_margin);
  1036. p_theme->set_constant("h_separation", "FlowContainer", p_config.separation_margin);
  1037. p_theme->set_constant("v_separation", "FlowContainer", p_config.separation_margin);
  1038. p_theme->set_constant("h_separation", "HFlowContainer", p_config.separation_margin);
  1039. p_theme->set_constant("v_separation", "HFlowContainer", p_config.separation_margin);
  1040. p_theme->set_constant("h_separation", "VFlowContainer", p_config.separation_margin);
  1041. p_theme->set_constant("v_separation", "VFlowContainer", p_config.separation_margin);
  1042. // SplitContainer.
  1043. p_theme->set_icon("h_grabber", "SplitContainer", p_theme->get_icon(SNAME("GuiHsplitter"), EditorStringName(EditorIcons)));
  1044. p_theme->set_icon("v_grabber", "SplitContainer", p_theme->get_icon(SNAME("GuiVsplitter"), EditorStringName(EditorIcons)));
  1045. p_theme->set_icon("grabber", "VSplitContainer", p_theme->get_icon(SNAME("GuiVsplitter"), EditorStringName(EditorIcons)));
  1046. p_theme->set_icon("grabber", "HSplitContainer", p_theme->get_icon(SNAME("GuiHsplitter"), EditorStringName(EditorIcons)));
  1047. p_theme->set_constant("separation", "SplitContainer", p_config.separation_margin);
  1048. p_theme->set_constant("separation", "HSplitContainer", p_config.separation_margin);
  1049. p_theme->set_constant("separation", "VSplitContainer", p_config.separation_margin);
  1050. p_theme->set_constant("minimum_grab_thickness", "SplitContainer", p_config.increased_margin * EDSCALE);
  1051. p_theme->set_constant("minimum_grab_thickness", "HSplitContainer", p_config.increased_margin * EDSCALE);
  1052. p_theme->set_constant("minimum_grab_thickness", "VSplitContainer", p_config.increased_margin * EDSCALE);
  1053. // GridContainer.
  1054. p_theme->set_constant("v_separation", "GridContainer", Math::round(p_config.widget_margin.y - 2 * EDSCALE));
  1055. }
  1056. // Window and dialogs.
  1057. {
  1058. // Window.
  1059. p_theme->set_stylebox("embedded_border", "Window", p_config.window_style);
  1060. p_theme->set_stylebox("embedded_unfocused_border", "Window", p_config.window_style);
  1061. p_theme->set_color("title_color", "Window", p_config.font_color);
  1062. p_theme->set_icon("close", "Window", p_theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons)));
  1063. p_theme->set_icon("close_pressed", "Window", p_theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons)));
  1064. p_theme->set_constant("close_h_offset", "Window", 22 * EDSCALE);
  1065. p_theme->set_constant("close_v_offset", "Window", 20 * EDSCALE);
  1066. p_theme->set_constant("title_height", "Window", 24 * EDSCALE);
  1067. p_theme->set_constant("resize_margin", "Window", 4 * EDSCALE);
  1068. p_theme->set_font("title_font", "Window", p_theme->get_font(SNAME("title"), EditorStringName(EditorFonts)));
  1069. p_theme->set_font_size("title_font_size", "Window", p_theme->get_font_size(SNAME("title_size"), EditorStringName(EditorFonts)));
  1070. // AcceptDialog.
  1071. p_theme->set_stylebox(SceneStringName(panel), "AcceptDialog", p_config.dialog_style);
  1072. p_theme->set_constant("buttons_separation", "AcceptDialog", 8 * EDSCALE);
  1073. // Make buttons with short texts such as "OK" easier to click/tap.
  1074. p_theme->set_constant("buttons_min_width", "AcceptDialog", p_config.dialogs_buttons_min_size.x * EDSCALE);
  1075. p_theme->set_constant("buttons_min_height", "AcceptDialog", p_config.dialogs_buttons_min_size.y * EDSCALE);
  1076. // FileDialog.
  1077. p_theme->set_icon("folder", "FileDialog", p_theme->get_icon(SNAME("Folder"), EditorStringName(EditorIcons)));
  1078. p_theme->set_icon("parent_folder", "FileDialog", p_theme->get_icon(SNAME("ArrowUp"), EditorStringName(EditorIcons)));
  1079. p_theme->set_icon("back_folder", "FileDialog", p_theme->get_icon(SNAME("Back"), EditorStringName(EditorIcons)));
  1080. p_theme->set_icon("forward_folder", "FileDialog", p_theme->get_icon(SNAME("Forward"), EditorStringName(EditorIcons)));
  1081. p_theme->set_icon("reload", "FileDialog", p_theme->get_icon(SNAME("Reload"), EditorStringName(EditorIcons)));
  1082. p_theme->set_icon("toggle_hidden", "FileDialog", p_theme->get_icon(SNAME("GuiVisibilityVisible"), EditorStringName(EditorIcons)));
  1083. p_theme->set_icon("create_folder", "FileDialog", p_theme->get_icon(SNAME("FolderCreate"), EditorStringName(EditorIcons)));
  1084. // Use a different color for folder icons to make them easier to distinguish from files.
  1085. // On a light theme, the icon will be dark, so we need to lighten it before blending it with the accent color.
  1086. p_theme->set_color("folder_icon_color", "FileDialog", (p_config.dark_theme ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25)).lerp(p_config.accent_color, 0.7));
  1087. p_theme->set_color("file_disabled_color", "FileDialog", p_config.font_disabled_color);
  1088. // PopupDialog.
  1089. p_theme->set_stylebox(SceneStringName(panel), "PopupDialog", p_config.popup_style);
  1090. // PopupMenu.
  1091. {
  1092. Ref<StyleBoxFlat> style_popup_menu = p_config.popup_border_style->duplicate();
  1093. // Use 1 pixel for the sides, since if 0 is used, the highlight of hovered items is drawn
  1094. // on top of the popup border. This causes a 'gap' in the panel border when an item is highlighted,
  1095. // and it looks weird. 1px solves this.
  1096. style_popup_menu->set_content_margin_individual(Math::round(EDSCALE), 2 * EDSCALE, Math::round(EDSCALE), 2 * EDSCALE);
  1097. p_theme->set_stylebox(SceneStringName(panel), "PopupMenu", style_popup_menu);
  1098. Ref<StyleBoxFlat> style_menu_hover = p_config.button_style_hover->duplicate();
  1099. // Don't use rounded corners for hover highlights since the StyleBox touches the PopupMenu's edges.
  1100. style_menu_hover->set_corner_radius_all(0);
  1101. p_theme->set_stylebox(SceneStringName(hover), "PopupMenu", style_menu_hover);
  1102. Ref<StyleBoxLine> style_popup_separator(memnew(StyleBoxLine));
  1103. style_popup_separator->set_color(p_config.separator_color);
  1104. style_popup_separator->set_grow_begin(Math::round(EDSCALE) - MAX(Math::round(EDSCALE), p_config.border_width));
  1105. style_popup_separator->set_grow_end(Math::round(EDSCALE) - MAX(Math::round(EDSCALE), p_config.border_width));
  1106. style_popup_separator->set_thickness(MAX(Math::round(EDSCALE), p_config.border_width));
  1107. Ref<StyleBoxLine> style_popup_labeled_separator_left(memnew(StyleBoxLine));
  1108. style_popup_labeled_separator_left->set_grow_begin(Math::round(EDSCALE) - MAX(Math::round(EDSCALE), p_config.border_width));
  1109. style_popup_labeled_separator_left->set_color(p_config.separator_color);
  1110. style_popup_labeled_separator_left->set_thickness(MAX(Math::round(EDSCALE), p_config.border_width));
  1111. Ref<StyleBoxLine> style_popup_labeled_separator_right(memnew(StyleBoxLine));
  1112. style_popup_labeled_separator_right->set_grow_end(Math::round(EDSCALE) - MAX(Math::round(EDSCALE), p_config.border_width));
  1113. style_popup_labeled_separator_right->set_color(p_config.separator_color);
  1114. style_popup_labeled_separator_right->set_thickness(MAX(Math::round(EDSCALE), p_config.border_width));
  1115. p_theme->set_stylebox("separator", "PopupMenu", style_popup_separator);
  1116. p_theme->set_stylebox("labeled_separator_left", "PopupMenu", style_popup_labeled_separator_left);
  1117. p_theme->set_stylebox("labeled_separator_right", "PopupMenu", style_popup_labeled_separator_right);
  1118. p_theme->set_color(SceneStringName(font_color), "PopupMenu", p_config.font_color);
  1119. p_theme->set_color("font_hover_color", "PopupMenu", p_config.font_hover_color);
  1120. p_theme->set_color("font_accelerator_color", "PopupMenu", p_config.font_disabled_color);
  1121. p_theme->set_color("font_disabled_color", "PopupMenu", p_config.font_disabled_color);
  1122. p_theme->set_color("font_separator_color", "PopupMenu", p_config.font_disabled_color);
  1123. p_theme->set_color("font_outline_color", "PopupMenu", p_config.font_outline_color);
  1124. p_theme->set_icon("checked", "PopupMenu", p_theme->get_icon(SNAME("GuiChecked"), EditorStringName(EditorIcons)));
  1125. p_theme->set_icon("unchecked", "PopupMenu", p_theme->get_icon(SNAME("GuiUnchecked"), EditorStringName(EditorIcons)));
  1126. p_theme->set_icon("radio_checked", "PopupMenu", p_theme->get_icon(SNAME("GuiRadioChecked"), EditorStringName(EditorIcons)));
  1127. p_theme->set_icon("radio_unchecked", "PopupMenu", p_theme->get_icon(SNAME("GuiRadioUnchecked"), EditorStringName(EditorIcons)));
  1128. p_theme->set_icon("checked_disabled", "PopupMenu", p_theme->get_icon(SNAME("GuiCheckedDisabled"), EditorStringName(EditorIcons)));
  1129. p_theme->set_icon("unchecked_disabled", "PopupMenu", p_theme->get_icon(SNAME("GuiUncheckedDisabled"), EditorStringName(EditorIcons)));
  1130. p_theme->set_icon("radio_checked_disabled", "PopupMenu", p_theme->get_icon(SNAME("GuiRadioCheckedDisabled"), EditorStringName(EditorIcons)));
  1131. p_theme->set_icon("radio_unchecked_disabled", "PopupMenu", p_theme->get_icon(SNAME("GuiRadioUncheckedDisabled"), EditorStringName(EditorIcons)));
  1132. p_theme->set_icon("submenu", "PopupMenu", p_theme->get_icon(SNAME("ArrowRight"), EditorStringName(EditorIcons)));
  1133. p_theme->set_icon("submenu_mirrored", "PopupMenu", p_theme->get_icon(SNAME("ArrowLeft"), EditorStringName(EditorIcons)));
  1134. p_theme->set_icon("visibility_hidden", "PopupMenu", p_theme->get_icon(SNAME("GuiVisibilityHidden"), EditorStringName(EditorIcons)));
  1135. p_theme->set_icon("visibility_visible", "PopupMenu", p_theme->get_icon(SNAME("GuiVisibilityVisible"), EditorStringName(EditorIcons)));
  1136. p_theme->set_icon("visibility_xray", "PopupMenu", p_theme->get_icon(SNAME("GuiVisibilityXray"), EditorStringName(EditorIcons)));
  1137. p_theme->set_constant("v_separation", "PopupMenu", p_config.forced_even_separation * EDSCALE);
  1138. p_theme->set_constant("outline_size", "PopupMenu", 0);
  1139. p_theme->set_constant("item_start_padding", "PopupMenu", p_config.separation_margin);
  1140. p_theme->set_constant("item_end_padding", "PopupMenu", p_config.separation_margin);
  1141. }
  1142. }
  1143. // Sliders and scrollbars.
  1144. {
  1145. Ref<Texture2D> empty_icon = memnew(ImageTexture);
  1146. // HScrollBar.
  1147. if (p_config.increase_scrollbar_touch_area) {
  1148. p_theme->set_stylebox("scroll", "HScrollBar", make_line_stylebox(p_config.separator_color, 50));
  1149. } else {
  1150. p_theme->set_stylebox("scroll", "HScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, -5, 1, -5, 1));
  1151. }
  1152. p_theme->set_stylebox("scroll_focus", "HScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1));
  1153. p_theme->set_stylebox("grabber", "HScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabber"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1));
  1154. p_theme->set_stylebox("grabber_highlight", "HScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabberHl"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1));
  1155. p_theme->set_stylebox("grabber_pressed", "HScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabberPressed"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1));
  1156. p_theme->set_icon("increment", "HScrollBar", empty_icon);
  1157. p_theme->set_icon("increment_highlight", "HScrollBar", empty_icon);
  1158. p_theme->set_icon("increment_pressed", "HScrollBar", empty_icon);
  1159. p_theme->set_icon("decrement", "HScrollBar", empty_icon);
  1160. p_theme->set_icon("decrement_highlight", "HScrollBar", empty_icon);
  1161. p_theme->set_icon("decrement_pressed", "HScrollBar", empty_icon);
  1162. // VScrollBar.
  1163. if (p_config.increase_scrollbar_touch_area) {
  1164. p_theme->set_stylebox("scroll", "VScrollBar", make_line_stylebox(p_config.separator_color, 50, 1, 1, true));
  1165. } else {
  1166. p_theme->set_stylebox("scroll", "VScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, -5, 1, -5));
  1167. }
  1168. p_theme->set_stylebox("scroll_focus", "VScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1));
  1169. p_theme->set_stylebox("grabber", "VScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabber"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1));
  1170. p_theme->set_stylebox("grabber_highlight", "VScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabberHl"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1));
  1171. p_theme->set_stylebox("grabber_pressed", "VScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabberPressed"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1));
  1172. p_theme->set_icon("increment", "VScrollBar", empty_icon);
  1173. p_theme->set_icon("increment_highlight", "VScrollBar", empty_icon);
  1174. p_theme->set_icon("increment_pressed", "VScrollBar", empty_icon);
  1175. p_theme->set_icon("decrement", "VScrollBar", empty_icon);
  1176. p_theme->set_icon("decrement_highlight", "VScrollBar", empty_icon);
  1177. p_theme->set_icon("decrement_pressed", "VScrollBar", empty_icon);
  1178. // Slider
  1179. const int background_margin = MAX(2, p_config.base_margin / 2);
  1180. // HSlider.
  1181. p_theme->set_icon("grabber_highlight", "HSlider", p_theme->get_icon(SNAME("GuiSliderGrabberHl"), EditorStringName(EditorIcons)));
  1182. p_theme->set_icon("grabber", "HSlider", p_theme->get_icon(SNAME("GuiSliderGrabber"), EditorStringName(EditorIcons)));
  1183. p_theme->set_stylebox("slider", "HSlider", make_flat_stylebox(p_config.dark_color_3, 0, background_margin, 0, background_margin, p_config.corner_radius));
  1184. p_theme->set_stylebox("grabber_area", "HSlider", make_flat_stylebox(p_config.contrast_color_1, 0, background_margin, 0, background_margin, p_config.corner_radius));
  1185. p_theme->set_stylebox("grabber_area_highlight", "HSlider", make_flat_stylebox(p_config.contrast_color_1, 0, background_margin, 0, background_margin));
  1186. p_theme->set_constant("center_grabber", "HSlider", 0);
  1187. p_theme->set_constant("grabber_offset", "HSlider", 0);
  1188. // VSlider.
  1189. p_theme->set_icon("grabber", "VSlider", p_theme->get_icon(SNAME("GuiSliderGrabber"), EditorStringName(EditorIcons)));
  1190. p_theme->set_icon("grabber_highlight", "VSlider", p_theme->get_icon(SNAME("GuiSliderGrabberHl"), EditorStringName(EditorIcons)));
  1191. p_theme->set_stylebox("slider", "VSlider", make_flat_stylebox(p_config.dark_color_3, background_margin, 0, background_margin, 0, p_config.corner_radius));
  1192. p_theme->set_stylebox("grabber_area", "VSlider", make_flat_stylebox(p_config.contrast_color_1, background_margin, 0, background_margin, 0, p_config.corner_radius));
  1193. p_theme->set_stylebox("grabber_area_highlight", "VSlider", make_flat_stylebox(p_config.contrast_color_1, background_margin, 0, background_margin, 0));
  1194. p_theme->set_constant("center_grabber", "VSlider", 0);
  1195. p_theme->set_constant("grabber_offset", "VSlider", 0);
  1196. }
  1197. // Labels.
  1198. {
  1199. // RichTextLabel.
  1200. p_theme->set_stylebox(CoreStringName(normal), "RichTextLabel", p_config.tree_panel_style);
  1201. p_theme->set_stylebox("focus", "RichTextLabel", make_empty_stylebox());
  1202. p_theme->set_color("default_color", "RichTextLabel", p_config.font_color);
  1203. p_theme->set_color("font_shadow_color", "RichTextLabel", Color(0, 0, 0, 0));
  1204. p_theme->set_color("font_outline_color", "RichTextLabel", p_config.font_outline_color);
  1205. p_theme->set_color("selection_color", "RichTextLabel", p_config.selection_color);
  1206. p_theme->set_constant("shadow_offset_x", "RichTextLabel", 1 * EDSCALE);
  1207. p_theme->set_constant("shadow_offset_y", "RichTextLabel", 1 * EDSCALE);
  1208. p_theme->set_constant("shadow_outline_size", "RichTextLabel", 1 * EDSCALE);
  1209. p_theme->set_constant("outline_size", "RichTextLabel", 0);
  1210. // Label.
  1211. p_theme->set_stylebox(CoreStringName(normal), "Label", p_config.base_empty_style);
  1212. p_theme->set_color(SceneStringName(font_color), "Label", p_config.font_color);
  1213. p_theme->set_color("font_shadow_color", "Label", Color(0, 0, 0, 0));
  1214. p_theme->set_color("font_outline_color", "Label", p_config.font_outline_color);
  1215. p_theme->set_constant("shadow_offset_x", "Label", 1 * EDSCALE);
  1216. p_theme->set_constant("shadow_offset_y", "Label", 1 * EDSCALE);
  1217. p_theme->set_constant("shadow_outline_size", "Label", 1 * EDSCALE);
  1218. p_theme->set_constant("line_spacing", "Label", 3 * EDSCALE);
  1219. p_theme->set_constant("outline_size", "Label", 0);
  1220. }
  1221. // SpinBox.
  1222. {
  1223. Ref<Texture2D> empty_icon = memnew(ImageTexture);
  1224. p_theme->set_icon("updown", "SpinBox", empty_icon);
  1225. p_theme->set_icon("up", "SpinBox", p_theme->get_icon(SNAME("GuiSpinboxUp"), EditorStringName(EditorIcons)));
  1226. p_theme->set_icon("up_hover", "SpinBox", p_theme->get_icon(SNAME("GuiSpinboxUp"), EditorStringName(EditorIcons)));
  1227. p_theme->set_icon("up_pressed", "SpinBox", p_theme->get_icon(SNAME("GuiSpinboxUp"), EditorStringName(EditorIcons)));
  1228. p_theme->set_icon("up_disabled", "SpinBox", p_theme->get_icon(SNAME("GuiSpinboxUp"), EditorStringName(EditorIcons)));
  1229. p_theme->set_icon("down", "SpinBox", p_theme->get_icon(SNAME("GuiSpinboxDown"), EditorStringName(EditorIcons)));
  1230. p_theme->set_icon("down_hover", "SpinBox", p_theme->get_icon(SNAME("GuiSpinboxDown"), EditorStringName(EditorIcons)));
  1231. p_theme->set_icon("down_pressed", "SpinBox", p_theme->get_icon(SNAME("GuiSpinboxDown"), EditorStringName(EditorIcons)));
  1232. p_theme->set_icon("down_disabled", "SpinBox", p_theme->get_icon(SNAME("GuiSpinboxDown"), EditorStringName(EditorIcons)));
  1233. p_theme->set_stylebox("up_background", "SpinBox", make_empty_stylebox());
  1234. p_theme->set_stylebox("up_background_hovered", "SpinBox", p_config.button_style_hover);
  1235. p_theme->set_stylebox("up_background_pressed", "SpinBox", p_config.button_style_pressed);
  1236. p_theme->set_stylebox("up_background_disabled", "SpinBox", make_empty_stylebox());
  1237. p_theme->set_stylebox("down_background", "SpinBox", make_empty_stylebox());
  1238. p_theme->set_stylebox("down_background_hovered", "SpinBox", p_config.button_style_hover);
  1239. p_theme->set_stylebox("down_background_pressed", "SpinBox", p_config.button_style_pressed);
  1240. p_theme->set_stylebox("down_background_disabled", "SpinBox", make_empty_stylebox());
  1241. p_theme->set_color("up_icon_modulate", "SpinBox", p_config.font_color);
  1242. p_theme->set_color("up_hover_icon_modulate", "SpinBox", p_config.font_hover_color);
  1243. p_theme->set_color("up_pressed_icon_modulate", "SpinBox", p_config.font_pressed_color);
  1244. p_theme->set_color("up_disabled_icon_modulate", "SpinBox", p_config.font_disabled_color);
  1245. p_theme->set_color("down_icon_modulate", "SpinBox", p_config.font_color);
  1246. p_theme->set_color("down_hover_icon_modulate", "SpinBox", p_config.font_hover_color);
  1247. p_theme->set_color("down_pressed_icon_modulate", "SpinBox", p_config.font_pressed_color);
  1248. p_theme->set_color("down_disabled_icon_modulate", "SpinBox", p_config.font_disabled_color);
  1249. p_theme->set_stylebox("field_and_buttons_separator", "SpinBox", make_empty_stylebox());
  1250. p_theme->set_stylebox("up_down_buttons_separator", "SpinBox", make_empty_stylebox());
  1251. p_theme->set_constant("buttons_vertical_separation", "SpinBox", 0);
  1252. p_theme->set_constant("field_and_buttons_separation", "SpinBox", 2);
  1253. p_theme->set_constant("buttons_width", "SpinBox", 16);
  1254. #ifndef DISABLE_DEPRECATED
  1255. p_theme->set_constant("set_min_buttons_width_from_icons", "SpinBox", 1);
  1256. #endif
  1257. }
  1258. // ProgressBar.
  1259. p_theme->set_stylebox("background", "ProgressBar", make_stylebox(p_theme->get_icon(SNAME("GuiProgressBar"), EditorStringName(EditorIcons)), 4, 4, 4, 4, 0, 0, 0, 0));
  1260. p_theme->set_stylebox("fill", "ProgressBar", make_stylebox(p_theme->get_icon(SNAME("GuiProgressFill"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 2, 1, 2, 1));
  1261. p_theme->set_color(SceneStringName(font_color), "ProgressBar", p_config.font_color);
  1262. p_theme->set_color("font_outline_color", "ProgressBar", p_config.font_outline_color);
  1263. p_theme->set_constant("outline_size", "ProgressBar", 0);
  1264. // GraphEdit and related nodes.
  1265. {
  1266. // GraphEdit.
  1267. p_theme->set_stylebox(SceneStringName(panel), "GraphEdit", p_config.tree_panel_style);
  1268. p_theme->set_stylebox("menu_panel", "GraphEdit", make_flat_stylebox(p_config.dark_color_1 * Color(1, 1, 1, 0.6), 4, 2, 4, 2, 3));
  1269. float grid_base_brightness = p_config.dark_theme ? 1.0 : 0.0;
  1270. GraphEdit::GridPattern grid_pattern = (GraphEdit::GridPattern) int(EDITOR_GET("editors/visual_editors/grid_pattern"));
  1271. switch (grid_pattern) {
  1272. case GraphEdit::GRID_PATTERN_LINES:
  1273. p_theme->set_color("grid_major", "GraphEdit", Color(grid_base_brightness, grid_base_brightness, grid_base_brightness, 0.10));
  1274. p_theme->set_color("grid_minor", "GraphEdit", Color(grid_base_brightness, grid_base_brightness, grid_base_brightness, 0.05));
  1275. break;
  1276. case GraphEdit::GRID_PATTERN_DOTS:
  1277. p_theme->set_color("grid_major", "GraphEdit", Color(grid_base_brightness, grid_base_brightness, grid_base_brightness, 0.07));
  1278. p_theme->set_color("grid_minor", "GraphEdit", Color(grid_base_brightness, grid_base_brightness, grid_base_brightness, 0.07));
  1279. break;
  1280. default:
  1281. WARN_PRINT("Unknown grid pattern.");
  1282. break;
  1283. }
  1284. p_theme->set_color("selection_fill", "GraphEdit", p_theme->get_color(SNAME("box_selection_fill_color"), EditorStringName(Editor)));
  1285. p_theme->set_color("selection_stroke", "GraphEdit", p_theme->get_color(SNAME("box_selection_stroke_color"), EditorStringName(Editor)));
  1286. p_theme->set_color("activity", "GraphEdit", p_config.dark_theme ? Color(1, 1, 1) : Color(0, 0, 0));
  1287. p_theme->set_color("connection_hover_tint_color", "GraphEdit", p_config.dark_theme ? Color(0, 0, 0, 0.3) : Color(1, 1, 1, 0.3));
  1288. p_theme->set_color("connection_valid_target_tint_color", "GraphEdit", p_config.dark_theme ? Color(1, 1, 1, 0.4) : Color(0, 0, 0, 0.4));
  1289. p_theme->set_color("connection_rim_color", "GraphEdit", p_config.tree_panel_style->get_bg_color());
  1290. p_theme->set_icon("zoom_out", "GraphEdit", p_theme->get_icon(SNAME("ZoomLess"), EditorStringName(EditorIcons)));
  1291. p_theme->set_icon("zoom_in", "GraphEdit", p_theme->get_icon(SNAME("ZoomMore"), EditorStringName(EditorIcons)));
  1292. p_theme->set_icon("zoom_reset", "GraphEdit", p_theme->get_icon(SNAME("ZoomReset"), EditorStringName(EditorIcons)));
  1293. p_theme->set_icon("grid_toggle", "GraphEdit", p_theme->get_icon(SNAME("GridToggle"), EditorStringName(EditorIcons)));
  1294. p_theme->set_icon("minimap_toggle", "GraphEdit", p_theme->get_icon(SNAME("GridMinimap"), EditorStringName(EditorIcons)));
  1295. p_theme->set_icon("snapping_toggle", "GraphEdit", p_theme->get_icon(SNAME("SnapGrid"), EditorStringName(EditorIcons)));
  1296. p_theme->set_icon("layout", "GraphEdit", p_theme->get_icon(SNAME("GridLayout"), EditorStringName(EditorIcons)));
  1297. // GraphEditMinimap.
  1298. {
  1299. Ref<StyleBoxFlat> style_minimap_bg = make_flat_stylebox(p_config.dark_color_1, 0, 0, 0, 0);
  1300. style_minimap_bg->set_border_color(p_config.dark_color_3);
  1301. style_minimap_bg->set_border_width_all(1);
  1302. p_theme->set_stylebox(SceneStringName(panel), "GraphEditMinimap", style_minimap_bg);
  1303. Ref<StyleBoxFlat> style_minimap_camera;
  1304. Ref<StyleBoxFlat> style_minimap_node;
  1305. if (p_config.dark_theme) {
  1306. style_minimap_camera = make_flat_stylebox(Color(0.65, 0.65, 0.65, 0.2), 0, 0, 0, 0);
  1307. style_minimap_camera->set_border_color(Color(0.65, 0.65, 0.65, 0.45));
  1308. style_minimap_node = make_flat_stylebox(Color(1, 1, 1), 0, 0, 0, 0);
  1309. } else {
  1310. style_minimap_camera = make_flat_stylebox(Color(0.38, 0.38, 0.38, 0.2), 0, 0, 0, 0);
  1311. style_minimap_camera->set_border_color(Color(0.38, 0.38, 0.38, 0.45));
  1312. style_minimap_node = make_flat_stylebox(Color(0, 0, 0), 0, 0, 0, 0);
  1313. }
  1314. style_minimap_camera->set_border_width_all(1);
  1315. style_minimap_node->set_anti_aliased(false);
  1316. p_theme->set_stylebox("camera", "GraphEditMinimap", style_minimap_camera);
  1317. p_theme->set_stylebox("node", "GraphEditMinimap", style_minimap_node);
  1318. const Color minimap_resizer_color = p_config.dark_theme ? Color(1, 1, 1, 0.65) : Color(0, 0, 0, 0.65);
  1319. p_theme->set_icon("resizer", "GraphEditMinimap", p_theme->get_icon(SNAME("GuiResizerTopLeft"), EditorStringName(EditorIcons)));
  1320. p_theme->set_color("resizer_color", "GraphEditMinimap", minimap_resizer_color);
  1321. }
  1322. // GraphElement, GraphNode & GraphFrame.
  1323. {
  1324. const int gn_margin_top = 2;
  1325. const int gn_margin_side = 2;
  1326. const int gn_margin_bottom = 2;
  1327. const int gn_corner_radius = 3;
  1328. const Color gn_bg_color = p_config.dark_theme ? p_config.dark_color_3 : p_config.dark_color_1.lerp(p_config.mono_color, 0.09);
  1329. const Color gn_selected_border_color = p_config.dark_theme ? Color(1, 1, 1) : Color(0, 0, 0);
  1330. const Color gn_frame_bg = gn_bg_color.lerp(p_config.tree_panel_style->get_bg_color(), 0.3);
  1331. const bool high_contrast_borders = p_config.draw_extra_borders && p_config.dark_theme;
  1332. Ref<StyleBoxFlat> gn_panel_style = make_flat_stylebox(gn_frame_bg, gn_margin_side, gn_margin_top, gn_margin_side, gn_margin_bottom, p_config.corner_radius);
  1333. gn_panel_style->set_border_width(SIDE_BOTTOM, 2 * EDSCALE);
  1334. gn_panel_style->set_border_width(SIDE_LEFT, 2 * EDSCALE);
  1335. gn_panel_style->set_border_width(SIDE_RIGHT, 2 * EDSCALE);
  1336. gn_panel_style->set_border_color(high_contrast_borders ? gn_bg_color.lightened(0.2) : gn_bg_color.darkened(0.3));
  1337. gn_panel_style->set_corner_radius_individual(0, 0, gn_corner_radius * EDSCALE, gn_corner_radius * EDSCALE);
  1338. gn_panel_style->set_anti_aliased(true);
  1339. Ref<StyleBoxFlat> gn_panel_selected_style = gn_panel_style->duplicate();
  1340. gn_panel_selected_style->set_bg_color(p_config.dark_theme ? gn_bg_color.lightened(0.15) : gn_bg_color.darkened(0.15));
  1341. gn_panel_selected_style->set_border_width(SIDE_TOP, 0);
  1342. gn_panel_selected_style->set_border_width(SIDE_BOTTOM, 2 * EDSCALE);
  1343. gn_panel_selected_style->set_border_width(SIDE_LEFT, 2 * EDSCALE);
  1344. gn_panel_selected_style->set_border_width(SIDE_RIGHT, 2 * EDSCALE);
  1345. gn_panel_selected_style->set_border_color(gn_selected_border_color);
  1346. const int gn_titlebar_margin_top = 8;
  1347. const int gn_titlebar_margin_side = 12;
  1348. const int gn_titlebar_margin_bottom = 8;
  1349. Ref<StyleBoxFlat> gn_titlebar_style = make_flat_stylebox(gn_bg_color, gn_titlebar_margin_side, gn_titlebar_margin_top, gn_titlebar_margin_side, gn_titlebar_margin_bottom, p_config.corner_radius);
  1350. gn_titlebar_style->set_border_width(SIDE_TOP, 2 * EDSCALE);
  1351. gn_titlebar_style->set_border_width(SIDE_LEFT, 2 * EDSCALE);
  1352. gn_titlebar_style->set_border_width(SIDE_RIGHT, 2 * EDSCALE);
  1353. gn_titlebar_style->set_border_color(high_contrast_borders ? gn_bg_color.lightened(0.2) : gn_bg_color.darkened(0.3));
  1354. gn_titlebar_style->set_expand_margin(SIDE_TOP, 2 * EDSCALE);
  1355. gn_titlebar_style->set_corner_radius_individual(gn_corner_radius * EDSCALE, gn_corner_radius * EDSCALE, 0, 0);
  1356. gn_titlebar_style->set_anti_aliased(true);
  1357. Ref<StyleBoxFlat> gn_titlebar_selected_style = gn_titlebar_style->duplicate();
  1358. gn_titlebar_selected_style->set_border_color(gn_selected_border_color);
  1359. gn_titlebar_selected_style->set_border_width(SIDE_TOP, 2 * EDSCALE);
  1360. gn_titlebar_selected_style->set_border_width(SIDE_LEFT, 2 * EDSCALE);
  1361. gn_titlebar_selected_style->set_border_width(SIDE_RIGHT, 2 * EDSCALE);
  1362. gn_titlebar_selected_style->set_expand_margin(SIDE_TOP, 2 * EDSCALE);
  1363. Color gn_decoration_color = p_config.dark_color_1.inverted();
  1364. // GraphElement.
  1365. p_theme->set_stylebox(SceneStringName(panel), "GraphElement", gn_panel_style);
  1366. p_theme->set_stylebox("panel_selected", "GraphElement", gn_panel_selected_style);
  1367. p_theme->set_stylebox("titlebar", "GraphElement", gn_titlebar_style);
  1368. p_theme->set_stylebox("titlebar_selected", "GraphElement", gn_titlebar_selected_style);
  1369. p_theme->set_color("resizer_color", "GraphElement", gn_decoration_color);
  1370. p_theme->set_icon("resizer", "GraphElement", p_theme->get_icon(SNAME("GuiResizer"), EditorStringName(EditorIcons)));
  1371. // GraphNode.
  1372. Ref<StyleBoxEmpty> gn_slot_style = make_empty_stylebox(12, 0, 12, 0);
  1373. p_theme->set_stylebox(SceneStringName(panel), "GraphNode", gn_panel_style);
  1374. p_theme->set_stylebox("panel_selected", "GraphNode", gn_panel_selected_style);
  1375. p_theme->set_stylebox("titlebar", "GraphNode", gn_titlebar_style);
  1376. p_theme->set_stylebox("titlebar_selected", "GraphNode", gn_titlebar_selected_style);
  1377. p_theme->set_stylebox("slot", "GraphNode", gn_slot_style);
  1378. p_theme->set_color("resizer_color", "GraphNode", gn_decoration_color);
  1379. p_theme->set_constant("port_h_offset", "GraphNode", 1);
  1380. p_theme->set_constant("separation", "GraphNode", 1 * EDSCALE);
  1381. Ref<ImageTexture> port_icon = p_theme->get_icon(SNAME("GuiGraphNodePort"), EditorStringName(EditorIcons));
  1382. // The true size is 24x24 This is necessary for sharp port icons at high zoom levels in GraphEdit (up to ~200%).
  1383. port_icon->set_size_override(Size2(12, 12));
  1384. p_theme->set_icon("port", "GraphNode", port_icon);
  1385. // GraphNode's title Label.
  1386. p_theme->set_type_variation("GraphNodeTitleLabel", "Label");
  1387. p_theme->set_stylebox(CoreStringName(normal), "GraphNodeTitleLabel", make_empty_stylebox(0, 0, 0, 0));
  1388. p_theme->set_color("font_shadow_color", "GraphNodeTitleLabel", p_config.shadow_color);
  1389. p_theme->set_constant("shadow_outline_size", "GraphNodeTitleLabel", 4);
  1390. p_theme->set_constant("shadow_offset_x", "GraphNodeTitleLabel", 0);
  1391. p_theme->set_constant("shadow_offset_y", "GraphNodeTitleLabel", 1);
  1392. p_theme->set_constant("line_spacing", "GraphNodeTitleLabel", 3 * EDSCALE);
  1393. // GraphFrame.
  1394. const int gf_corner_width = 7 * EDSCALE;
  1395. const int gf_border_width = 2 * MAX(1, EDSCALE);
  1396. Ref<StyleBoxFlat> graphframe_sb = make_flat_stylebox(Color(0.0, 0.0, 0.0, 0.2), gn_margin_side, gn_margin_side, gn_margin_side, gn_margin_bottom, gf_corner_width);
  1397. graphframe_sb->set_expand_margin(SIDE_TOP, 38 * EDSCALE);
  1398. graphframe_sb->set_border_width_all(gf_border_width);
  1399. graphframe_sb->set_border_color(high_contrast_borders ? gn_bg_color.lightened(0.2) : gn_bg_color.darkened(0.3));
  1400. graphframe_sb->set_shadow_size(8 * EDSCALE);
  1401. graphframe_sb->set_shadow_color(Color(p_config.shadow_color, p_config.shadow_color.a * 0.25));
  1402. graphframe_sb->set_anti_aliased(true);
  1403. Ref<StyleBoxFlat> graphframe_sb_selected = graphframe_sb->duplicate();
  1404. graphframe_sb_selected->set_border_color(gn_selected_border_color);
  1405. p_theme->set_stylebox(SceneStringName(panel), "GraphFrame", graphframe_sb);
  1406. p_theme->set_stylebox("panel_selected", "GraphFrame", graphframe_sb_selected);
  1407. p_theme->set_stylebox("titlebar", "GraphFrame", make_empty_stylebox(4, 4, 4, 4));
  1408. p_theme->set_stylebox("titlebar_selected", "GraphFrame", make_empty_stylebox(4, 4, 4, 4));
  1409. p_theme->set_color("resizer_color", "GraphFrame", gn_decoration_color);
  1410. // GraphFrame's title Label.
  1411. p_theme->set_type_variation("GraphFrameTitleLabel", "Label");
  1412. p_theme->set_stylebox(CoreStringName(normal), "GraphFrameTitleLabel", memnew(StyleBoxEmpty));
  1413. p_theme->set_font_size(SceneStringName(font_size), "GraphFrameTitleLabel", 22 * EDSCALE);
  1414. p_theme->set_color(SceneStringName(font_color), "GraphFrameTitleLabel", Color(1, 1, 1));
  1415. p_theme->set_color("font_shadow_color", "GraphFrameTitleLabel", Color(0, 0, 0, 0));
  1416. p_theme->set_color("font_outline_color", "GraphFrameTitleLabel", Color(1, 1, 1));
  1417. p_theme->set_constant("shadow_offset_x", "GraphFrameTitleLabel", 1 * EDSCALE);
  1418. p_theme->set_constant("shadow_offset_y", "GraphFrameTitleLabel", 1 * EDSCALE);
  1419. p_theme->set_constant("outline_size", "GraphFrameTitleLabel", 0);
  1420. p_theme->set_constant("shadow_outline_size", "GraphFrameTitleLabel", 1 * EDSCALE);
  1421. p_theme->set_constant("line_spacing", "GraphFrameTitleLabel", 3 * EDSCALE);
  1422. }
  1423. // VisualShader reroute node.
  1424. {
  1425. Ref<StyleBox> vs_reroute_panel_style = make_empty_stylebox();
  1426. Ref<StyleBox> vs_reroute_titlebar_style = vs_reroute_panel_style->duplicate();
  1427. vs_reroute_titlebar_style->set_content_margin_all(16 * EDSCALE);
  1428. p_theme->set_stylebox(SceneStringName(panel), "VSRerouteNode", vs_reroute_panel_style);
  1429. p_theme->set_stylebox("panel_selected", "VSRerouteNode", vs_reroute_panel_style);
  1430. p_theme->set_stylebox("titlebar", "VSRerouteNode", vs_reroute_titlebar_style);
  1431. p_theme->set_stylebox("titlebar_selected", "VSRerouteNode", vs_reroute_titlebar_style);
  1432. p_theme->set_stylebox("slot", "VSRerouteNode", make_empty_stylebox());
  1433. p_theme->set_color("drag_background", "VSRerouteNode", p_config.dark_theme ? Color(0.19, 0.21, 0.24) : Color(0.8, 0.8, 0.8));
  1434. p_theme->set_color("selected_rim_color", "VSRerouteNode", p_config.dark_theme ? Color(1, 1, 1) : Color(0, 0, 0));
  1435. }
  1436. }
  1437. // ColorPicker and related nodes.
  1438. {
  1439. // ColorPicker.
  1440. p_theme->set_constant("margin", "ColorPicker", p_config.base_margin);
  1441. p_theme->set_constant("sv_width", "ColorPicker", 256 * EDSCALE);
  1442. p_theme->set_constant("sv_height", "ColorPicker", 256 * EDSCALE);
  1443. p_theme->set_constant("h_width", "ColorPicker", 30 * EDSCALE);
  1444. p_theme->set_constant("label_width", "ColorPicker", 10 * EDSCALE);
  1445. p_theme->set_constant("center_slider_grabbers", "ColorPicker", 1);
  1446. p_theme->set_icon("screen_picker", "ColorPicker", p_theme->get_icon(SNAME("ColorPick"), EditorStringName(EditorIcons)));
  1447. p_theme->set_icon("shape_circle", "ColorPicker", p_theme->get_icon(SNAME("PickerShapeCircle"), EditorStringName(EditorIcons)));
  1448. p_theme->set_icon("shape_rect", "ColorPicker", p_theme->get_icon(SNAME("PickerShapeRectangle"), EditorStringName(EditorIcons)));
  1449. p_theme->set_icon("shape_rect_wheel", "ColorPicker", p_theme->get_icon(SNAME("PickerShapeRectangleWheel"), EditorStringName(EditorIcons)));
  1450. p_theme->set_icon("add_preset", "ColorPicker", p_theme->get_icon(SNAME("Add"), EditorStringName(EditorIcons)));
  1451. p_theme->set_icon("sample_bg", "ColorPicker", p_theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons)));
  1452. p_theme->set_icon("sample_revert", "ColorPicker", p_theme->get_icon(SNAME("Reload"), EditorStringName(EditorIcons)));
  1453. p_theme->set_icon("overbright_indicator", "ColorPicker", p_theme->get_icon(SNAME("OverbrightIndicator"), EditorStringName(EditorIcons)));
  1454. p_theme->set_icon("bar_arrow", "ColorPicker", p_theme->get_icon(SNAME("ColorPickerBarArrow"), EditorStringName(EditorIcons)));
  1455. p_theme->set_icon("picker_cursor", "ColorPicker", p_theme->get_icon(SNAME("PickerCursor"), EditorStringName(EditorIcons)));
  1456. // ColorPickerButton.
  1457. p_theme->set_icon("bg", "ColorPickerButton", p_theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons)));
  1458. // ColorPresetButton.
  1459. p_theme->set_stylebox("preset_fg", "ColorPresetButton", make_flat_stylebox(Color(1, 1, 1), 2, 2, 2, 2, 2));
  1460. p_theme->set_icon("preset_bg", "ColorPresetButton", p_theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons)));
  1461. p_theme->set_icon("overbright_indicator", "ColorPresetButton", p_theme->get_icon(SNAME("OverbrightIndicator"), EditorStringName(EditorIcons)));
  1462. }
  1463. }
  1464. void EditorThemeManager::_populate_editor_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config) {
  1465. // Project manager.
  1466. {
  1467. p_theme->set_stylebox("project_list", "ProjectManager", p_config.tree_panel_style);
  1468. p_theme->set_constant("sidebar_button_icon_separation", "ProjectManager", int(6 * EDSCALE));
  1469. p_theme->set_icon("browse_folder", "ProjectManager", p_theme->get_icon(SNAME("FolderBrowse"), EditorStringName(EditorIcons)));
  1470. p_theme->set_icon("browse_file", "ProjectManager", p_theme->get_icon(SNAME("FileBrowse"), EditorStringName(EditorIcons)));
  1471. // ProjectTag.
  1472. {
  1473. p_theme->set_type_variation("ProjectTag", "Button");
  1474. Ref<StyleBoxFlat> tag = p_config.button_style->duplicate();
  1475. tag->set_bg_color(p_config.dark_theme ? tag->get_bg_color().lightened(0.2) : tag->get_bg_color().darkened(0.2));
  1476. tag->set_corner_radius(CORNER_TOP_LEFT, 0);
  1477. tag->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
  1478. tag->set_corner_radius(CORNER_TOP_RIGHT, 4);
  1479. tag->set_corner_radius(CORNER_BOTTOM_RIGHT, 4);
  1480. p_theme->set_stylebox(CoreStringName(normal), "ProjectTag", tag);
  1481. tag = p_config.button_style_hover->duplicate();
  1482. tag->set_corner_radius(CORNER_TOP_LEFT, 0);
  1483. tag->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
  1484. tag->set_corner_radius(CORNER_TOP_RIGHT, 4);
  1485. tag->set_corner_radius(CORNER_BOTTOM_RIGHT, 4);
  1486. p_theme->set_stylebox(SceneStringName(hover), "ProjectTag", tag);
  1487. tag = p_config.button_style_pressed->duplicate();
  1488. tag->set_corner_radius(CORNER_TOP_LEFT, 0);
  1489. tag->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
  1490. tag->set_corner_radius(CORNER_TOP_RIGHT, 4);
  1491. tag->set_corner_radius(CORNER_BOTTOM_RIGHT, 4);
  1492. p_theme->set_stylebox(SceneStringName(pressed), "ProjectTag", tag);
  1493. }
  1494. }
  1495. // Editor and main screen.
  1496. {
  1497. // Editor background.
  1498. Color background_color_opaque = p_config.dark_color_2;
  1499. background_color_opaque.a = 1.0;
  1500. p_theme->set_color("background", EditorStringName(Editor), background_color_opaque);
  1501. p_theme->set_stylebox("Background", EditorStringName(EditorStyles), make_flat_stylebox(background_color_opaque, p_config.base_margin, p_config.base_margin, p_config.base_margin, p_config.base_margin));
  1502. Ref<StyleBoxFlat> editor_panel_foreground = p_config.base_style->duplicate();
  1503. editor_panel_foreground->set_corner_radius_all(0);
  1504. p_theme->set_stylebox("PanelForeground", EditorStringName(EditorStyles), editor_panel_foreground);
  1505. // Editor focus.
  1506. p_theme->set_stylebox("Focus", EditorStringName(EditorStyles), p_config.button_style_focus);
  1507. Ref<StyleBoxFlat> style_widget_focus_viewport = p_config.button_style_focus->duplicate();
  1508. // Make the focus outline appear to be flush with the buttons it's focusing, so not draw on top of the content.
  1509. style_widget_focus_viewport->set_expand_margin_all(2);
  1510. // Use a less opaque color to be less distracting for the 2D and 3D editor viewports.
  1511. style_widget_focus_viewport->set_border_color(p_config.accent_color * Color(1, 1, 1, 0.5));
  1512. p_theme->set_stylebox("FocusViewport", EditorStringName(EditorStyles), style_widget_focus_viewport);
  1513. Ref<StyleBoxFlat> style_widget_scroll_container = p_config.button_style_focus->duplicate();
  1514. // Make the focus outline appear to be flush with the buttons it's focusing, so not draw on top of the content.
  1515. style_widget_scroll_container->set_expand_margin_all(4);
  1516. p_theme->set_stylebox("focus", "ScrollContainer", style_widget_scroll_container);
  1517. // This stylebox is used in 3d and 2d viewports (no borders).
  1518. Ref<StyleBoxFlat> style_content_panel_vp = p_config.content_panel_style->duplicate();
  1519. style_content_panel_vp->set_content_margin_individual(p_config.border_width * 2, p_config.base_margin * EDSCALE, p_config.border_width * 2, p_config.border_width * 2);
  1520. p_theme->set_stylebox("Content", EditorStringName(EditorStyles), style_content_panel_vp);
  1521. // 3D/Spatial editor.
  1522. Ref<StyleBoxFlat> style_info_3d_viewport = p_config.base_style->duplicate();
  1523. style_info_3d_viewport->set_bg_color(style_info_3d_viewport->get_bg_color() * Color(1, 1, 1, 0.5));
  1524. style_info_3d_viewport->set_border_width_all(0);
  1525. p_theme->set_stylebox("Information3dViewport", EditorStringName(EditorStyles), style_info_3d_viewport);
  1526. // 2D and 3D contextual toolbar.
  1527. // Use a custom stylebox to make contextual menu items stand out from the rest.
  1528. // This helps with editor usability as contextual menu items change when selecting nodes,
  1529. // even though it may not be immediately obvious at first.
  1530. Ref<StyleBoxFlat> toolbar_stylebox = memnew(StyleBoxFlat);
  1531. toolbar_stylebox->set_bg_color(p_config.accent_color * Color(1, 1, 1, 0.1));
  1532. toolbar_stylebox->set_anti_aliased(false);
  1533. // Add an underline to the StyleBox, but prevent its minimum vertical size from changing.
  1534. toolbar_stylebox->set_border_color(p_config.accent_color);
  1535. toolbar_stylebox->set_border_width(SIDE_BOTTOM, Math::round(2 * EDSCALE));
  1536. toolbar_stylebox->set_content_margin(SIDE_BOTTOM, 0);
  1537. toolbar_stylebox->set_expand_margin_individual(4 * EDSCALE, 2 * EDSCALE, 4 * EDSCALE, 4 * EDSCALE);
  1538. p_theme->set_stylebox("ContextualToolbar", EditorStringName(EditorStyles), toolbar_stylebox);
  1539. // Script editor.
  1540. p_theme->set_stylebox("ScriptEditorPanel", EditorStringName(EditorStyles), make_empty_stylebox(p_config.base_margin, 0, p_config.base_margin, p_config.base_margin));
  1541. p_theme->set_stylebox("ScriptEditorPanelFloating", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0));
  1542. p_theme->set_stylebox("ScriptEditor", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0));
  1543. // Game view.
  1544. p_theme->set_type_variation("GamePanel", "Panel");
  1545. Ref<StyleBoxFlat> game_panel = p_theme->get_stylebox(SceneStringName(panel), SNAME("Panel"))->duplicate();
  1546. game_panel->set_corner_radius_all(0);
  1547. p_theme->set_stylebox(SceneStringName(panel), "GamePanel", game_panel);
  1548. // Main menu.
  1549. Ref<StyleBoxFlat> menu_transparent_style = p_config.button_style->duplicate();
  1550. menu_transparent_style->set_bg_color(Color(1, 1, 1, 0));
  1551. menu_transparent_style->set_border_width_all(0);
  1552. Ref<StyleBoxFlat> main_screen_button_hover = p_config.button_style_hover->duplicate();
  1553. for (int i = 0; i < 4; i++) {
  1554. menu_transparent_style->set_content_margin((Side)i, p_config.button_style->get_content_margin((Side)i));
  1555. main_screen_button_hover->set_content_margin((Side)i, p_config.button_style_hover->get_content_margin((Side)i));
  1556. }
  1557. p_theme->set_stylebox(CoreStringName(normal), "MainScreenButton", menu_transparent_style);
  1558. p_theme->set_stylebox("normal_mirrored", "MainScreenButton", menu_transparent_style);
  1559. p_theme->set_stylebox(SceneStringName(pressed), "MainScreenButton", menu_transparent_style);
  1560. p_theme->set_stylebox("pressed_mirrored", "MainScreenButton", menu_transparent_style);
  1561. p_theme->set_stylebox(SceneStringName(hover), "MainScreenButton", main_screen_button_hover);
  1562. p_theme->set_stylebox("hover_mirrored", "MainScreenButton", main_screen_button_hover);
  1563. p_theme->set_stylebox("hover_pressed", "MainScreenButton", main_screen_button_hover);
  1564. p_theme->set_stylebox("hover_pressed_mirrored", "MainScreenButton", main_screen_button_hover);
  1565. p_theme->set_type_variation("MainMenuBar", "FlatMenuButton");
  1566. p_theme->set_stylebox(CoreStringName(normal), "MainMenuBar", menu_transparent_style);
  1567. p_theme->set_stylebox(SceneStringName(pressed), "MainMenuBar", main_screen_button_hover);
  1568. p_theme->set_stylebox(SceneStringName(hover), "MainMenuBar", main_screen_button_hover);
  1569. p_theme->set_stylebox("hover_pressed", "MainMenuBar", main_screen_button_hover);
  1570. // Run bar.
  1571. p_theme->set_type_variation("RunBarButton", "FlatMenuButton");
  1572. p_theme->set_stylebox("disabled", "RunBarButton", menu_transparent_style);
  1573. p_theme->set_stylebox(SceneStringName(pressed), "RunBarButton", menu_transparent_style);
  1574. // Bottom panel.
  1575. Ref<StyleBoxFlat> style_bottom_panel = p_config.content_panel_style->duplicate();
  1576. style_bottom_panel->set_corner_radius_all(p_config.corner_radius * EDSCALE);
  1577. p_theme->set_stylebox("BottomPanel", EditorStringName(EditorStyles), style_bottom_panel);
  1578. p_theme->set_type_variation("BottomPanelButton", "FlatMenuButton");
  1579. p_theme->set_stylebox(CoreStringName(normal), "BottomPanelButton", menu_transparent_style);
  1580. p_theme->set_stylebox(SceneStringName(pressed), "BottomPanelButton", menu_transparent_style);
  1581. p_theme->set_stylebox("hover_pressed", "BottomPanelButton", main_screen_button_hover);
  1582. p_theme->set_stylebox(SceneStringName(hover), "BottomPanelButton", main_screen_button_hover);
  1583. // Don't tint the icon even when in "pressed" state.
  1584. p_theme->set_color("icon_pressed_color", "BottomPanelButton", Color(1, 1, 1, 1));
  1585. Color icon_hover_color = p_config.icon_normal_color * (p_config.dark_theme ? 1.15 : 1.0);
  1586. icon_hover_color.a = 1.0;
  1587. p_theme->set_color("icon_hover_color", "BottomPanelButton", icon_hover_color);
  1588. p_theme->set_color("icon_hover_pressed_color", "BottomPanelButton", icon_hover_color);
  1589. }
  1590. // Editor GUI widgets.
  1591. {
  1592. // EditorSpinSlider.
  1593. p_theme->set_color("label_color", "EditorSpinSlider", p_config.font_color);
  1594. p_theme->set_color("read_only_label_color", "EditorSpinSlider", p_config.font_readonly_color);
  1595. Ref<StyleBoxFlat> editor_spin_label_bg = p_config.base_style->duplicate();
  1596. editor_spin_label_bg->set_bg_color(p_config.dark_color_3);
  1597. editor_spin_label_bg->set_border_width_all(0);
  1598. p_theme->set_stylebox("label_bg", "EditorSpinSlider", editor_spin_label_bg);
  1599. // TODO Use separate arrows instead like on SpinBox. Planned for a different PR.
  1600. p_theme->set_icon("updown", "EditorSpinSlider", p_theme->get_icon(SNAME("GuiSpinboxUpdown"), EditorStringName(EditorIcons)));
  1601. p_theme->set_icon("updown_disabled", "EditorSpinSlider", p_theme->get_icon(SNAME("GuiSpinboxUpdownDisabled"), EditorStringName(EditorIcons)));
  1602. // Launch Pad and Play buttons.
  1603. Ref<StyleBoxFlat> style_launch_pad = make_flat_stylebox(p_config.dark_color_1, 2 * EDSCALE, 0, 2 * EDSCALE, 0, p_config.corner_radius);
  1604. style_launch_pad->set_corner_radius_all(p_config.corner_radius * EDSCALE);
  1605. p_theme->set_stylebox("LaunchPadNormal", EditorStringName(EditorStyles), style_launch_pad);
  1606. Ref<StyleBoxFlat> style_launch_pad_movie = style_launch_pad->duplicate();
  1607. style_launch_pad_movie->set_bg_color(p_config.accent_color * Color(1, 1, 1, 0.1));
  1608. style_launch_pad_movie->set_border_color(p_config.accent_color);
  1609. style_launch_pad_movie->set_border_width_all(Math::round(2 * EDSCALE));
  1610. p_theme->set_stylebox("LaunchPadMovieMode", EditorStringName(EditorStyles), style_launch_pad_movie);
  1611. p_theme->set_stylebox("MovieWriterButtonNormal", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0));
  1612. Ref<StyleBoxFlat> style_write_movie_button = p_config.button_style_pressed->duplicate();
  1613. style_write_movie_button->set_bg_color(p_config.accent_color);
  1614. style_write_movie_button->set_corner_radius_all(p_config.corner_radius * EDSCALE);
  1615. style_write_movie_button->set_content_margin(SIDE_TOP, 0);
  1616. style_write_movie_button->set_content_margin(SIDE_BOTTOM, 0);
  1617. style_write_movie_button->set_content_margin(SIDE_LEFT, 0);
  1618. style_write_movie_button->set_content_margin(SIDE_RIGHT, 0);
  1619. style_write_movie_button->set_expand_margin(SIDE_RIGHT, 2 * EDSCALE);
  1620. p_theme->set_stylebox("MovieWriterButtonPressed", EditorStringName(EditorStyles), style_write_movie_button);
  1621. // Movie writer button colors.
  1622. p_theme->set_color("movie_writer_icon_normal", EditorStringName(EditorStyles), Color(1, 1, 1, 0.7));
  1623. p_theme->set_color("movie_writer_icon_pressed", EditorStringName(EditorStyles), Color(0, 0, 0, 0.84));
  1624. p_theme->set_color("movie_writer_icon_hover", EditorStringName(EditorStyles), Color(1, 1, 1, 0.9));
  1625. p_theme->set_color("movie_writer_icon_hover_pressed", EditorStringName(EditorStyles), Color(0, 0, 0, 0.84));
  1626. }
  1627. // Standard GUI variations.
  1628. {
  1629. // Custom theme type for MarginContainer with 4px margins.
  1630. p_theme->set_type_variation("MarginContainer4px", "MarginContainer");
  1631. p_theme->set_constant("margin_left", "MarginContainer4px", 4 * EDSCALE);
  1632. p_theme->set_constant("margin_top", "MarginContainer4px", 4 * EDSCALE);
  1633. p_theme->set_constant("margin_right", "MarginContainer4px", 4 * EDSCALE);
  1634. p_theme->set_constant("margin_bottom", "MarginContainer4px", 4 * EDSCALE);
  1635. // Header LinkButton variation.
  1636. p_theme->set_type_variation("HeaderSmallLink", "LinkButton");
  1637. p_theme->set_font(SceneStringName(font), "HeaderSmallLink", p_theme->get_font(SceneStringName(font), SNAME("HeaderSmall")));
  1638. p_theme->set_font_size(SceneStringName(font_size), "HeaderSmallLink", p_theme->get_font_size(SceneStringName(font_size), SNAME("HeaderSmall")));
  1639. // Flat button variations.
  1640. {
  1641. Ref<StyleBoxEmpty> style_flat_button = make_empty_stylebox();
  1642. Ref<StyleBoxFlat> style_flat_button_hover = p_config.button_style_hover->duplicate();
  1643. Ref<StyleBoxFlat> style_flat_button_pressed = p_config.button_style_pressed->duplicate();
  1644. for (int i = 0; i < 4; i++) {
  1645. style_flat_button->set_content_margin((Side)i, p_config.button_style->get_content_margin((Side)i));
  1646. style_flat_button_hover->set_content_margin((Side)i, p_config.button_style->get_content_margin((Side)i));
  1647. style_flat_button_pressed->set_content_margin((Side)i, p_config.button_style->get_content_margin((Side)i));
  1648. }
  1649. Color flat_pressed_color = p_config.dark_color_1.lightened(0.24).lerp(p_config.accent_color, 0.2) * Color(0.8, 0.8, 0.8, 0.85);
  1650. if (p_config.dark_theme) {
  1651. flat_pressed_color = p_config.dark_color_1.lerp(p_config.accent_color, 0.12) * Color(0.6, 0.6, 0.6, 0.85);
  1652. }
  1653. style_flat_button_pressed->set_bg_color(flat_pressed_color);
  1654. p_theme->set_stylebox(CoreStringName(normal), SceneStringName(FlatButton), style_flat_button);
  1655. p_theme->set_stylebox(SceneStringName(hover), SceneStringName(FlatButton), style_flat_button_hover);
  1656. p_theme->set_stylebox(SceneStringName(pressed), SceneStringName(FlatButton), style_flat_button_pressed);
  1657. p_theme->set_stylebox("disabled", SceneStringName(FlatButton), style_flat_button);
  1658. p_theme->set_stylebox(CoreStringName(normal), "FlatMenuButton", style_flat_button);
  1659. p_theme->set_stylebox(SceneStringName(hover), "FlatMenuButton", style_flat_button_hover);
  1660. p_theme->set_stylebox(SceneStringName(pressed), "FlatMenuButton", style_flat_button_pressed);
  1661. p_theme->set_stylebox("disabled", "FlatMenuButton", style_flat_button);
  1662. // Variation for Editor Log filter buttons.
  1663. p_theme->set_type_variation("EditorLogFilterButton", "Button");
  1664. // When pressed, don't tint the icons with the accent color, just leave them normal.
  1665. p_theme->set_color("icon_pressed_color", "EditorLogFilterButton", p_config.icon_normal_color);
  1666. // When unpressed, dim the icons.
  1667. Color icon_normal_color = Color(p_config.icon_normal_color, (p_config.dark_theme ? 0.4 : 0.8));
  1668. p_theme->set_color("icon_normal_color", "EditorLogFilterButton", icon_normal_color);
  1669. Color icon_hover_color = p_config.icon_normal_color * (p_config.dark_theme ? 1.15 : 1.0);
  1670. icon_hover_color.a = 1.0;
  1671. p_theme->set_color("icon_hover_color", "EditorLogFilterButton", icon_hover_color);
  1672. p_theme->set_color("icon_hover_pressed_color", "EditorLogFilterButton", icon_hover_color);
  1673. // When pressed, add a small bottom border to the buttons to better show their active state,
  1674. // similar to active tabs.
  1675. Ref<StyleBoxFlat> editor_log_button_pressed = style_flat_button_pressed->duplicate();
  1676. editor_log_button_pressed->set_border_width(SIDE_BOTTOM, 2 * EDSCALE);
  1677. editor_log_button_pressed->set_border_color(p_config.accent_color);
  1678. if (!p_config.dark_theme) {
  1679. editor_log_button_pressed->set_bg_color(flat_pressed_color.lightened(0.5));
  1680. }
  1681. p_theme->set_stylebox(CoreStringName(normal), "EditorLogFilterButton", style_flat_button);
  1682. p_theme->set_stylebox(SceneStringName(hover), "EditorLogFilterButton", style_flat_button_hover);
  1683. p_theme->set_stylebox(SceneStringName(pressed), "EditorLogFilterButton", editor_log_button_pressed);
  1684. }
  1685. // Buttons styles that stand out against the panel background (e.g. AssetLib).
  1686. {
  1687. p_theme->set_type_variation("PanelBackgroundButton", "Button");
  1688. Ref<StyleBoxFlat> panel_button_style = p_config.button_style->duplicate();
  1689. panel_button_style->set_bg_color(p_config.base_color.lerp(p_config.mono_color, 0.08));
  1690. Ref<StyleBoxFlat> panel_button_style_hover = p_config.button_style_hover->duplicate();
  1691. panel_button_style_hover->set_bg_color(p_config.base_color.lerp(p_config.mono_color, 0.16));
  1692. Ref<StyleBoxFlat> panel_button_style_pressed = p_config.button_style_pressed->duplicate();
  1693. panel_button_style_pressed->set_bg_color(p_config.base_color.lerp(p_config.mono_color, 0.20));
  1694. Ref<StyleBoxFlat> panel_button_style_disabled = p_config.button_style_disabled->duplicate();
  1695. panel_button_style_disabled->set_bg_color(p_config.disabled_bg_color);
  1696. p_theme->set_stylebox(CoreStringName(normal), "PanelBackgroundButton", panel_button_style);
  1697. p_theme->set_stylebox(SceneStringName(hover), "PanelBackgroundButton", panel_button_style_hover);
  1698. p_theme->set_stylebox(SceneStringName(pressed), "PanelBackgroundButton", panel_button_style_pressed);
  1699. p_theme->set_stylebox("disabled", "PanelBackgroundButton", panel_button_style_disabled);
  1700. }
  1701. // Top bar selectors.
  1702. {
  1703. p_theme->set_type_variation("TopBarOptionButton", "OptionButton");
  1704. p_theme->set_font(SceneStringName(font), "TopBarOptionButton", p_theme->get_font(SNAME("bold"), EditorStringName(EditorFonts)));
  1705. p_theme->set_font_size(SceneStringName(font_size), "TopBarOptionButton", p_theme->get_font_size(SNAME("bold_size"), EditorStringName(EditorFonts)));
  1706. }
  1707. // Complex editor windows.
  1708. {
  1709. Ref<StyleBoxFlat> style_complex_window = p_config.window_style->duplicate();
  1710. style_complex_window->set_bg_color(p_config.dark_color_2);
  1711. style_complex_window->set_border_color(p_config.dark_color_2);
  1712. p_theme->set_stylebox(SceneStringName(panel), "EditorSettingsDialog", style_complex_window);
  1713. p_theme->set_stylebox(SceneStringName(panel), "ProjectSettingsEditor", style_complex_window);
  1714. p_theme->set_stylebox(SceneStringName(panel), "EditorAbout", style_complex_window);
  1715. }
  1716. // InspectorActionButton.
  1717. {
  1718. p_theme->set_type_variation("InspectorActionButton", "Button");
  1719. const float action_extra_margin = 32 * EDSCALE;
  1720. p_theme->set_constant("h_separation", "InspectorActionButton", action_extra_margin);
  1721. Color color_inspector_action = p_config.dark_color_1.lerp(p_config.mono_color, 0.12);
  1722. color_inspector_action.a = 0.5;
  1723. Ref<StyleBoxFlat> style_inspector_action = p_config.button_style->duplicate();
  1724. style_inspector_action->set_bg_color(color_inspector_action);
  1725. style_inspector_action->set_content_margin(SIDE_RIGHT, action_extra_margin);
  1726. p_theme->set_stylebox(CoreStringName(normal), "InspectorActionButton", style_inspector_action);
  1727. style_inspector_action = p_config.button_style->duplicate();
  1728. style_inspector_action->set_bg_color(color_inspector_action);
  1729. style_inspector_action->set_content_margin(SIDE_LEFT, action_extra_margin);
  1730. p_theme->set_stylebox("normal_mirrored", "InspectorActionButton", style_inspector_action);
  1731. style_inspector_action = p_config.button_style_hover->duplicate();
  1732. style_inspector_action->set_content_margin(SIDE_RIGHT, action_extra_margin);
  1733. p_theme->set_stylebox(SceneStringName(hover), "InspectorActionButton", style_inspector_action);
  1734. style_inspector_action = p_config.button_style_hover->duplicate();
  1735. style_inspector_action->set_content_margin(SIDE_LEFT, action_extra_margin);
  1736. p_theme->set_stylebox("hover_mirrored", "InspectorActionButton", style_inspector_action);
  1737. style_inspector_action = p_config.button_style_pressed->duplicate();
  1738. style_inspector_action->set_content_margin(SIDE_RIGHT, action_extra_margin);
  1739. p_theme->set_stylebox(SceneStringName(pressed), "InspectorActionButton", style_inspector_action);
  1740. style_inspector_action = p_config.button_style_pressed->duplicate();
  1741. style_inspector_action->set_content_margin(SIDE_LEFT, action_extra_margin);
  1742. p_theme->set_stylebox("pressed_mirrored", "InspectorActionButton", style_inspector_action);
  1743. style_inspector_action = p_config.button_style_disabled->duplicate();
  1744. style_inspector_action->set_content_margin(SIDE_RIGHT, action_extra_margin);
  1745. p_theme->set_stylebox("disabled", "InspectorActionButton", style_inspector_action);
  1746. style_inspector_action = p_config.button_style_disabled->duplicate();
  1747. style_inspector_action->set_content_margin(SIDE_LEFT, action_extra_margin);
  1748. p_theme->set_stylebox("disabled_mirrored", "InspectorActionButton", style_inspector_action);
  1749. }
  1750. // Buttons in material previews.
  1751. {
  1752. const Color dim_light_color = p_config.icon_normal_color.darkened(0.24);
  1753. const Color dim_light_highlighted_color = p_config.icon_normal_color.darkened(0.18);
  1754. Ref<StyleBox> sb_empty_borderless = make_empty_stylebox();
  1755. p_theme->set_type_variation("PreviewLightButton", "Button");
  1756. // When pressed, don't use the accent color tint. When unpressed, dim the icon.
  1757. p_theme->set_color("icon_normal_color", "PreviewLightButton", dim_light_color);
  1758. p_theme->set_color("icon_focus_color", "PreviewLightButton", dim_light_color);
  1759. p_theme->set_color("icon_pressed_color", "PreviewLightButton", p_config.icon_normal_color);
  1760. p_theme->set_color("icon_hover_pressed_color", "PreviewLightButton", p_config.icon_normal_color);
  1761. // Unpressed icon is dim, so use a dim highlight.
  1762. p_theme->set_color("icon_hover_color", "PreviewLightButton", dim_light_highlighted_color);
  1763. p_theme->set_stylebox(CoreStringName(normal), "PreviewLightButton", sb_empty_borderless);
  1764. p_theme->set_stylebox(SceneStringName(hover), "PreviewLightButton", sb_empty_borderless);
  1765. p_theme->set_stylebox("focus", "PreviewLightButton", sb_empty_borderless);
  1766. p_theme->set_stylebox(SceneStringName(pressed), "PreviewLightButton", sb_empty_borderless);
  1767. }
  1768. // TabContainerOdd variation.
  1769. {
  1770. // Can be used on tabs against the base color background (e.g. nested tabs).
  1771. p_theme->set_type_variation("TabContainerOdd", "TabContainer");
  1772. Ref<StyleBoxFlat> style_tab_selected_odd = p_theme->get_stylebox(SNAME("tab_selected"), SNAME("TabContainer"))->duplicate();
  1773. style_tab_selected_odd->set_bg_color(p_config.disabled_bg_color);
  1774. p_theme->set_stylebox("tab_selected", "TabContainerOdd", style_tab_selected_odd);
  1775. Ref<StyleBoxFlat> style_content_panel_odd = p_config.content_panel_style->duplicate();
  1776. style_content_panel_odd->set_bg_color(p_config.disabled_bg_color);
  1777. p_theme->set_stylebox(SceneStringName(panel), "TabContainerOdd", style_content_panel_odd);
  1778. }
  1779. // EditorValidationPanel.
  1780. p_theme->set_stylebox(SceneStringName(panel), "EditorValidationPanel", p_config.tree_panel_style);
  1781. // Secondary trees and item lists.
  1782. p_theme->set_type_variation("TreeSecondary", "Tree");
  1783. p_theme->set_type_variation("ItemListSecondary", "ItemList");
  1784. }
  1785. // Editor inspector.
  1786. {
  1787. // Vertical separation between inspector categories and sections.
  1788. p_theme->set_constant("v_separation", "EditorInspector", 0);
  1789. // EditorProperty.
  1790. Ref<StyleBoxFlat> style_property_bg = p_config.base_style->duplicate();
  1791. style_property_bg->set_bg_color(p_config.highlight_color);
  1792. style_property_bg->set_border_width_all(0);
  1793. Ref<StyleBoxFlat> style_property_child_bg = p_config.base_style->duplicate();
  1794. style_property_child_bg->set_bg_color(p_config.dark_color_2);
  1795. style_property_child_bg->set_border_width_all(0);
  1796. p_theme->set_stylebox("bg", "EditorProperty", memnew(StyleBoxEmpty));
  1797. p_theme->set_stylebox("bg_selected", "EditorProperty", style_property_bg);
  1798. p_theme->set_stylebox("child_bg", "EditorProperty", style_property_child_bg);
  1799. p_theme->set_constant("font_offset", "EditorProperty", 8 * EDSCALE);
  1800. p_theme->set_constant("v_separation", "EditorProperty", p_config.increased_margin * EDSCALE);
  1801. const Color property_color = p_config.font_color.lerp(Color(0.5, 0.5, 0.5), 0.5);
  1802. const Color readonly_color = property_color.lerp(p_config.dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.25);
  1803. const Color readonly_warning_color = p_config.error_color.lerp(p_config.dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.25);
  1804. p_theme->set_color("property_color", "EditorProperty", property_color);
  1805. p_theme->set_color("readonly_color", "EditorProperty", readonly_color);
  1806. p_theme->set_color("warning_color", "EditorProperty", p_config.warning_color);
  1807. p_theme->set_color("readonly_warning_color", "EditorProperty", readonly_warning_color);
  1808. Ref<StyleBoxFlat> style_property_group_note = p_config.base_style->duplicate();
  1809. Color property_group_note_color = p_config.accent_color;
  1810. property_group_note_color.a = 0.1;
  1811. style_property_group_note->set_bg_color(property_group_note_color);
  1812. p_theme->set_stylebox("bg_group_note", "EditorProperty", style_property_group_note);
  1813. // EditorInspectorSection.
  1814. Color inspector_section_color = p_config.font_color.lerp(Color(0.5, 0.5, 0.5), 0.35);
  1815. p_theme->set_color(SceneStringName(font_color), "EditorInspectorSection", inspector_section_color);
  1816. Color inspector_indent_color = p_config.accent_color;
  1817. inspector_indent_color.a = 0.2;
  1818. Ref<StyleBoxFlat> inspector_indent_style = make_flat_stylebox(inspector_indent_color, 2.0 * EDSCALE, 0, 2.0 * EDSCALE, 0);
  1819. p_theme->set_stylebox("indent_box", "EditorInspectorSection", inspector_indent_style);
  1820. p_theme->set_constant("indent_size", "EditorInspectorSection", 6.0 * EDSCALE);
  1821. p_theme->set_constant("h_separation", "EditorInspectorSection", 2.0 * EDSCALE);
  1822. Color prop_category_color = p_config.dark_color_1.lerp(p_config.mono_color, 0.12);
  1823. Color prop_section_color = p_config.dark_color_1.lerp(p_config.mono_color, 0.09);
  1824. Color prop_subsection_color = p_config.dark_color_1.lerp(p_config.mono_color, 0.06);
  1825. p_theme->set_color("prop_category", EditorStringName(Editor), prop_category_color);
  1826. p_theme->set_color("prop_section", EditorStringName(Editor), prop_section_color);
  1827. p_theme->set_color("prop_subsection", EditorStringName(Editor), prop_subsection_color);
  1828. #ifndef DISABLE_DEPRECATED // Used before 4.3.
  1829. p_theme->set_color("property_color", EditorStringName(Editor), prop_category_color);
  1830. #endif
  1831. // EditorInspectorCategory.
  1832. Ref<StyleBoxFlat> category_bg = p_config.base_style->duplicate();
  1833. category_bg->set_bg_color(prop_category_color);
  1834. category_bg->set_border_color(prop_category_color);
  1835. category_bg->set_content_margin_all(0);
  1836. p_theme->set_stylebox("bg", "EditorInspectorCategory", category_bg);
  1837. p_theme->set_constant("inspector_margin", EditorStringName(Editor), 12 * EDSCALE);
  1838. // Colored EditorProperty.
  1839. for (int i = 0; i < 16; i++) {
  1840. Color si_base_color = p_config.accent_color;
  1841. float hue_rotate = (i * 2 % 16) / 16.0;
  1842. si_base_color.set_hsv(Math::fmod(float(si_base_color.get_h() + hue_rotate), float(1.0)), si_base_color.get_s(), si_base_color.get_v());
  1843. si_base_color = p_config.accent_color.lerp(si_base_color, p_config.subresource_hue_tint);
  1844. // Sub-inspector background.
  1845. Ref<StyleBoxFlat> sub_inspector_bg = p_config.base_style->duplicate();
  1846. sub_inspector_bg->set_bg_color(p_config.dark_color_1.lerp(si_base_color, 0.08));
  1847. sub_inspector_bg->set_border_width_all(2 * EDSCALE);
  1848. sub_inspector_bg->set_border_color(si_base_color * Color(0.7, 0.7, 0.7, 0.8));
  1849. sub_inspector_bg->set_content_margin_all(4 * EDSCALE);
  1850. sub_inspector_bg->set_corner_radius(CORNER_TOP_LEFT, 0);
  1851. sub_inspector_bg->set_corner_radius(CORNER_TOP_RIGHT, 0);
  1852. p_theme->set_stylebox("sub_inspector_bg" + itos(i + 1), EditorStringName(EditorStyles), sub_inspector_bg);
  1853. // EditorProperty background while it has a sub-inspector open.
  1854. Ref<StyleBoxFlat> bg_color = make_flat_stylebox(si_base_color * Color(0.7, 0.7, 0.7, 0.8), 0, 0, 0, 0, p_config.corner_radius);
  1855. bg_color->set_anti_aliased(false);
  1856. bg_color->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
  1857. bg_color->set_corner_radius(CORNER_BOTTOM_RIGHT, 0);
  1858. p_theme->set_stylebox("sub_inspector_property_bg" + itos(i + 1), EditorStringName(EditorStyles), bg_color);
  1859. // Dictionary editor add item.
  1860. // Expand to the left and right by 4px to compensate for the dictionary editor margins.
  1861. Color style_dictionary_bg_color = p_config.dark_color_3.lerp(si_base_color, 0.08);
  1862. Ref<StyleBoxFlat> style_dictionary_add_item = make_flat_stylebox(style_dictionary_bg_color, 0, 4, 0, 4, p_config.corner_radius);
  1863. style_dictionary_add_item->set_expand_margin(SIDE_LEFT, 2 * EDSCALE);
  1864. style_dictionary_add_item->set_expand_margin(SIDE_RIGHT, 2 * EDSCALE);
  1865. p_theme->set_stylebox("DictionaryAddItem" + itos(i + 1), EditorStringName(EditorStyles), style_dictionary_add_item);
  1866. }
  1867. Color si_base_color = p_config.accent_color;
  1868. // Sub-inspector background.
  1869. Ref<StyleBoxFlat> sub_inspector_bg = p_config.base_style->duplicate();
  1870. sub_inspector_bg->set_bg_color(Color(1, 1, 1, 0));
  1871. sub_inspector_bg->set_border_width_all(2 * EDSCALE);
  1872. sub_inspector_bg->set_border_color(p_config.dark_color_1.lerp(si_base_color, 0.15));
  1873. sub_inspector_bg->set_content_margin_all(4 * EDSCALE);
  1874. sub_inspector_bg->set_corner_radius(CORNER_TOP_LEFT, 0);
  1875. sub_inspector_bg->set_corner_radius(CORNER_TOP_RIGHT, 0);
  1876. p_theme->set_stylebox("sub_inspector_bg0", EditorStringName(EditorStyles), sub_inspector_bg);
  1877. // Sub-inspector background no border.
  1878. Ref<StyleBoxFlat> sub_inspector_bg_no_border = p_config.base_style->duplicate();
  1879. sub_inspector_bg_no_border->set_content_margin_all(2 * EDSCALE);
  1880. sub_inspector_bg_no_border->set_bg_color(p_config.dark_color_2.lerp(p_config.dark_color_3, 0.15));
  1881. p_theme->set_stylebox("sub_inspector_bg_no_border", EditorStringName(EditorStyles), sub_inspector_bg_no_border);
  1882. // EditorProperty background while it has a sub-inspector open.
  1883. Ref<StyleBoxFlat> bg_color = make_flat_stylebox(p_config.dark_color_1.lerp(si_base_color, 0.15), 0, 0, 0, 0, p_config.corner_radius);
  1884. bg_color->set_anti_aliased(false);
  1885. bg_color->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
  1886. bg_color->set_corner_radius(CORNER_BOTTOM_RIGHT, 0);
  1887. p_theme->set_stylebox("sub_inspector_property_bg0", EditorStringName(EditorStyles), bg_color);
  1888. p_theme->set_color("sub_inspector_property_color", EditorStringName(EditorStyles), p_config.dark_theme ? Color(1, 1, 1, 1) : Color(0, 0, 0, 1));
  1889. // Dictionary editor.
  1890. // Expand to the left and right by 4px to compensate for the dictionary editor margins.
  1891. Ref<StyleBoxFlat> style_dictionary_add_item = make_flat_stylebox(prop_subsection_color, 0, 4, 0, 4, p_config.corner_radius);
  1892. style_dictionary_add_item->set_expand_margin(SIDE_LEFT, 2 * EDSCALE);
  1893. style_dictionary_add_item->set_expand_margin(SIDE_RIGHT, 2 * EDSCALE);
  1894. p_theme->set_stylebox("DictionaryAddItem0", EditorStringName(EditorStyles), style_dictionary_add_item);
  1895. }
  1896. // Animation Editor.
  1897. {
  1898. // Timeline general.
  1899. p_theme->set_constant("timeline_v_separation", "AnimationTrackEditor", 0);
  1900. p_theme->set_constant("track_v_separation", "AnimationTrackEditor", 0);
  1901. // AnimationTimelineEdit.
  1902. // "primary" is used for integer timeline values, "secondary" for decimals.
  1903. Ref<StyleBoxFlat> style_time_unavailable = make_flat_stylebox(p_config.dark_color_2, 0, 0, 0, 0, 0);
  1904. Ref<StyleBoxFlat> style_time_available = make_flat_stylebox(p_config.font_color * Color(1, 1, 1, 0.2), 0, 0, 0, 0, 0);
  1905. p_theme->set_stylebox("time_unavailable", "AnimationTimelineEdit", style_time_unavailable);
  1906. p_theme->set_stylebox("time_available", "AnimationTimelineEdit", style_time_available);
  1907. p_theme->set_color("v_line_primary_color", "AnimationTimelineEdit", p_config.font_color * Color(1, 1, 1, 0.2));
  1908. p_theme->set_color("v_line_secondary_color", "AnimationTimelineEdit", p_config.font_color * Color(1, 1, 1, 0.2));
  1909. p_theme->set_color("h_line_color", "AnimationTimelineEdit", p_config.font_color * Color(1, 1, 1, 0.2));
  1910. p_theme->set_color("font_primary_color", "AnimationTimelineEdit", p_config.font_color);
  1911. p_theme->set_color("font_secondary_color", "AnimationTimelineEdit", p_config.font_color * Color(1, 1, 1, 0.5));
  1912. p_theme->set_constant("v_line_primary_margin", "AnimationTimelineEdit", 0);
  1913. p_theme->set_constant("v_line_secondary_margin", "AnimationTimelineEdit", 0);
  1914. p_theme->set_constant("v_line_primary_width", "AnimationTimelineEdit", 1 * EDSCALE);
  1915. p_theme->set_constant("v_line_secondary_width", "AnimationTimelineEdit", 1 * EDSCALE);
  1916. p_theme->set_constant("text_primary_margin", "AnimationTimelineEdit", 3 * EDSCALE);
  1917. p_theme->set_constant("text_secondary_margin", "AnimationTimelineEdit", 3 * EDSCALE);
  1918. // AnimationTrackEdit.
  1919. Ref<StyleBoxFlat> style_animation_track_odd = make_flat_stylebox(Color(0.5, 0.5, 0.5, 0.05), 0, 0, 0, 0, p_config.corner_radius);
  1920. Ref<StyleBoxFlat> style_animation_track_hover = make_flat_stylebox(Color(0.5, 0.5, 0.5, 0.1), 0, 0, 0, 0, p_config.corner_radius);
  1921. p_theme->set_stylebox("odd", "AnimationTrackEdit", style_animation_track_odd);
  1922. p_theme->set_stylebox(SceneStringName(hover), "AnimationTrackEdit", style_animation_track_hover);
  1923. p_theme->set_stylebox("focus", "AnimationTrackEdit", p_config.button_style_focus);
  1924. p_theme->set_color("h_line_color", "AnimationTrackEdit", p_config.font_color * Color(1, 1, 1, 0.2));
  1925. p_theme->set_constant("h_separation", "AnimationTrackEdit", (p_config.increased_margin + 2) * EDSCALE);
  1926. p_theme->set_constant("outer_margin", "AnimationTrackEdit", p_config.increased_margin * 6 * EDSCALE);
  1927. // AnimationTrackEditGroup.
  1928. Ref<StyleBoxFlat> style_animation_track_header = make_flat_stylebox(p_config.dark_color_2 * Color(1, 1, 1, 0.6), p_config.increased_margin * 3, 0, 0, 0, p_config.corner_radius);
  1929. p_theme->set_stylebox("header", "AnimationTrackEditGroup", style_animation_track_header);
  1930. p_theme->set_color("h_line_color", "AnimationTrackEditGroup", p_config.font_color * Color(1, 1, 1, 0.2));
  1931. p_theme->set_color("v_line_color", "AnimationTrackEditGroup", p_config.font_color * Color(1, 1, 1, 0.2));
  1932. p_theme->set_constant("h_separation", "AnimationTrackEditGroup", (p_config.increased_margin + 2) * EDSCALE);
  1933. p_theme->set_constant("v_separation", "AnimationTrackEditGroup", 0);
  1934. // AnimationBezierTrackEdit.
  1935. p_theme->set_color("focus_color", "AnimationBezierTrackEdit", p_config.accent_color * Color(1, 1, 1, 0.7));
  1936. p_theme->set_color("track_focus_color", "AnimationBezierTrackEdit", p_config.accent_color * Color(1, 1, 1, 0.5));
  1937. p_theme->set_color("h_line_color", "AnimationBezierTrackEdit", p_config.font_color * Color(1, 1, 1, 0.2));
  1938. p_theme->set_color("v_line_color", "AnimationBezierTrackEdit", p_config.font_color * Color(1, 1, 1, 0.2));
  1939. p_theme->set_constant("h_separation", "AnimationBezierTrackEdit", (p_config.increased_margin + 2) * EDSCALE);
  1940. p_theme->set_constant("v_separation", "AnimationBezierTrackEdit", p_config.forced_even_separation * EDSCALE);
  1941. }
  1942. // Editor help.
  1943. {
  1944. Ref<StyleBoxFlat> style_editor_help = p_config.base_style->duplicate();
  1945. style_editor_help->set_bg_color(p_config.dark_color_2);
  1946. style_editor_help->set_border_color(p_config.dark_color_3);
  1947. p_theme->set_stylebox("background", "EditorHelp", style_editor_help);
  1948. const Color kbd_color = p_config.font_color.lerp(Color(0.5, 0.5, 0.5), 0.5);
  1949. p_theme->set_color("title_color", "EditorHelp", p_config.accent_color);
  1950. p_theme->set_color("headline_color", "EditorHelp", p_config.mono_color);
  1951. p_theme->set_color("text_color", "EditorHelp", p_config.font_color);
  1952. p_theme->set_color("comment_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.6));
  1953. p_theme->set_color("symbol_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.6));
  1954. p_theme->set_color("value_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.6));
  1955. p_theme->set_color("qualifier_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.8));
  1956. p_theme->set_color("type_color", "EditorHelp", p_config.accent_color.lerp(p_config.font_color, 0.5));
  1957. p_theme->set_color("override_color", "EditorHelp", p_config.warning_color);
  1958. p_theme->set_color("selection_color", "EditorHelp", p_config.selection_color);
  1959. p_theme->set_color("link_color", "EditorHelp", p_config.accent_color.lerp(p_config.mono_color, 0.8));
  1960. p_theme->set_color("code_color", "EditorHelp", p_config.accent_color.lerp(p_config.mono_color, 0.6));
  1961. p_theme->set_color("kbd_color", "EditorHelp", p_config.accent_color.lerp(kbd_color, 0.6));
  1962. p_theme->set_color("code_bg_color", "EditorHelp", p_config.dark_color_3);
  1963. p_theme->set_color("kbd_bg_color", "EditorHelp", p_config.dark_color_1);
  1964. p_theme->set_color("param_bg_color", "EditorHelp", p_config.dark_color_1);
  1965. p_theme->set_constant(SceneStringName(line_separation), "EditorHelp", Math::round(6 * EDSCALE));
  1966. p_theme->set_constant("table_h_separation", "EditorHelp", 16 * EDSCALE);
  1967. p_theme->set_constant("table_v_separation", "EditorHelp", 6 * EDSCALE);
  1968. p_theme->set_constant("text_highlight_h_padding", "EditorHelp", 1 * EDSCALE);
  1969. p_theme->set_constant("text_highlight_v_padding", "EditorHelp", 2 * EDSCALE);
  1970. }
  1971. // EditorHelpBitTitle.
  1972. {
  1973. Ref<StyleBoxFlat> style = p_config.tree_panel_style->duplicate();
  1974. style->set_bg_color(p_config.dark_theme ? style->get_bg_color().lightened(0.04) : style->get_bg_color().darkened(0.04));
  1975. style->set_border_color(p_config.dark_theme ? style->get_border_color().lightened(0.04) : style->get_border_color().darkened(0.04));
  1976. style->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
  1977. style->set_corner_radius(CORNER_BOTTOM_RIGHT, 0);
  1978. p_theme->set_type_variation("EditorHelpBitTitle", "RichTextLabel");
  1979. p_theme->set_stylebox(CoreStringName(normal), "EditorHelpBitTitle", style);
  1980. }
  1981. // EditorHelpBitContent.
  1982. {
  1983. Ref<StyleBoxFlat> style = p_config.tree_panel_style->duplicate();
  1984. style->set_corner_radius(CORNER_TOP_LEFT, 0);
  1985. style->set_corner_radius(CORNER_TOP_RIGHT, 0);
  1986. p_theme->set_type_variation("EditorHelpBitContent", "RichTextLabel");
  1987. p_theme->set_stylebox(CoreStringName(normal), "EditorHelpBitContent", style);
  1988. }
  1989. // Asset Library.
  1990. p_theme->set_stylebox("bg", "AssetLib", p_config.base_empty_style);
  1991. p_theme->set_stylebox(SceneStringName(panel), "AssetLib", p_config.content_panel_style);
  1992. p_theme->set_color("status_color", "AssetLib", Color(0.5, 0.5, 0.5)); // FIXME: Use a defined color instead.
  1993. p_theme->set_icon("dismiss", "AssetLib", p_theme->get_icon(SNAME("Close"), EditorStringName(EditorIcons)));
  1994. // Debugger.
  1995. {
  1996. Ref<StyleBoxFlat> debugger_panel_style = p_config.content_panel_style->duplicate();
  1997. debugger_panel_style->set_border_width(SIDE_BOTTOM, 0);
  1998. p_theme->set_stylebox("DebuggerPanel", EditorStringName(EditorStyles), debugger_panel_style);
  1999. // This pattern of get_font()->get_height(get_font_size()) is used quite a lot and is very verbose.
  2000. // FIXME: Introduce Theme::get_font_height() / Control::get_theme_font_height() / Window::get_theme_font_height().
  2001. const int offset_i1 = p_theme->get_font(SNAME("tab_selected"), SNAME("TabContainer"))->get_height(p_theme->get_font_size(SNAME("tab_selected"), SNAME("TabContainer")));
  2002. const int offset_i2 = p_theme->get_stylebox(SNAME("tab_selected"), SNAME("TabContainer"))->get_minimum_size().height;
  2003. const int offset_i3 = p_theme->get_stylebox(SceneStringName(panel), SNAME("TabContainer"))->get_content_margin(SIDE_TOP);
  2004. const int invisible_top_offset = offset_i1 + offset_i2 + offset_i3;
  2005. Ref<StyleBoxFlat> invisible_top_panel_style = p_config.content_panel_style->duplicate();
  2006. invisible_top_panel_style->set_expand_margin(SIDE_TOP, -invisible_top_offset);
  2007. invisible_top_panel_style->set_content_margin(SIDE_TOP, 0);
  2008. p_theme->set_stylebox("BottomPanelDebuggerOverride", EditorStringName(EditorStyles), invisible_top_panel_style);
  2009. }
  2010. // Resource and node editors.
  2011. {
  2012. // TextureRegion editor.
  2013. Ref<StyleBoxFlat> style_texture_region_bg = p_config.tree_panel_style->duplicate();
  2014. style_texture_region_bg->set_content_margin_all(0);
  2015. p_theme->set_stylebox("TextureRegionPreviewBG", EditorStringName(EditorStyles), style_texture_region_bg);
  2016. p_theme->set_stylebox("TextureRegionPreviewFG", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0));
  2017. // Theme editor.
  2018. {
  2019. p_theme->set_color("preview_picker_overlay_color", "ThemeEditor", Color(0.1, 0.1, 0.1, 0.25));
  2020. Color theme_preview_picker_bg_color = p_config.accent_color;
  2021. theme_preview_picker_bg_color.a = 0.2;
  2022. Ref<StyleBoxFlat> theme_preview_picker_sb = make_flat_stylebox(theme_preview_picker_bg_color, 0, 0, 0, 0);
  2023. theme_preview_picker_sb->set_border_color(p_config.accent_color);
  2024. theme_preview_picker_sb->set_border_width_all(1.0 * EDSCALE);
  2025. p_theme->set_stylebox("preview_picker_overlay", "ThemeEditor", theme_preview_picker_sb);
  2026. Color theme_preview_picker_label_bg_color = p_config.accent_color;
  2027. theme_preview_picker_label_bg_color.set_v(0.5);
  2028. Ref<StyleBoxFlat> theme_preview_picker_label_sb = make_flat_stylebox(theme_preview_picker_label_bg_color, 4.0, 1.0, 4.0, 3.0);
  2029. p_theme->set_stylebox("preview_picker_label", "ThemeEditor", theme_preview_picker_label_sb);
  2030. Ref<StyleBoxFlat> style_theme_preview_tab = p_theme->get_stylebox(SNAME("tab_selected"), SNAME("TabContainerOdd"))->duplicate();
  2031. style_theme_preview_tab->set_expand_margin(SIDE_BOTTOM, 5 * EDSCALE);
  2032. p_theme->set_stylebox("ThemeEditorPreviewFG", EditorStringName(EditorStyles), style_theme_preview_tab);
  2033. Ref<StyleBoxFlat> style_theme_preview_bg_tab = p_theme->get_stylebox(SNAME("tab_unselected"), SNAME("TabContainer"))->duplicate();
  2034. style_theme_preview_bg_tab->set_expand_margin(SIDE_BOTTOM, 2 * EDSCALE);
  2035. p_theme->set_stylebox("ThemeEditorPreviewBG", EditorStringName(EditorStyles), style_theme_preview_bg_tab);
  2036. }
  2037. // VisualShader editor.
  2038. p_theme->set_stylebox("label_style", "VShaderEditor", make_empty_stylebox(4, 6, 4, 6));
  2039. // StateMachine graph.
  2040. {
  2041. p_theme->set_stylebox(SceneStringName(panel), "GraphStateMachine", p_config.tree_panel_style);
  2042. p_theme->set_stylebox("error_panel", "GraphStateMachine", p_config.tree_panel_style);
  2043. p_theme->set_color("error_color", "GraphStateMachine", p_config.error_color);
  2044. const int sm_margin_side = 10 * EDSCALE;
  2045. const int sm_margin_bottom = 2;
  2046. const Color sm_bg_color = p_config.dark_theme ? p_config.dark_color_3 : p_config.dark_color_1.lerp(p_config.mono_color, 0.09);
  2047. Ref<StyleBoxFlat> sm_node_style = make_flat_stylebox(p_config.dark_color_3 * Color(1, 1, 1, 0.7), sm_margin_side, 24 * EDSCALE, sm_margin_side, sm_margin_bottom, p_config.corner_radius);
  2048. sm_node_style->set_border_width_all(p_config.border_width);
  2049. sm_node_style->set_border_color(sm_bg_color);
  2050. Ref<StyleBoxFlat> sm_node_selected_style = make_flat_stylebox(sm_bg_color * Color(1, 1, 1, 0.9), sm_margin_side, 24 * EDSCALE, sm_margin_side, sm_margin_bottom, p_config.corner_radius);
  2051. sm_node_selected_style->set_border_width_all(2 * EDSCALE + p_config.border_width);
  2052. sm_node_selected_style->set_border_color(p_config.accent_color * Color(1, 1, 1, 0.9));
  2053. sm_node_selected_style->set_shadow_size(8 * EDSCALE);
  2054. sm_node_selected_style->set_shadow_color(p_config.shadow_color);
  2055. Ref<StyleBoxFlat> sm_node_playing_style = sm_node_selected_style->duplicate();
  2056. sm_node_playing_style->set_border_color(p_config.warning_color);
  2057. sm_node_playing_style->set_shadow_color(p_config.warning_color * Color(1, 1, 1, 0.2));
  2058. sm_node_playing_style->set_draw_center(false);
  2059. p_theme->set_stylebox("node_frame", "GraphStateMachine", sm_node_style);
  2060. p_theme->set_stylebox("node_frame_selected", "GraphStateMachine", sm_node_selected_style);
  2061. p_theme->set_stylebox("node_frame_playing", "GraphStateMachine", sm_node_playing_style);
  2062. Ref<StyleBoxFlat> sm_node_start_style = sm_node_style->duplicate();
  2063. sm_node_start_style->set_border_width_all(1 * EDSCALE);
  2064. sm_node_start_style->set_border_color(p_config.success_color.lightened(0.24));
  2065. p_theme->set_stylebox("node_frame_start", "GraphStateMachine", sm_node_start_style);
  2066. Ref<StyleBoxFlat> sm_node_end_style = sm_node_style->duplicate();
  2067. sm_node_end_style->set_border_width_all(1 * EDSCALE);
  2068. sm_node_end_style->set_border_color(p_config.error_color);
  2069. p_theme->set_stylebox("node_frame_end", "GraphStateMachine", sm_node_end_style);
  2070. p_theme->set_font("node_title_font", "GraphStateMachine", p_theme->get_font(SceneStringName(font), SNAME("Label")));
  2071. p_theme->set_font_size("node_title_font_size", "GraphStateMachine", p_theme->get_font_size(SceneStringName(font_size), SNAME("Label")));
  2072. p_theme->set_color("node_title_font_color", "GraphStateMachine", p_config.font_color);
  2073. p_theme->set_color("transition_color", "GraphStateMachine", p_config.font_color);
  2074. p_theme->set_color("transition_disabled_color", "GraphStateMachine", p_config.font_color * Color(1, 1, 1, 0.2));
  2075. p_theme->set_color("transition_icon_color", "GraphStateMachine", Color(1, 1, 1));
  2076. p_theme->set_color("transition_icon_disabled_color", "GraphStateMachine", Color(1, 1, 1, 0.2));
  2077. p_theme->set_color("highlight_color", "GraphStateMachine", p_config.accent_color);
  2078. p_theme->set_color("highlight_disabled_color", "GraphStateMachine", p_config.accent_color * Color(1, 1, 1, 0.6));
  2079. p_theme->set_color("focus_color", "GraphStateMachine", p_config.accent_color);
  2080. p_theme->set_color("guideline_color", "GraphStateMachine", p_config.font_color * Color(1, 1, 1, 0.3));
  2081. p_theme->set_color("playback_color", "GraphStateMachine", p_config.font_color);
  2082. p_theme->set_color("playback_background_color", "GraphStateMachine", p_config.font_color * Color(1, 1, 1, 0.3));
  2083. }
  2084. }
  2085. }
  2086. void EditorThemeManager::_generate_text_editor_defaults(ThemeConfiguration &p_config) {
  2087. // Adaptive colors for comments and elements with lower relevance.
  2088. const Color dim_color = Color(p_config.font_color, 0.5);
  2089. const float mono_value = p_config.mono_color.r;
  2090. const Color alpha1 = Color(mono_value, mono_value, mono_value, 0.07);
  2091. const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.14);
  2092. const Color alpha3 = Color(mono_value, mono_value, mono_value, 0.27);
  2093. /* clang-format off */
  2094. // Syntax highlight token colors.
  2095. const Color symbol_color = p_config.dark_theme ? Color(0.67, 0.79, 1) : Color(0, 0, 0.61);
  2096. const Color keyword_color = p_config.dark_theme ? Color(1.0, 0.44, 0.52) : Color(0.9, 0.135, 0.51);
  2097. const Color control_flow_keyword_color = p_config.dark_theme ? Color(1.0, 0.55, 0.8) : Color(0.743, 0.12, 0.8);
  2098. const Color base_type_color = p_config.dark_theme ? Color(0.26, 1.0, 0.76) : Color(0, 0.6, 0.2);
  2099. const Color engine_type_color = p_config.dark_theme ? Color(0.56, 1, 0.86) : Color(0.11, 0.55, 0.4);
  2100. const Color user_type_color = p_config.dark_theme ? Color(0.78, 1, 0.93) : Color(0.18, 0.45, 0.4);
  2101. const Color comment_color = p_config.dark_theme ? dim_color : Color(0.08, 0.08, 0.08, 0.5);
  2102. const Color doc_comment_color = p_config.dark_theme ? Color(0.6, 0.7, 0.8, 0.8) : Color(0.15, 0.15, 0.4, 0.7);
  2103. const Color string_color = p_config.dark_theme ? Color(1, 0.93, 0.63) : Color(0.6, 0.42, 0);
  2104. // Use the brightest background color on a light theme (which generally uses a negative contrast rate).
  2105. const Color te_background_color = p_config.dark_theme ? p_config.dark_color_2 : p_config.dark_color_3;
  2106. const Color completion_background_color = p_config.dark_theme ? p_config.base_color : p_config.dark_color_2;
  2107. const Color completion_selected_color = alpha1;
  2108. const Color completion_existing_color = alpha2;
  2109. // Same opacity as the scroll grabber editor icon.
  2110. const Color completion_scroll_color = Color(mono_value, mono_value, mono_value, 0.29);
  2111. const Color completion_scroll_hovered_color = Color(mono_value, mono_value, mono_value, 0.4);
  2112. const Color completion_font_color = p_config.font_color;
  2113. const Color text_color = p_config.font_color;
  2114. const Color line_number_color = dim_color;
  2115. const Color safe_line_number_color = p_config.dark_theme ? (dim_color * Color(1, 1.2, 1, 1.5)) : Color(0, 0.4, 0, 0.75);
  2116. const Color caret_color = p_config.mono_color;
  2117. const Color caret_background_color = p_config.mono_color.inverted();
  2118. const Color text_selected_color = Color(0, 0, 0, 0);
  2119. const Color selection_color = p_config.selection_color;
  2120. const Color brace_mismatch_color = p_config.dark_theme ? p_config.error_color : Color(1, 0.08, 0, 1);
  2121. const Color current_line_color = alpha1;
  2122. const Color line_length_guideline_color = p_config.dark_theme ? p_config.base_color : p_config.dark_color_2;
  2123. const Color word_highlighted_color = alpha1;
  2124. const Color number_color = p_config.dark_theme ? Color(0.63, 1, 0.88) : Color(0, 0.55, 0.28, 1);
  2125. const Color function_color = p_config.dark_theme ? Color(0.34, 0.7, 1.0) : Color(0, 0.225, 0.9, 1);
  2126. const Color member_variable_color = p_config.dark_theme ? Color(0.34, 0.7, 1.0).lerp(p_config.mono_color, 0.6) : Color(0, 0.4, 0.68, 1);
  2127. const Color mark_color = Color(p_config.error_color.r, p_config.error_color.g, p_config.error_color.b, 0.3);
  2128. const Color bookmark_color = Color(0.08, 0.49, 0.98);
  2129. const Color breakpoint_color = p_config.dark_theme ? p_config.error_color : Color(1, 0.27, 0.2, 1);
  2130. const Color executing_line_color = Color(0.98, 0.89, 0.27);
  2131. const Color code_folding_color = alpha3;
  2132. const Color folded_code_region_color = Color(0.68, 0.46, 0.77, 0.2);
  2133. const Color search_result_color = alpha1;
  2134. const Color search_result_border_color = p_config.dark_theme ? Color(0.41, 0.61, 0.91, 0.38) : Color(0, 0.4, 1, 0.38);
  2135. /* clang-format on */
  2136. EditorSettings *setting = EditorSettings::get_singleton();
  2137. /* clang-format off */
  2138. setting->set_initial_value("text_editor/theme/highlighting/symbol_color", symbol_color, true);
  2139. setting->set_initial_value("text_editor/theme/highlighting/keyword_color", keyword_color, true);
  2140. setting->set_initial_value("text_editor/theme/highlighting/control_flow_keyword_color", control_flow_keyword_color, true);
  2141. setting->set_initial_value("text_editor/theme/highlighting/base_type_color", base_type_color, true);
  2142. setting->set_initial_value("text_editor/theme/highlighting/engine_type_color", engine_type_color, true);
  2143. setting->set_initial_value("text_editor/theme/highlighting/user_type_color", user_type_color, true);
  2144. setting->set_initial_value("text_editor/theme/highlighting/comment_color", comment_color, true);
  2145. setting->set_initial_value("text_editor/theme/highlighting/doc_comment_color", doc_comment_color, true);
  2146. setting->set_initial_value("text_editor/theme/highlighting/string_color", string_color, true);
  2147. setting->set_initial_value("text_editor/theme/highlighting/background_color", te_background_color, true);
  2148. setting->set_initial_value("text_editor/theme/highlighting/completion_background_color", completion_background_color, true);
  2149. setting->set_initial_value("text_editor/theme/highlighting/completion_selected_color", completion_selected_color, true);
  2150. setting->set_initial_value("text_editor/theme/highlighting/completion_existing_color", completion_existing_color, true);
  2151. setting->set_initial_value("text_editor/theme/highlighting/completion_scroll_color", completion_scroll_color, true);
  2152. setting->set_initial_value("text_editor/theme/highlighting/completion_scroll_hovered_color", completion_scroll_hovered_color, true);
  2153. setting->set_initial_value("text_editor/theme/highlighting/completion_font_color", completion_font_color, true);
  2154. setting->set_initial_value("text_editor/theme/highlighting/text_color", text_color, true);
  2155. setting->set_initial_value("text_editor/theme/highlighting/line_number_color", line_number_color, true);
  2156. setting->set_initial_value("text_editor/theme/highlighting/safe_line_number_color", safe_line_number_color, true);
  2157. setting->set_initial_value("text_editor/theme/highlighting/caret_color", caret_color, true);
  2158. setting->set_initial_value("text_editor/theme/highlighting/caret_background_color", caret_background_color, true);
  2159. setting->set_initial_value("text_editor/theme/highlighting/text_selected_color", text_selected_color, true);
  2160. setting->set_initial_value("text_editor/theme/highlighting/selection_color", selection_color, true);
  2161. setting->set_initial_value("text_editor/theme/highlighting/brace_mismatch_color", brace_mismatch_color, true);
  2162. setting->set_initial_value("text_editor/theme/highlighting/current_line_color", current_line_color, true);
  2163. setting->set_initial_value("text_editor/theme/highlighting/line_length_guideline_color", line_length_guideline_color, true);
  2164. setting->set_initial_value("text_editor/theme/highlighting/word_highlighted_color", word_highlighted_color, true);
  2165. setting->set_initial_value("text_editor/theme/highlighting/number_color", number_color, true);
  2166. setting->set_initial_value("text_editor/theme/highlighting/function_color", function_color, true);
  2167. setting->set_initial_value("text_editor/theme/highlighting/member_variable_color", member_variable_color, true);
  2168. setting->set_initial_value("text_editor/theme/highlighting/mark_color", mark_color, true);
  2169. setting->set_initial_value("text_editor/theme/highlighting/bookmark_color", bookmark_color, true);
  2170. setting->set_initial_value("text_editor/theme/highlighting/breakpoint_color", breakpoint_color, true);
  2171. setting->set_initial_value("text_editor/theme/highlighting/executing_line_color", executing_line_color, true);
  2172. setting->set_initial_value("text_editor/theme/highlighting/code_folding_color", code_folding_color, true);
  2173. setting->set_initial_value("text_editor/theme/highlighting/folded_code_region_color", folded_code_region_color, true);
  2174. setting->set_initial_value("text_editor/theme/highlighting/search_result_color", search_result_color, true);
  2175. setting->set_initial_value("text_editor/theme/highlighting/search_result_border_color", search_result_border_color, true);
  2176. /* clang-format on */
  2177. }
  2178. void EditorThemeManager::_populate_text_editor_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config) {
  2179. String text_editor_color_theme = EditorSettings::get_singleton()->get("text_editor/theme/color_theme");
  2180. if (text_editor_color_theme == "Default") {
  2181. _generate_text_editor_defaults(p_config);
  2182. } else if (text_editor_color_theme == "Godot 2") {
  2183. EditorSettings::get_singleton()->load_text_editor_theme();
  2184. }
  2185. // Now theme is loaded, apply it to CodeEdit.
  2186. p_theme->set_font(SceneStringName(font), "CodeEdit", p_theme->get_font(SNAME("source"), EditorStringName(EditorFonts)));
  2187. p_theme->set_font_size(SceneStringName(font_size), "CodeEdit", p_theme->get_font_size(SNAME("source_size"), EditorStringName(EditorFonts)));
  2188. /* clang-format off */
  2189. p_theme->set_icon("tab", "CodeEdit", p_theme->get_icon(SNAME("GuiTab"), EditorStringName(EditorIcons)));
  2190. p_theme->set_icon("space", "CodeEdit", p_theme->get_icon(SNAME("GuiSpace"), EditorStringName(EditorIcons)));
  2191. p_theme->set_icon("folded", "CodeEdit", p_theme->get_icon(SNAME("CodeFoldedRightArrow"), EditorStringName(EditorIcons)));
  2192. p_theme->set_icon("can_fold", "CodeEdit", p_theme->get_icon(SNAME("CodeFoldDownArrow"), EditorStringName(EditorIcons)));
  2193. p_theme->set_icon("folded_code_region", "CodeEdit", p_theme->get_icon(SNAME("CodeRegionFoldedRightArrow"), EditorStringName(EditorIcons)));
  2194. p_theme->set_icon("can_fold_code_region", "CodeEdit", p_theme->get_icon(SNAME("CodeRegionFoldDownArrow"), EditorStringName(EditorIcons)));
  2195. p_theme->set_icon("executing_line", "CodeEdit", p_theme->get_icon(SNAME("TextEditorPlay"), EditorStringName(EditorIcons)));
  2196. p_theme->set_icon("breakpoint", "CodeEdit", p_theme->get_icon(SNAME("Breakpoint"), EditorStringName(EditorIcons)));
  2197. /* clang-format on */
  2198. p_theme->set_constant("line_spacing", "CodeEdit", EDITOR_GET("text_editor/appearance/whitespace/line_spacing"));
  2199. const Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color");
  2200. Ref<StyleBoxFlat> code_edit_stylebox = make_flat_stylebox(background_color, p_config.widget_margin.x, p_config.widget_margin.y, p_config.widget_margin.x, p_config.widget_margin.y, p_config.corner_radius);
  2201. p_theme->set_stylebox(CoreStringName(normal), "CodeEdit", code_edit_stylebox);
  2202. p_theme->set_stylebox("read_only", "CodeEdit", code_edit_stylebox);
  2203. p_theme->set_stylebox("focus", "CodeEdit", memnew(StyleBoxEmpty));
  2204. p_theme->set_color("background_color", "CodeEdit", Color(0, 0, 0, 0)); // Unset any color, we use a stylebox.
  2205. /* clang-format off */
  2206. p_theme->set_color("completion_background_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_background_color"));
  2207. p_theme->set_color("completion_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_selected_color"));
  2208. p_theme->set_color("completion_existing_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_existing_color"));
  2209. p_theme->set_color("completion_scroll_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_scroll_color"));
  2210. p_theme->set_color("completion_scroll_hovered_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_scroll_hovered_color"));
  2211. p_theme->set_color(SceneStringName(font_color), "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_color"));
  2212. p_theme->set_color("line_number_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_number_color"));
  2213. p_theme->set_color("caret_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/caret_color"));
  2214. p_theme->set_color("font_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_selected_color"));
  2215. p_theme->set_color("selection_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/selection_color"));
  2216. p_theme->set_color("brace_mismatch_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/brace_mismatch_color"));
  2217. p_theme->set_color("current_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/current_line_color"));
  2218. p_theme->set_color("line_length_guideline_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_length_guideline_color"));
  2219. p_theme->set_color("word_highlighted_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/word_highlighted_color"));
  2220. p_theme->set_color("bookmark_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/bookmark_color"));
  2221. p_theme->set_color("breakpoint_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/breakpoint_color"));
  2222. p_theme->set_color("executing_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/executing_line_color"));
  2223. p_theme->set_color("code_folding_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/code_folding_color"));
  2224. p_theme->set_color("folded_code_region_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/folded_code_region_color"));
  2225. p_theme->set_color("search_result_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_color"));
  2226. p_theme->set_color("search_result_border_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_border_color"));
  2227. /* clang-format on */
  2228. }
  2229. void EditorThemeManager::_populate_visual_shader_styles(const Ref<EditorTheme> &p_theme, ThemeConfiguration &p_config) {
  2230. EditorSettings *ed_settings = EditorSettings::get_singleton();
  2231. String visual_shader_color_theme = ed_settings->get("editors/visual_editors/color_theme");
  2232. if (visual_shader_color_theme == "Default") {
  2233. // Connection type colors
  2234. ed_settings->set_initial_value("editors/visual_editors/connection_colors/scalar_color", Color(0.55, 0.55, 0.55), true);
  2235. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector2_color", Color(0.44, 0.43, 0.64), true);
  2236. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector3_color", Color(0.337, 0.314, 0.71), true);
  2237. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector4_color", Color(0.7, 0.65, 0.147), true);
  2238. ed_settings->set_initial_value("editors/visual_editors/connection_colors/boolean_color", Color(0.243, 0.612, 0.349), true);
  2239. ed_settings->set_initial_value("editors/visual_editors/connection_colors/transform_color", Color(0.71, 0.357, 0.64), true);
  2240. ed_settings->set_initial_value("editors/visual_editors/connection_colors/sampler_color", Color(0.659, 0.4, 0.137), true);
  2241. // Node category colors (used for the node headers)
  2242. ed_settings->set_initial_value("editors/visual_editors/category_colors/output_color", Color(0.26, 0.10, 0.15), true);
  2243. ed_settings->set_initial_value("editors/visual_editors/category_colors/color_color", Color(0.5, 0.5, 0.1), true);
  2244. ed_settings->set_initial_value("editors/visual_editors/category_colors/conditional_color", Color(0.208, 0.522, 0.298), true);
  2245. ed_settings->set_initial_value("editors/visual_editors/category_colors/input_color", Color(0.502, 0.2, 0.204), true);
  2246. ed_settings->set_initial_value("editors/visual_editors/category_colors/scalar_color", Color(0.1, 0.5, 0.6), true);
  2247. ed_settings->set_initial_value("editors/visual_editors/category_colors/textures_color", Color(0.5, 0.3, 0.1), true);
  2248. ed_settings->set_initial_value("editors/visual_editors/category_colors/transform_color", Color(0.5, 0.3, 0.5), true);
  2249. ed_settings->set_initial_value("editors/visual_editors/category_colors/utility_color", Color(0.2, 0.2, 0.2), true);
  2250. ed_settings->set_initial_value("editors/visual_editors/category_colors/vector_color", Color(0.2, 0.2, 0.5), true);
  2251. ed_settings->set_initial_value("editors/visual_editors/category_colors/special_color", Color(0.098, 0.361, 0.294), true);
  2252. ed_settings->set_initial_value("editors/visual_editors/category_colors/particle_color", Color(0.12, 0.358, 0.8), true);
  2253. } else if (visual_shader_color_theme == "Legacy") {
  2254. // Connection type colors
  2255. ed_settings->set_initial_value("editors/visual_editors/connection_colors/scalar_color", Color(0.38, 0.85, 0.96), true);
  2256. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector2_color", Color(0.74, 0.57, 0.95), true);
  2257. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector3_color", Color(0.84, 0.49, 0.93), true);
  2258. ed_settings->set_initial_value("editors/visual_editors/connection_colors/vector4_color", Color(1.0, 0.125, 0.95), true);
  2259. ed_settings->set_initial_value("editors/visual_editors/connection_colors/boolean_color", Color(0.55, 0.65, 0.94), true);
  2260. ed_settings->set_initial_value("editors/visual_editors/connection_colors/transform_color", Color(0.96, 0.66, 0.43), true);
  2261. ed_settings->set_initial_value("editors/visual_editors/connection_colors/sampler_color", Color(1.0, 1.0, 0.0), true);
  2262. // Node category colors (used for the node headers)
  2263. Ref<StyleBoxFlat> gn_panel_style = p_theme->get_stylebox(SceneStringName(panel), "GraphNode");
  2264. Color gn_bg_color = gn_panel_style->get_bg_color();
  2265. ed_settings->set_initial_value("editors/visual_editors/category_colors/output_color", gn_bg_color, true);
  2266. ed_settings->set_initial_value("editors/visual_editors/category_colors/color_color", gn_bg_color, true);
  2267. ed_settings->set_initial_value("editors/visual_editors/category_colors/conditional_color", gn_bg_color, true);
  2268. ed_settings->set_initial_value("editors/visual_editors/category_colors/input_color", gn_bg_color, true);
  2269. ed_settings->set_initial_value("editors/visual_editors/category_colors/scalar_color", gn_bg_color, true);
  2270. ed_settings->set_initial_value("editors/visual_editors/category_colors/textures_color", gn_bg_color, true);
  2271. ed_settings->set_initial_value("editors/visual_editors/category_colors/transform_color", gn_bg_color, true);
  2272. ed_settings->set_initial_value("editors/visual_editors/category_colors/utility_color", gn_bg_color, true);
  2273. ed_settings->set_initial_value("editors/visual_editors/category_colors/vector_color", gn_bg_color, true);
  2274. ed_settings->set_initial_value("editors/visual_editors/category_colors/special_color", gn_bg_color, true);
  2275. ed_settings->set_initial_value("editors/visual_editors/category_colors/particle_color", gn_bg_color, true);
  2276. }
  2277. }
  2278. void EditorThemeManager::_reset_dirty_flag() {
  2279. outdated_cache_dirty = true;
  2280. }
  2281. // Public interface for theme generation.
  2282. Ref<EditorTheme> EditorThemeManager::generate_theme(const Ref<EditorTheme> &p_old_theme) {
  2283. OS::get_singleton()->benchmark_begin_measure(get_benchmark_key(), "Generate Theme");
  2284. Ref<EditorTheme> theme = _create_base_theme(p_old_theme);
  2285. OS::get_singleton()->benchmark_begin_measure(get_benchmark_key(), "Merge Custom Theme");
  2286. const String custom_theme_path = EDITOR_GET("interface/theme/custom_theme");
  2287. if (!custom_theme_path.is_empty()) {
  2288. Ref<Theme> custom_theme = ResourceLoader::load(custom_theme_path);
  2289. if (custom_theme.is_valid()) {
  2290. theme->merge_with(custom_theme);
  2291. }
  2292. }
  2293. OS::get_singleton()->benchmark_end_measure(get_benchmark_key(), "Merge Custom Theme");
  2294. OS::get_singleton()->benchmark_end_measure(get_benchmark_key(), "Generate Theme");
  2295. benchmark_run++;
  2296. return theme;
  2297. }
  2298. bool EditorThemeManager::is_generated_theme_outdated() {
  2299. // This list includes settings used by files in the editor/themes folder.
  2300. // Note that the editor scale is purposefully omitted because it cannot be changed
  2301. // without a restart, so there is no point regenerating the theme.
  2302. if (outdated_cache_dirty) {
  2303. // TODO: We can use this information more intelligently to do partial theme updates and speed things up.
  2304. outdated_cache = EditorSettings::get_singleton()->check_changed_settings_in_group("interface/theme") ||
  2305. EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/font") ||
  2306. EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/main_font") ||
  2307. EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/code_font") ||
  2308. EditorSettings::get_singleton()->check_changed_settings_in_group("editors/visual_editors") ||
  2309. EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/theme") ||
  2310. EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/help/help") ||
  2311. EditorSettings::get_singleton()->check_changed_settings_in_group("docks/property_editor/subresource_hue_tint") ||
  2312. EditorSettings::get_singleton()->check_changed_settings_in_group("filesystem/file_dialog/thumbnail_size") ||
  2313. EditorSettings::get_singleton()->check_changed_settings_in_group("run/output/font_size");
  2314. // The outdated flag is relevant at the moment of changing editor settings.
  2315. callable_mp_static(&EditorThemeManager::_reset_dirty_flag).call_deferred();
  2316. outdated_cache_dirty = false;
  2317. }
  2318. return outdated_cache;
  2319. }
  2320. bool EditorThemeManager::is_dark_theme() {
  2321. // Light color mode for icons and fonts means it's a dark theme, and vice versa.
  2322. int icon_font_color_setting = EDITOR_GET("interface/theme/icon_and_font_color");
  2323. if (icon_font_color_setting == ColorMode::AUTO_COLOR) {
  2324. Color base_color = EDITOR_GET("interface/theme/base_color");
  2325. return base_color.get_luminance() < 0.5;
  2326. }
  2327. return icon_font_color_setting == ColorMode::LIGHT_COLOR;
  2328. }
  2329. void EditorThemeManager::initialize() {
  2330. EditorColorMap::create();
  2331. EditorTheme::initialize();
  2332. }
  2333. void EditorThemeManager::finalize() {
  2334. EditorColorMap::finish();
  2335. EditorTheme::finalize();
  2336. }