fix clippy warnings
This commit is contained in:
1 parent
7b88083020
commit
bdc3ba435f
39 files changed
+825
-688
No files matched your search
@@ -1248,6 +1248,53 @@ impl ResolvedTheme {
|
||||
}
|
||||
}
|
||||
|
||||
pub type ImportedFamily = (crate::families::Family, (Option<Tokens>, Option<Tokens>), Vec<String>);
|
||||
|
||||
pub fn import_family(id: &str, source: &str) -> Result<ImportedFamily, String> {
|
||||
let document = Document::parse(source).map_err(|e| e.to_string())?;
|
||||
let root = document.get("theme").unwrap_or(document.value());
|
||||
let name = root.get("name").and_then(Value::as_str).unwrap_or(id).to_owned();
|
||||
let mut variants = [None, None];
|
||||
let mut warnings = vec![];
|
||||
for (index, (key, appearance)) in [("light", Appearance::Light), ("dark", Appearance::Dark)]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
if let Some(layer) = root.get(key) {
|
||||
let base = preset(
|
||||
if appearance == Appearance::Light {
|
||||
"ferese-blue-light"
|
||||
} else {
|
||||
"ferese-blue"
|
||||
},
|
||||
appearance,
|
||||
)?;
|
||||
let mut value = serde_json::to_value(base).map_err(|e| e.to_string())?;
|
||||
merge(&mut value, layer, "", &mut warnings, false)?;
|
||||
let tokens: Tokens = serde_json::from_value(value).map_err(|e| e.to_string())?;
|
||||
validate(&tokens)?;
|
||||
warnings.extend(authored_warnings(&tokens));
|
||||
variants[index] = Some(tokens);
|
||||
}
|
||||
}
|
||||
if variants.iter().all(Option::is_none) {
|
||||
return Err("A theme file must declare a light and/or dark section; partial palettes are allowed.".into());
|
||||
}
|
||||
for key in root.as_object().ok_or("Theme file must be a section")?.keys() {
|
||||
if !matches!(key.as_str(), "name" | "light" | "dark") {
|
||||
warnings.push(format!("Unknown theme token: {key}"));
|
||||
}
|
||||
}
|
||||
let [light, dark] = variants;
|
||||
let family = crate::families::Family {
|
||||
id: id.into(),
|
||||
name,
|
||||
light: light.as_ref().map(crate::families::Palette::from),
|
||||
dark: dark.as_ref().map(crate::families::Palette::from),
|
||||
};
|
||||
Ok((family, (light, dark), warnings))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -1697,51 +1744,3 @@ mod tests {
|
||||
assert_eq!(ResolvedTheme::default().transition(&light, 0.), light);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn import_family(
|
||||
id: &str,
|
||||
source: &str,
|
||||
) -> Result<(crate::families::Family, (Option<Tokens>, Option<Tokens>), Vec<String>), String> {
|
||||
let document = Document::parse(source).map_err(|e| e.to_string())?;
|
||||
let root = document.get("theme").unwrap_or(document.value());
|
||||
let name = root.get("name").and_then(Value::as_str).unwrap_or(id).to_owned();
|
||||
let mut variants = [None, None];
|
||||
let mut warnings = vec![];
|
||||
for (index, (key, appearance)) in [("light", Appearance::Light), ("dark", Appearance::Dark)]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
if let Some(layer) = root.get(key) {
|
||||
let base = preset(
|
||||
if appearance == Appearance::Light {
|
||||
"ferese-blue-light"
|
||||
} else {
|
||||
"ferese-blue"
|
||||
},
|
||||
appearance,
|
||||
)?;
|
||||
let mut value = serde_json::to_value(base).map_err(|e| e.to_string())?;
|
||||
merge(&mut value, layer, "", &mut warnings, false)?;
|
||||
let tokens: Tokens = serde_json::from_value(value).map_err(|e| e.to_string())?;
|
||||
validate(&tokens)?;
|
||||
warnings.extend(authored_warnings(&tokens));
|
||||
variants[index] = Some(tokens);
|
||||
}
|
||||
}
|
||||
if variants.iter().all(Option::is_none) {
|
||||
return Err("A theme file must declare a light and/or dark section; partial palettes are allowed.".into());
|
||||
}
|
||||
for key in root.as_object().ok_or("Theme file must be a section")?.keys() {
|
||||
if !matches!(key.as_str(), "name" | "light" | "dark") {
|
||||
warnings.push(format!("Unknown theme token: {key}"));
|
||||
}
|
||||
}
|
||||
let [light, dark] = variants;
|
||||
let family = crate::families::Family {
|
||||
id: id.into(),
|
||||
name,
|
||||
light: light.as_ref().map(crate::families::Palette::from),
|
||||
dark: dark.as_ref().map(crate::families::Palette::from),
|
||||
};
|
||||
Ok((family, (light, dark), warnings))
|
||||
}
|
||||
@@ -6,17 +6,29 @@ use ferese_config::families::{Family, Palette};
|
||||
use ferese_config::theme::Appearance;
|
||||
use iced_accessibility::{A11yTree, accesskit};
|
||||
|
||||
pub struct TileOptions {
|
||||
pub variant: Option<Appearance>,
|
||||
pub active: Option<Appearance>,
|
||||
pub selected: bool,
|
||||
pub palette: crate::Palette,
|
||||
pub font: cosmic::font::Font,
|
||||
pub id: Id,
|
||||
}
|
||||
|
||||
pub fn tile<M: Clone + 'static>(
|
||||
family: &Family,
|
||||
variant: Option<Appearance>,
|
||||
active: Option<Appearance>,
|
||||
selected: bool,
|
||||
palette: crate::Palette,
|
||||
font: cosmic::font::Font,
|
||||
id: Id,
|
||||
options: TileOptions,
|
||||
on_select: M,
|
||||
navigate: impl Fn(&keyboard::key::Named) -> Option<M> + 'static,
|
||||
) -> Element<'static, M> {
|
||||
let TileOptions {
|
||||
variant,
|
||||
active,
|
||||
selected,
|
||||
palette,
|
||||
font,
|
||||
id,
|
||||
} = options;
|
||||
use cosmic::widget::{button, column, row};
|
||||
let mut caption = row([])
|
||||
.spacing(6)
|
||||
@@ -225,13 +237,15 @@ impl cosmic::iced::advanced::widget::operation::Focusable for Focus {
|
||||
}
|
||||
}
|
||||
|
||||
type Navigation<'a, M> = Box<dyn Fn(&keyboard::key::Named) -> Option<M> + 'a>;
|
||||
|
||||
pub struct Radio<'a, M> {
|
||||
content: Element<'a, M>,
|
||||
id: Id,
|
||||
selected: bool,
|
||||
group: bool,
|
||||
label: String,
|
||||
navigate: Option<Box<dyn Fn(&keyboard::key::Named) -> Option<M> + 'a>>,
|
||||
navigate: Option<Navigation<'a, M>>,
|
||||
}
|
||||
|
||||
pub fn radio<'a, M: Clone + 'a>(
|
||||
|
||||
@@ -120,8 +120,10 @@ mod tests {
|
||||
ferese_config::theme::Appearance::Dark,
|
||||
] {
|
||||
for high_contrast in [false, true] {
|
||||
let mut resolved = ferese_config::theme::ResolvedTheme::default();
|
||||
resolved.appearance = appearance;
|
||||
let mut resolved = ferese_config::theme::ResolvedTheme {
|
||||
appearance,
|
||||
..Default::default()
|
||||
};
|
||||
resolved.accessibility.increase_contrast = high_contrast;
|
||||
let palette = Palette::from_resolved(&resolved);
|
||||
assert_eq!(palette.high_contrast, high_contrast);
|
||||
@@ -133,9 +135,11 @@ mod tests {
|
||||
#[test]
|
||||
fn every_preset_builds_an_opaque_control_palette_over_translucent_materials() {
|
||||
for preset in crate::PRESETS {
|
||||
let mut resolved = ferese_config::theme::ResolvedTheme::default();
|
||||
resolved.appearance = preset.appearance;
|
||||
resolved.tokens = ferese_config::theme::preset(preset.id, preset.appearance).unwrap();
|
||||
let mut resolved = ferese_config::theme::ResolvedTheme {
|
||||
appearance: preset.appearance,
|
||||
tokens: ferese_config::theme::preset(preset.id, preset.appearance).unwrap(),
|
||||
..Default::default()
|
||||
};
|
||||
resolved.tokens.material.style = "translucent".into();
|
||||
resolved.tokens.material.opacity = 0.25;
|
||||
resolved.tokens.geometry.shell_radius = 0.;
|
||||
|
||||
Reference in new issue
Block a user