From 45f67625291af6432c42b99a3b68b2b77fb8ad9c Mon Sep 17 00:00:00 2001 From: nasso Date: Sun, 11 Oct 2020 02:53:37 +0200 Subject: [PATCH 1/4] Add a setting to use the system theme --- src/librustdoc/html/render/mod.rs | 103 ++++++++++++++++++++---- src/librustdoc/html/static/settings.css | 40 ++++++++- src/librustdoc/html/static/settings.js | 55 +++++++++---- src/librustdoc/html/static/storage.js | 72 +++++++++++++++-- 4 files changed, 233 insertions(+), 37 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 76334f0213d..a9d4c2cc813 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -575,7 +575,8 @@ impl FormatRenderer for Context { settings( self.shared.static_root_path.as_deref().unwrap_or("./"), &self.shared.resource_suffix, - ), + &self.shared.style_files, + )?, &style_files, ); self.shared.fs.write(&settings_file, v.as_bytes())?; @@ -810,6 +811,7 @@ themePicker.onblur = handleThemeButtonsBlur; but.textContent = item; but.onclick = function(el) {{ switchTheme(currentTheme, mainTheme, item, true); + useSystemTheme(false); }}; but.onblur = handleThemeButtonsBlur; themes.appendChild(but); @@ -1343,12 +1345,25 @@ impl AllTypes { #[derive(Debug)] enum Setting { - Section { description: &'static str, sub_settings: Vec }, - Entry { js_data_name: &'static str, description: &'static str, default_value: bool }, + Section { + description: &'static str, + sub_settings: Vec, + }, + Toggle { + js_data_name: &'static str, + description: &'static str, + default_value: bool, + }, + Select { + js_data_name: &'static str, + description: &'static str, + default_value: &'static str, + options: Vec<(String, String)>, + }, } impl Setting { - fn display(&self) -> String { + fn display(&self, root_path: &str, suffix: &str) -> String { match *self { Setting::Section { ref description, ref sub_settings } => format!( "
\ @@ -1356,9 +1371,9 @@ impl Setting {
{}
", description, - sub_settings.iter().map(|s| s.display()).collect::() + sub_settings.iter().map(|s| s.display(root_path, suffix)).collect::() ), - Setting::Entry { ref js_data_name, ref description, ref default_value } => format!( + Setting::Toggle { ref js_data_name, ref description, ref default_value } => format!( "
\