styling fix and clippy fixes
This commit is contained in:
1 parent
1364ff62b8
commit
4137f787bf
17 files changed
+123
-75
No files matched your search
@@ -534,14 +534,12 @@ pub fn resolve_with_context(
|
||||
.get("geometry")
|
||||
.and_then(|value| value.get("shell_radius"))
|
||||
.is_none()
|
||||
{
|
||||
if let Some(radius) = document
|
||||
&& let Some(radius) = document
|
||||
.get("appearance.corner_radius")
|
||||
.and_then(Value::as_f64)
|
||||
.or_else(|| document.get("theme.geometry.top_bar_radius").and_then(Value::as_f64))
|
||||
{
|
||||
tokens.geometry.shell_radius = radius;
|
||||
}
|
||||
{
|
||||
tokens.geometry.shell_radius = radius;
|
||||
}
|
||||
let mut value = serde_json::to_value(&tokens).map_err(|e| e.to_string())?;
|
||||
for file in [&policy.file, &selection.file].into_iter().flatten() {
|
||||
@@ -646,10 +644,10 @@ pub fn theme_path(directory: &Path, path: &Path) -> PathBuf {
|
||||
} else {
|
||||
directory.join(path)
|
||||
};
|
||||
if let (Some(parent), Some(name)) = (path.parent(), path.file_name()) {
|
||||
if let Ok(parent) = parent.canonicalize() {
|
||||
return parent.join(name);
|
||||
}
|
||||
if let (Some(parent), Some(name)) = (path.parent(), path.file_name())
|
||||
&& let Ok(parent) = parent.canonicalize()
|
||||
{
|
||||
return parent.join(name);
|
||||
}
|
||||
path
|
||||
}
|
||||
|
||||
@@ -130,6 +130,34 @@ fn styled_button(p: Palette, selected: bool, navigation: bool) -> theme::Button
|
||||
}
|
||||
}
|
||||
|
||||
/// Authentication actions use normal text while enabled and muted text while disabled.
|
||||
/// Keep the disabled fill neutral so contrast correction cannot make it look active.
|
||||
pub fn authentication_button(palette: Palette) -> theme::Button {
|
||||
let paint = move |enabled: bool, interaction: f32, focused: bool| {
|
||||
let (fill, foreground) = if enabled {
|
||||
let candidate = mix(palette.accent, palette.text, interaction);
|
||||
crate::accent_pair(crate::composite(candidate, palette.card), palette.text)
|
||||
} else {
|
||||
(crate::composite(palette.card, palette.background), palette.muted)
|
||||
};
|
||||
button::Style {
|
||||
background: Some(Background::Color(fill)),
|
||||
text_color: Some(foreground),
|
||||
icon_color: Some(foreground),
|
||||
border_radius: palette.radius.into(),
|
||||
outline_width: if focused { 1. } else { 0. },
|
||||
outline_color: foreground,
|
||||
..Default::default()
|
||||
}
|
||||
};
|
||||
theme::Button::Custom {
|
||||
active: Box::new(move |focused, _| paint(true, 0., focused)),
|
||||
hovered: Box::new(move |focused, _| paint(true, 0.06, focused)),
|
||||
pressed: Box::new(move |focused, _| paint(true, 0.12, focused)),
|
||||
disabled: Box::new(move |_| paint(false, 0., false)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn authentication_input(palette: Palette) -> theme::TextInput {
|
||||
let text = palette.text;
|
||||
let muted = palette.muted;
|
||||
@@ -268,6 +296,40 @@ pub fn filled_button(fill: Color, foreground: Color, radius: f32, opacity: f32)
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn authentication_button_does_not_reverse_enabled_and_disabled_text() {
|
||||
use cosmic::widget::button::Catalog;
|
||||
|
||||
let palette = Palette {
|
||||
appearance: ferese_config::theme::Appearance::Dark,
|
||||
background: Color::from_rgb8(17, 24, 33),
|
||||
sidebar: Color::from_rgb8(17, 24, 33),
|
||||
card: Color::from_rgb8(17, 24, 33),
|
||||
accent: Color::from_rgb8(61, 123, 230),
|
||||
on_accent: Color::from_rgb8(17, 24, 33),
|
||||
text: Color::from_rgb8(244, 247, 251),
|
||||
muted: Color::from_rgb8(135, 147, 162),
|
||||
error: Color::from_rgb8(235, 98, 98),
|
||||
radius: 10.,
|
||||
};
|
||||
let theme = palette.native_theme();
|
||||
let class = authentication_button(palette);
|
||||
for style in [
|
||||
theme.active(false, false, &class),
|
||||
theme.hovered(false, false, &class),
|
||||
theme.pressed(false, false, &class),
|
||||
] {
|
||||
assert_eq!(style.text_color, Some(palette.text));
|
||||
let Some(Background::Color(fill)) = style.background else {
|
||||
panic!("No fill")
|
||||
};
|
||||
assert!(crate::contrast(fill, palette.text) >= 4.5);
|
||||
}
|
||||
let disabled = theme.disabled(&class);
|
||||
assert_eq!(disabled.text_color, Some(palette.muted));
|
||||
assert_eq!(disabled.background, Some(Background::Color(palette.card)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn switch_thumb_remains_readable_in_every_preset_and_state() {
|
||||
for preset in crate::PRESETS {
|
||||
|
||||
@@ -309,16 +309,15 @@ impl<M: Clone> Widget<M, Theme, Renderer> for Radio<'_, M> {
|
||||
if !iced_accessibility::IdEq::eq(&id.0, &self.id.0) {
|
||||
return;
|
||||
}
|
||||
if matches!(request.action, accesskit::Action::Focus | accesskit::Action::Click) {
|
||||
if let Some(message) = self
|
||||
if matches!(request.action, accesskit::Action::Focus | accesskit::Action::Click)
|
||||
&& let Some(message) = self
|
||||
.navigate
|
||||
.as_ref()
|
||||
.and_then(|navigate| navigate(&keyboard::key::Named::Enter))
|
||||
{
|
||||
shell.publish(message);
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
{
|
||||
shell.publish(message);
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if matches!(event, Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left))) {
|
||||
@@ -344,12 +343,11 @@ impl<M: Clone> Widget<M, Theme, Renderer> for Radio<'_, M> {
|
||||
key: keyboard::Key::Named(key),
|
||||
..
|
||||
}) = event
|
||||
&& let Some(message) = self.navigate.as_ref().and_then(|navigate| navigate(key))
|
||||
{
|
||||
if let Some(message) = self.navigate.as_ref().and_then(|navigate| navigate(key)) {
|
||||
shell.publish(message);
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
shell.publish(message);
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
self.content.as_widget_mut().update(
|
||||
|
||||
@@ -44,10 +44,10 @@ fn stream() -> impl cosmic::iced::futures::Stream<Item = Snapshot> {
|
||||
});
|
||||
while receive.changed().await.is_ok() {
|
||||
let snapshot = receive.borrow_and_update().clone();
|
||||
if let Some(snapshot) = snapshot {
|
||||
if output.send(snapshot).await.is_err() {
|
||||
return;
|
||||
}
|
||||
if let Some(snapshot) = snapshot
|
||||
&& output.send(snapshot).await.is_err()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
drop(cancellation);
|
||||
|
||||
Reference in new issue
Block a user