Add editable panels and refine shell settings (#18)

* Integrate panel composition, adaptive sizing, and overflow

* Add instance editing controls to panel settings

* Add panel group editing and measured composition preview

* Reorganize panel settings and add drag-and-drop item editing

* Simplify panel settings and place inspectors beside the editor

* Refine Panel & Shell settings, previews, and panel rendering

* Organize settings navigation and modernize packaged panel config

* Support top and bottom panels and refine shell surfaces

Add edge-aware settings, previews, popup placement, notifications, margins, and corner rendering. Preserve translucency in notification and dialog controls, and tighten spacing around the clock and display-mode icon.

* Add workspace styles and fix Settings text rendering

* Make panel allocation independent of measurement order

* Normalize panel item settings and visibility

* Move shell geometry into each panel

* Add independent group surfaces and finalize panel configuration

* Keep panel fit checks and restoration consistent with allocation

* Reject unknown panel item options and namespace metadata

* Reject invalid shell startup configuration and remove old radius fields

* Discover workspace application icons in a background task

* Remove the panel architecture document and improve reference prose

* Let panel media fill available space and improve Settings scrolling

* Preserve panel labels across clipped GPU rendering

* Use matching alpine lake wallpapers for light and dark modes

* Fix panel accessibility and popup lifecycle

Apply Reduce Transparency to panel opacity in the shell, compositor, and
Settings preview. Reject unknown theme tokens before snapshot substitution
and validate the current geometry fields in both consumers.

Dismiss popovers and workspace tooltips after panel layout changes. Handle
bar pointer exits directly and recover workspace hover after reentry without
repeated motion updates. Cover the transitions with regression tests and
update the wallpaper dimensions check for the bundled lake defaults.

* Use tagged Ferese toolkit fixes

* Fix center-only panel spacing and headless text rendering

* Bundle native 4K abstract wallpapers for both appearances

* Dismiss workspace tooltips before captured pointer dispatch

* Verify installed JPEG wallpapers when replacing a release
This commit is contained in:
Samuel Onoja authored and GitHub committed 2026-10-10 18:50:37 +01:00
1 parent d4c8c10b39
commit 65fcaef13f
84 files changed
+12809 -1258

No files matched your search

+3 -2
View File
@@ -8,9 +8,10 @@ rust-version.workspace = true
[dependencies]
jiff.workspace = true
ferese-theme-model = { path = "../ferese-theme-model" }
ferese-config = { path = "../ferese-config" }
libcosmic = { workspace = true, features = ["a11y"] }
iced_accessibility = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.0" }
iced_accessibility = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.1" }
[dev-dependencies]
ferese-config = { path = "../ferese-config" }
tokio = { version = "1", features = ["rt"] }
+2
View File
@@ -8,7 +8,9 @@ mod geometry;
pub mod icons;
pub mod menus;
mod palette;
pub mod panel;
mod typography;
pub mod workspaces;
pub use button::accent_button;
pub use contrast::{accent_color, accent_pair, apply, composite, contrast, foreground, luminance};
+475
View File
@@ -0,0 +1,475 @@
//! Measure item representations and resolve panel allocation for shell views and previews.
use cosmic::iced::advanced::{Clipboard, Layout, Shell, Widget, layout, mouse, renderer, widget};
use cosmic::iced::{Event, Length, Rectangle, Size, Vector};
use cosmic::{Element, Theme};
use ferese_config::panel::layout::{Measurement, Resolution, resolve_with_gap};
use ferese_config::panel::{ItemId, Panel, Representation};
use std::borrow::Cow;
/// Group outlines never paint a second fill over the panel background.
pub fn group_border(
outline: cosmic::iced::Color,
radius: impl Into<cosmic::iced::border::Radius>,
enabled: bool,
) -> cosmic::widget::container::Style {
let mut style = cosmic::widget::container::Style::default();
style.border.radius = radius.into();
if enabled {
style.border.width = 1.;
style.border.color = outline;
}
style
}
pub struct Sample<'a, M> {
pub id: ItemId,
pub representation: Representation,
pub minimum: Option<f32>,
pub view: Element<'a, M>,
}
pub struct Spacing {
pub overflow_decoration: f32,
pub zone_gap: f32,
}
impl From<f32> for Spacing {
fn from(overflow_decoration: f32) -> Self {
Self {
overflow_decoration,
zone_gap: 8.,
}
}
}
pub fn frame<'a, M: 'a>(
panel: Cow<'a, Panel>,
samples: Vec<Sample<'a, M>>,
spacing: impl Into<Spacing>,
initial: Resolution,
build: impl Fn(&Resolution) -> Element<'a, M> + 'a,
changed: impl Fn(Resolution) -> M + 'a,
) -> Element<'a, M> {
let content = build(&initial);
let spacing = spacing.into();
Element::new(Adaptive {
panel,
samples,
overflow_width: spacing.overflow_decoration,
zone_gap: spacing.zone_gap,
content,
resolution: initial,
build: Box::new(build),
changed: Box::new(changed),
})
}
#[derive(Default)]
struct State {
published: Option<Resolution>,
}
type Build<'a, M> = Box<dyn Fn(&Resolution) -> Element<'a, M> + 'a>;
struct Adaptive<'a, M> {
panel: Cow<'a, Panel>,
samples: Vec<Sample<'a, M>>,
overflow_width: f32,
zone_gap: f32,
content: Element<'a, M>,
resolution: Resolution,
build: Build<'a, M>,
changed: Box<dyn Fn(Resolution) -> M + 'a>,
}
impl<M> Widget<M, Theme, cosmic::Renderer> for Adaptive<'_, M> {
fn tag(&self) -> widget::tree::Tag {
widget::tree::Tag::of::<State>()
}
fn state(&self) -> widget::tree::State {
widget::tree::State::new(State::default())
}
fn children(&self) -> Vec<widget::Tree> {
std::iter::once(widget::Tree::new(&self.content))
.chain(self.samples.iter().map(|sample| widget::Tree::new(&sample.view)))
.collect()
}
fn diff(&mut self, tree: &mut widget::Tree) {
tree.children.truncate(self.samples.len() + 1);
if tree.children.is_empty() {
tree.children.push(widget::Tree::new(&self.content));
}
tree.children[0].diff(self.content.as_widget_mut());
for (index, sample) in self.samples.iter_mut().enumerate() {
if tree.children.len() == index + 1 {
tree.children.push(widget::Tree::new(&sample.view));
}
tree.children[index + 1].diff(sample.view.as_widget_mut());
}
}
fn size(&self) -> Size<Length> {
Size::new(Length::Fill, Length::Fill)
}
fn layout(
&mut self,
tree: &mut widget::Tree,
renderer: &cosmic::Renderer,
limits: &layout::Limits,
) -> layout::Node {
let mut measurements: Vec<Measurement> = Vec::new();
// Measure preferred content before imposing the panel's width. Otherwise
// a clipped wide control can look as small as its compact alternative.
let measurement_limits = layout::Limits::new(Size::ZERO, Size::new(f32::INFINITY, limits.max().height));
for (index, sample) in self.samples.iter_mut().enumerate() {
let node = sample
.view
.as_widget_mut()
.layout(&mut tree.children[index + 1], renderer, &measurement_limits);
let width = node.size().width;
if let Some(measurement) = measurements.iter_mut().find(|measurement| measurement.id == sample.id) {
measurement.alternatives.push((sample.representation, width));
} else {
measurements.push(Measurement {
id: sample.id.clone(),
alternatives: vec![(sample.representation, width)],
minimum: sample.minimum,
});
}
}
let trigger = measurements
.iter()
.find(|measurement| measurement.id.0 == "_overflow")
.map_or(0.0, |measurement| measurement.alternatives[0].1);
let trigger = trigger.min((limits.max().width - self.overflow_width).max(0.0));
self.resolution = resolve_with_gap(
&self.panel,
&measurements,
limits.max().width,
(self.overflow_width + trigger).min(limits.max().width),
self.zone_gap,
);
self.resolution.overflow_trigger_width = trigger;
self.content = (self.build)(&self.resolution);
tree.children[0].diff(self.content.as_widget_mut());
self.content
.as_widget_mut()
.layout(&mut tree.children[0], renderer, limits)
}
fn a11y_nodes(
&self,
layout: Layout<'_>,
tree: &widget::Tree,
cursor: mouse::Cursor,
) -> iced_accessibility::A11yTree {
self.content.as_widget().a11y_nodes(layout, &tree.children[0], cursor)
}
fn update(
&mut self,
tree: &mut widget::Tree,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &cosmic::Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, M>,
viewport: &Rectangle,
) {
self.content.as_widget_mut().update(
&mut tree.children[0],
event,
layout,
cursor,
renderer,
clipboard,
shell,
viewport,
);
let state = tree.state.downcast_mut::<State>();
if matches!(event, Event::Window(cosmic::iced::window::Event::RedrawRequested(_)))
&& state.published.as_ref() != Some(&self.resolution)
{
state.published = Some(self.resolution.clone());
shell.publish((self.changed)(self.resolution.clone()));
}
}
fn draw(
&self,
tree: &widget::Tree,
renderer: &mut cosmic::Renderer,
theme: &Theme,
style: &renderer::Style,
layout: Layout<'_>,
cursor: mouse::Cursor,
viewport: &Rectangle,
) {
self.content
.as_widget()
.draw(&tree.children[0], renderer, theme, style, layout, cursor, viewport);
}
fn mouse_interaction(
&self,
tree: &widget::Tree,
layout: Layout<'_>,
cursor: mouse::Cursor,
viewport: &Rectangle,
renderer: &cosmic::Renderer,
) -> mouse::Interaction {
self.content
.as_widget()
.mouse_interaction(&tree.children[0], layout, cursor, viewport, renderer)
}
fn operate(
&mut self,
tree: &mut widget::Tree,
layout: Layout<'_>,
renderer: &cosmic::Renderer,
operation: &mut dyn widget::Operation,
) {
self.content
.as_widget_mut()
.operate(&mut tree.children[0], layout, renderer, operation);
}
fn overlay<'a>(
&'a mut self,
tree: &'a mut widget::Tree,
layout: Layout<'a>,
renderer: &cosmic::Renderer,
viewport: &Rectangle,
translation: Vector,
) -> Option<cosmic::iced::advanced::overlay::Element<'a, M, Theme, cosmic::Renderer>> {
self.content
.as_widget_mut()
.overlay(&mut tree.children[0], layout, renderer, viewport, translation)
}
}
#[cfg(test)]
mod tests {
use super::*;
use cosmic::iced::advanced::{clipboard, renderer::Headless};
use cosmic::iced::{Font, Pixels, Point};
use cosmic::widget::{button, text};
use ferese_config::panel::OverflowPolicy;
use ferese_config::panel::layout::Placement;
#[derive(Clone, Debug)]
enum Probe {
Resolved(Resolution),
Click,
MeasurementClick,
}
#[test]
fn group_borders_do_not_add_a_fill_or_change_content_colors() {
use cosmic::iced::Color;
let outline = Color::from_rgb(0.4, 0.5, 0.6);
let enabled = group_border(outline, [0., 0., 12., 16.], true);
let disabled = group_border(outline, [0., 0., 12., 16.], false);
assert!(enabled.background.is_none() && disabled.background.is_none());
assert_eq!(enabled.border.width, 1.);
assert_eq!(enabled.border.color, outline);
assert_eq!(disabled.border.width, 0.);
assert_eq!(disabled.border.radius, enabled.border.radius);
assert!(enabled.text_color.is_none() && enabled.icon_color.is_none());
assert!(disabled.text_color.is_none() && disabled.icon_color.is_none());
}
#[test]
fn drawing_an_outlined_group_does_not_raise_panel_background_alpha() {
use cosmic::iced::advanced::{Renderer, renderer};
use cosmic::iced::{Color, widget as widgets};
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let mut renderer = runtime
.block_on(<cosmic::Renderer as Headless>::new(
Font::default(),
Pixels(14.),
Some("tiny-skia"),
))
.unwrap();
let bounds = Rectangle::new(Point::ORIGIN, Size::new(40., 40.));
for opacity in [0., 0.5, 1.] {
for border in [false, true] {
renderer.reset(bounds);
let group = cosmic::widget::container(widgets::Space::new().width(40).height(40)).class(
cosmic::theme::Container::custom(move |_| group_border(Color::WHITE, 8., border)),
);
let mut view: Element<'_, ()> = cosmic::widget::container(group)
.class(cosmic::theme::Container::custom(move |_| {
crate::controls::surface_appearance(
Color {
a: opacity,
..Color::WHITE
},
8.,
)
}))
.into();
let mut tree = widget::Tree::new(&view);
let node =
view.as_widget_mut()
.layout(&mut tree, &renderer, &layout::Limits::new(Size::ZERO, bounds.size()));
view.as_widget().draw(
&tree,
&mut renderer,
&Theme::default(),
&renderer::Style {
text_color: Color::WHITE,
icon_color: Color::WHITE,
scale_factor: 1.,
},
Layout::new(&node),
mouse::Cursor::Unavailable,
&bounds,
);
let pixels = Headless::screenshot(&mut renderer, Size::new(40, 40), 1., Color::TRANSPARENT);
let alpha = pixels[(20 * 40 + 20) * 4 + 3];
assert!(
i16::from(alpha).abs_diff((opacity * 255.).round() as i16) <= 1,
"opacity={opacity}, border={border}, rendered alpha={alpha}"
);
}
}
}
#[test]
fn measured_widgets_adapt_publish_once_and_only_visible_controls_receive_input() {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let renderer = runtime
.block_on(<cosmic::Renderer as Headless>::new(
Font::default(),
Pixels(14.),
Some("tiny-skia"),
))
.unwrap();
let mut panel = Panel::default();
panel.start.groups.clear();
panel.center.groups.clear();
panel.end.groups.retain(|group| group.id.0 == "time");
let id = ItemId("clock".into());
let mut tree = None;
for (width, always) in [(500., false), (75., false), (100., true), (500., false)] {
panel.end.groups[0].items[0].overflow = if always {
OverflowPolicy::Always
} else {
OverflowPolicy::Auto
};
let samples = [
(Representation::Wide, "Wednesday, 7 October · 14:35"),
(Representation::Compact, "14:35"),
(Representation::Icon, "+"),
]
.into_iter()
.map(|(representation, label)| Sample {
id: id.clone(),
representation,
minimum: None,
view: button::custom(text(label).wrapping(cosmic::iced::widget::text::Wrapping::None))
.height(28)
.on_press(Probe::MeasurementClick)
.into(),
})
.chain(std::iter::once(Sample {
id: ItemId("_overflow".into()),
representation: Representation::Icon,
minimum: None,
view: button::custom(text("+"))
.height(28)
.on_press(Probe::MeasurementClick)
.into(),
}))
.collect();
let id = id.clone();
let mut view = frame(
Cow::Borrowed(&panel),
samples,
0.,
Resolution::default(),
move |resolution| {
let width = match resolution.items.get(&id) {
Some(Placement::Visible { width, .. }) => *width,
_ => resolution.overflow_trigger_width,
};
button::custom(text("+"))
.width(width)
.height(28)
.on_press(Probe::Click)
.into()
},
Probe::Resolved,
);
let tree = tree.get_or_insert_with(|| widget::Tree::new(&view));
tree.diff(&mut view);
let viewport = Rectangle::new(Point::ORIGIN, Size::new(width, 28.));
let limits = layout::Limits::new(Size::ZERO, viewport.size());
let node = view.as_widget_mut().layout(tree, &renderer, &limits);
let mut messages = Vec::new();
for _ in 0..4 {
view.as_widget_mut().update(
tree,
&Event::Window(cosmic::iced::window::Event::RedrawRequested(std::time::Instant::now())),
Layout::new(&node),
mouse::Cursor::Unavailable,
&renderer,
&mut clipboard::Null,
&mut Shell::new(&mut messages),
&viewport,
);
}
assert_eq!(messages.len(), 1);
let Probe::Resolved(resolution) = &messages[0] else {
panic!("expected measured resolution")
};
assert!(resolution.fits(width));
if always {
assert_eq!(resolution.overflow, [ItemId("clock".into())]);
} else if width == 500. {
assert!(matches!(
resolution.items.get(&ItemId("clock".into())),
Some(Placement::Visible {
representation: Representation::Wide,
..
})
));
} else {
assert!(matches!(
resolution.items.get(&ItemId("clock".into())),
Some(Placement::Visible {
representation: Representation::Compact | Representation::Icon,
..
})
));
}
for event in [
mouse::Event::ButtonPressed(mouse::Button::Left),
mouse::Event::ButtonReleased(mouse::Button::Left),
] {
view.as_widget_mut().update(
tree,
&Event::Mouse(event),
Layout::new(&node),
mouse::Cursor::Available(Point::new(5., 10.)),
&renderer,
&mut clipboard::Null,
&mut Shell::new(&mut messages),
&viewport,
);
}
assert_eq!(
messages
.iter()
.filter(|message| matches!(message, Probe::Click))
.count(),
1
);
assert!(
!messages
.iter()
.any(|message| matches!(message, Probe::MeasurementClick))
);
}
}
}
+323
View File
@@ -0,0 +1,323 @@
use std::borrow::Cow;
use cosmic::iced::{Alignment, Color, Length};
use cosmic::widget::{Space, container, row};
use cosmic::{Element, theme};
use ferese_config::panel::WorkspaceStyle;
use crate::Palette;
#[derive(Clone)]
pub struct Workspace<'a> {
pub name: Cow<'a, str>,
pub index: u32,
pub window_count: u32,
pub active: bool,
pub visible_elsewhere: bool,
}
pub fn width(style: WorkspaceStyle) -> f32 {
match style {
WorkspaceStyle::Numbers | WorkspaceStyle::Dots => 24.,
WorkspaceStyle::Tabs => 48.,
WorkspaceStyle::WindowStacks => 32.,
WorkspaceStyle::AppIcons => 48.,
}
}
pub fn tooltip_label(workspace: &Workspace<'_>) -> String {
let name = if workspace.name.is_empty() || workspace.name == workspace.index.to_string() {
String::new()
} else {
format!(" · {}", workspace.name)
};
format!(
"Workspace {}{name} · {} {}{}",
workspace.index,
workspace.window_count,
if workspace.window_count == 1 {
"window"
} else {
"windows"
},
if workspace.active { " · Active" } else { "" },
)
}
pub fn indicator<'a, M: 'a>(
style: WorkspaceStyle,
workspace: Workspace<'a>,
palette: Palette,
font: cosmic::font::Font,
height: f32,
progress: f32,
apps: Vec<Element<'a, M>>,
) -> Element<'a, M> {
let progress = progress.clamp(0., 1.);
let occupied = workspace.window_count > 0;
let neutral = if occupied { palette.text } else { palette.muted };
let foreground = crate::mix(neutral, palette.accent, progress);
let content: Element<'a, M> = match style {
WorkspaceStyle::Numbers | WorkspaceStyle::Tabs => {
let label = if style == WorkspaceStyle::Tabs && !workspace.name.trim().is_empty() {
workspace.name.into_owned()
} else {
workspace.index.to_string()
};
crate::text(label, font)
.size(if style == WorkspaceStyle::Tabs { 11 } else { 12 })
.width(width(style) - 8.)
.align_x(cosmic::iced::alignment::Horizontal::Center)
.wrapping(cosmic::iced::widget::text::Wrapping::None)
.ellipsize(cosmic::iced::widget::text::Ellipsize::End(
cosmic::iced::advanced::text::EllipsizeHeightLimit::Lines(1),
))
.class(theme::Text::Color(foreground))
.into()
}
WorkspaceStyle::Dots => container(Space::new())
.width(6. + 10. * progress)
.height(6)
.class(theme::Container::custom(move |_| {
let mut paint = crate::controls::surface_appearance(
foreground.scale_alpha(if occupied { 0.65 + 0.35 * progress } else { progress }),
3.,
);
paint.border.width = 1.;
paint.border.color = foreground.scale_alpha(if occupied { 0.65 } else { 0.55 });
paint
}))
.into(),
WorkspaceStyle::WindowStacks => {
let back = match workspace.window_count {
0 | 1 => "",
2 => "<path d=\"M6 4h13a2 2 0 0 1 2 2v9\"/>",
_ => "<path d=\"M6 4h13a2 2 0 0 1 2 2v9M9 1h13a2 2 0 0 1 2 2v9\"/>",
};
let svg = format!(
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 26 22\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linejoin=\"round\">{back}<rect x=\"2\" y=\"7\" width=\"16\" height=\"12\" rx=\"2.5\"/>{}</svg>",
if occupied { "<path d=\"M2 11h16\"/>" } else { "" }
);
cosmic::widget::icon::from_svg_bytes(crate::icons::tint_svg(svg.as_bytes(), foreground, foreground))
.symbolic(false)
.icon()
.size(20)
.class(theme::Svg::custom(|_| cosmic::iced::widget::svg::Style { color: None }))
.into()
}
WorkspaceStyle::AppIcons => {
let mut icons = row::with_capacity(2).spacing(3).align_y(Alignment::Center);
if apps.is_empty() {
icons = icons.push(crate::icons::tinted(crate::icons::OVERVIEW, 16, foreground));
} else {
for app in apps.into_iter().take(2) {
icons = icons.push(app);
}
}
icons.into()
}
};
let face = container(content).center_x(width(style)).center_y(height);
let face: Element<'a, M> = if style == WorkspaceStyle::Dots {
face.into()
} else {
let marker = container(Space::new())
.width(10)
.height(2)
.class(crate::controls::surface(foreground.scale_alpha(progress), 1.));
cosmic::iced::widget::stack![
face,
container(marker)
.width(Length::Fill)
.height(Length::Fill)
.align_x(cosmic::iced::alignment::Horizontal::Center)
.align_y(cosmic::iced::alignment::Vertical::Bottom)
.padding([1, 0]),
]
.into()
};
container(face)
.width(width(style))
.height(height)
.clip_to_border(true)
.class(theme::Container::custom(move |_| {
let fill = if style == WorkspaceStyle::Dots {
Color::TRANSPARENT
} else if progress > 0. {
palette.accent.scale_alpha(0.16 * progress)
} else if style == WorkspaceStyle::Tabs || occupied && style == WorkspaceStyle::Numbers {
palette.text.scale_alpha(0.045)
} else {
Color::TRANSPARENT
};
let mut paint = crate::controls::surface_appearance(fill, palette.radius.min(8.));
if workspace.visible_elsewhere {
paint.border.width = 1.;
paint.border.color = palette.accent.scale_alpha(0.55);
}
paint
}))
.into()
}
pub fn sample<'a, M: 'a>(
style: WorkspaceStyle,
palette: Palette,
font: cosmic::font::Font,
height: f32,
) -> Element<'a, M> {
let mut samples = row::with_capacity(3).spacing(1).align_y(Alignment::Center);
for (index, count, active) in [(1, 2, true), (2, 1, false), (3, 0, false)] {
let apps = if style == WorkspaceStyle::AppIcons && count > 0 {
let mut apps = vec![crate::icons::tinted(crate::icons::SETTINGS, 16, palette.text).into()];
if count > 1 {
apps.push(crate::icons::tinted(crate::icons::FERESE, 16, palette.accent).into());
}
apps
} else {
Vec::new()
};
samples = samples.push(indicator(
style,
Workspace {
name: Cow::Owned(index.to_string()),
index,
window_count: count,
active,
visible_elsewhere: false,
},
palette,
font,
height,
if active { 1. } else { 0. },
apps,
));
}
samples.into()
}
#[cfg(test)]
mod tests {
use super::*;
use cosmic::iced::advanced::{Layout, Renderer, layout, renderer, renderer::Headless, widget::Tree};
use cosmic::iced::{Font, Pixels, Rectangle, Size, mouse};
#[test]
fn indicators_keep_their_allocation_and_active_shape_in_every_style() {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let mut renderer = runtime
.block_on(<cosmic::Renderer as Headless>::new(
Font::default(),
Pixels(14.),
Some("tiny-skia"),
))
.unwrap();
let palette = Palette::from_resolved(&ferese_config::theme::default_theme());
let theme = palette.native_theme();
for style in WorkspaceStyle::ALL {
for height in [20., 28., 36.] {
let bounds = Rectangle::with_size(Size::new(width(style), height));
let mut active_alpha = Vec::new();
let mut inactive_alpha = Vec::new();
for (count, progress, name) in [
(0, 0., ""),
(1, 0., "1"),
(3, 0., "Design and development"),
(3, 0.5, "Design and development"),
(3, 1., "Design and development"),
] {
let apps = (0..count.min(2))
.map(|_| crate::icons::tinted(crate::icons::SETTINGS, 16, palette.text).into())
.collect();
let mut view: Element<'_, ()> = indicator(
style,
Workspace {
name: name.into(),
index: 1,
window_count: count,
active: progress == 1.,
visible_elsewhere: false,
},
palette,
Font::default(),
height,
progress,
apps,
);
let mut tree = Tree::new(&view);
let node = view.as_widget_mut().layout(
&mut tree,
&renderer,
&layout::Limits::new(Size::ZERO, bounds.size()),
);
assert_eq!(
node.bounds().size(),
bounds.size(),
"{style:?}, height={height}, count={count}, progress={progress}"
);
renderer.reset(bounds);
view.as_widget().draw(
&tree,
&mut renderer,
&theme,
&renderer::Style {
text_color: palette.text,
icon_color: palette.text,
scale_factor: 1.,
},
Layout::new(&node),
mouse::Cursor::Unavailable,
&bounds,
);
let pixels = Headless::screenshot(
&mut renderer,
Size::new(width(style) as u32, height as u32),
1.,
Color::TRANSPARENT,
);
let alpha: Vec<_> = pixels.chunks_exact(4).map(|p| p[3]).collect();
assert!(alpha.iter().any(|a| *a > 0), "{style:?} rendered empty");
if count == 3 && progress == 0. {
inactive_alpha = alpha;
} else if progress == 1. {
active_alpha = alpha;
}
}
assert_ne!(
active_alpha, inactive_alpha,
"{style:?} needs an active shape that survives removal of color"
);
}
}
}
#[test]
fn hover_details_include_names_and_pluralize_window_counts() {
let mut workspace = Workspace {
name: "Design".into(),
index: 2,
window_count: 1,
active: true,
visible_elsewhere: false,
};
assert_eq!(tooltip_label(&workspace), "Workspace 2 · Design · 1 window · Active");
workspace.name = "2".into();
workspace.window_count = 0;
workspace.active = false;
assert_eq!(tooltip_label(&workspace), "Workspace 2 · 0 windows");
}
}