fix(view): match pin button appearance to designs

This commit is contained in:
Vukašin Vojinović 2025-04-24 13:48:42 +02:00 committed by Michael Murphy
parent 3c9a923f41
commit e2e0f09311

View file

@ -12,7 +12,7 @@ use cosmic::{
advanced::layout::flex::Axis, advanced::layout::flex::Axis,
clipboard::mime::{AllowedMimeTypes, AsMimeTypes}, clipboard::mime::{AllowedMimeTypes, AsMimeTypes},
widget::{column, row}, widget::{column, row},
Border, Length, Alignment, Border, Length,
}, },
iced_core::{text::Wrapping, Shadow}, iced_core::{text::Wrapping, Shadow},
iced_winit::platform_specific::wayland::subsurface_widget::Subsurface, iced_winit::platform_specific::wayland::subsurface_widget::Subsurface,
@ -175,7 +175,7 @@ fn pin_button_style(theme: &cosmic::Theme, is_pinned: bool) -> cosmic::widget::b
cosmic::widget::button::Style { cosmic::widget::button::Style {
icon_color: Some(icon_color), icon_color: Some(icon_color),
background: Some(iced::Background::Color(bg_color)), background: Some(iced::Background::Color(bg_color)),
border_radius: theme.cosmic().corner_radii.radius_s.into(), border_radius: theme.cosmic().corner_radii.radius_m.into(),
..cosmic::widget::button::Style::new() ..cosmic::widget::button::Style::new()
} }
} }
@ -188,6 +188,7 @@ fn pin_button(workspace: &Workspace) -> cosmic::Element<'static, Msg> {
.symbolic(true) .symbolic(true)
.size(16), //.style(|theme, status| todo!()) .size(16), //.style(|theme, status| todo!())
) )
.padding([4, 8])
//.class(cosmic::theme::Button::Icon) //.class(cosmic::theme::Button::Icon)
//.class(cosmic::theme::Button::Image) //.class(cosmic::theme::Button::Image)
.class(cosmic::theme::Button::Custom { .class(cosmic::theme::Button::Custom {
@ -237,11 +238,10 @@ fn workspace_item_appearance(
fn workspace_item( fn workspace_item(
workspace: &Workspace, workspace: &Workspace,
_output: &wl_output::WlOutput, _output: &wl_output::WlOutput,
layout: WorkspaceLayout,
is_drop_target: bool, is_drop_target: bool,
has_workspace_drag: bool, has_workspace_drag: bool,
) -> cosmic::Element<'static, Msg> { ) -> cosmic::Element<'static, Msg> {
let (mut image, image_height) = if let Some(img) = workspace.img.as_ref() { let (image, image_height, image_width) = if let Some(img) = workspace.img.as_ref() {
let is_rotated = matches!( let is_rotated = matches!(
img.transform, img.transform,
wl_output::Transform::_90 wl_output::Transform::_90
@ -262,50 +262,52 @@ fn workspace_item(
// Landscape: fix height // Landscape: fix height
widget::container(capture_image(Some(img), 1.0)).max_height(fixed_size), widget::container(capture_image(Some(img), 1.0)).max_height(fixed_size),
fixed_size, fixed_size,
fixed_size * effective_width as f32 / effective_height as f32,
) )
} else { } else {
( (
// Portrait: fix width // Portrait: fix width
widget::container(capture_image(Some(img), 1.0)).max_width(fixed_size), widget::container(capture_image(Some(img), 1.0)).max_width(fixed_size),
fixed_size * effective_height as f32 / effective_width as f32, fixed_size * effective_height as f32 / effective_width as f32,
fixed_size,
) )
} }
} else { } else {
( (
widget::container(capture_image(None, 1.0)) widget::container(capture_image(None, 1.0))
.max_width(224.0) .max_height(126.0)
.max_height(126.0), .max_width(224.0),
126.0, 126.0,
224.0,
) )
}; };
let workspace_name = row![ let workspace_name = row![
widget::horizontal_space().width(Length::Fixed(if image_width < 160.0 {
0.0
} else {
32.0
})),
widget::text::body(fl!( widget::text::body(fl!(
"workspace", "workspace",
HashMap::from([("number", &workspace.info.name)]) HashMap::from([("number", &workspace.info.name)])
)) ))
.width(Length::Fill) // XXX mades workspace bar fill screen .width(Length::Fill) // XXX mades workspace bar fill screen
.align_x(iced::Alignment::Center), .align_x(Alignment::Center),
pin_button(workspace), pin_button(workspace),
]; ];
// Needed to prevent text getting pushed out when scaling on Vertical layout let content = crate::widgets::size_cross_nth(
if layout == WorkspaceLayout::Vertical {
image = image.height(Length::Fill);
}
let mut content = crate::widgets::size_cross_nth(
vec![ vec![
image.into(), image.height(Length::Fill).into(),
iced::widget::Space::with_height(4.0).into(), iced::widget::Space::with_height(4.0).into(),
workspace_name.into(), workspace_name.into(),
], ],
Axis::Vertical, Axis::Vertical,
0, // Size container to match image size 0, // Size container to match image size
) )
.apply(widget::container); .apply(widget::container)
if layout == WorkspaceLayout::Vertical { .max_height(image_height + 26.0);
content = content.max_height(image_height + 21.0 + 4.0); // text height + spacing
}
let is_active = workspace.is_active() && !has_workspace_drag; let is_active = workspace.is_active() && !has_workspace_drag;
// TODO editable name? // TODO editable name?
@ -339,7 +341,6 @@ fn workspace_item(
fn workspace_drag_placeholder( fn workspace_drag_placeholder(
other_workspace: &Workspace, other_workspace: &Workspace,
other_output: &wl_output::WlOutput, other_output: &wl_output::WlOutput,
layout: WorkspaceLayout,
) -> cosmic::Element<'static, Msg> { ) -> cosmic::Element<'static, Msg> {
let drop_target = DropTarget::WorkspaceSidebarDragPlaceholder( let drop_target = DropTarget::WorkspaceSidebarDragPlaceholder(
other_workspace.handle().clone(), other_workspace.handle().clone(),
@ -354,7 +355,7 @@ fn workspace_drag_placeholder(
}) })
.padding(8); .padding(8);
let placeholder = crate::widgets::match_size( let placeholder = crate::widgets::match_size(
workspace_item(other_workspace, other_output, layout, true, true), workspace_item(other_workspace, other_output, true, true),
placeholder, placeholder,
); );
dnd_destination_for_target(drop_target, placeholder.into(), Msg::DndWorkspaceDrop) dnd_destination_for_target(drop_target, placeholder.into(), Msg::DndWorkspaceDrop)
@ -363,7 +364,6 @@ fn workspace_drag_placeholder(
fn workspace_sidebar_entry<'a>( fn workspace_sidebar_entry<'a>(
workspace: &'a Workspace, workspace: &'a Workspace,
output: &'a wl_output::WlOutput, output: &'a wl_output::WlOutput,
layout: WorkspaceLayout,
is_drop_target: bool, is_drop_target: bool,
has_toplevels: bool, has_toplevels: bool,
has_workspace_drag: bool, has_workspace_drag: bool,
@ -375,13 +375,7 @@ fn workspace_sidebar_entry<'a>(
iced::mouse::Interaction::Idle iced::mouse::Interaction::Idle
}; };
*/ */
let item = workspace_item( let item = workspace_item(workspace, output, is_drop_target, has_workspace_drag);
workspace,
output,
layout,
is_drop_target,
has_workspace_drag,
);
let item = iced::widget::mouse_area(item) let item = iced::widget::mouse_area(item)
.on_enter(Msg::EnteredWorkspaceSidebarEntry( .on_enter(Msg::EnteredWorkspaceSidebarEntry(
workspace.handle().clone(), workspace.handle().clone(),
@ -412,7 +406,7 @@ fn workspace_sidebar_entry<'a>(
DragSurface::Workspace(workspace.handle().clone()), DragSurface::Workspace(workspace.handle().clone()),
Some(workspace.dnd_source_id.clone()), Some(workspace.dnd_source_id.clone()),
destination, destination,
move || workspace_item(&workspace_clone, &output_clone, layout, false, true), move || workspace_item(&workspace_clone, &output_clone, false, true),
) )
} else { } else {
destination destination
@ -439,7 +433,7 @@ fn workspaces_sidebar<'a>(
DragSurface::Workspace(workspace.handle().clone()), DragSurface::Workspace(workspace.handle().clone()),
Some(workspace.dnd_source_id.clone()), Some(workspace.dnd_source_id.clone()),
widget::Space::new(Length::Shrink, Length::Shrink).into(), widget::Space::new(Length::Shrink, Length::Shrink).into(),
move || workspace_item(&workspace_clone, &output_clone, layout, false, true), move || workspace_item(&workspace_clone, &output_clone, false, true),
); );
sidebar_entries.push(source); sidebar_entries.push(source);
continue; continue;
@ -465,12 +459,11 @@ fn workspaces_sidebar<'a>(
&& drag_workspace != Some(workspace.handle()) && drag_workspace != Some(workspace.handle())
&& (drop_target_is_workspace || drop_target_is_placeholder) && (drop_target_is_workspace || drop_target_is_placeholder)
{ {
sidebar_entries.push(workspace_drag_placeholder(workspace, output, layout)); sidebar_entries.push(workspace_drag_placeholder(workspace, output));
} }
sidebar_entries.push(workspace_sidebar_entry( sidebar_entries.push(workspace_sidebar_entry(
workspace, workspace,
output, output,
layout,
drop_target_is_workspace && drag_workspace.is_none(), drop_target_is_workspace && drag_workspace.is_none(),
workspaces_with_toplevels.contains(workspace.handle()), workspaces_with_toplevels.contains(workspace.handle()),
drag_workspace.is_some(), drag_workspace.is_some(),
@ -523,7 +516,7 @@ fn toplevel_preview(toplevel: &Toplevel, is_being_dragged: bool) -> cosmic::Elem
} else { } else {
row![label] row![label]
} }
.align_y(iced::Alignment::Center); .align_y(Alignment::Center);
let alpha = if is_being_dragged { 0.5 } else { 1.0 }; let alpha = if is_being_dragged { 0.5 } else { 1.0 };
crate::widgets::size_cross_nth( crate::widgets::size_cross_nth(
vec![ vec![
@ -552,7 +545,7 @@ fn toplevel_preview(toplevel: &Toplevel, is_being_dragged: bool) -> cosmic::Elem
close_button(Msg::CloseToplevel(toplevel.handle.clone())) close_button(Msg::CloseToplevel(toplevel.handle.clone()))
] ]
.padding([0, 0, 4, 0]) .padding([0, 0, 4, 0])
.align_y(iced::Alignment::Center) .align_y(Alignment::Center)
.into(), .into(),
widget::button::custom(capture_image(toplevel.img.as_ref(), alpha)) widget::button::custom(capture_image(toplevel.img.as_ref(), alpha))
.selected( .selected(
@ -569,7 +562,7 @@ fn toplevel_preview(toplevel: &Toplevel, is_being_dragged: bool) -> cosmic::Elem
1, // Allocate width to match capture image 1, // Allocate width to match capture image
) )
//.spacing(4) //.spacing(4)
//.align_items(iced::Alignment::Center) //.align_items(Alignment::Center)
//.width(Length::Fill) //.width(Length::Fill)
.into() .into()
} }
@ -609,14 +602,14 @@ fn toplevel_previews<'a>(
//row(entries) //row(entries)
widget::mouse_area( widget::mouse_area(
widget::container(crate::widgets::toplevels(entries)) widget::container(crate::widgets::toplevels(entries))
.align_x(iced::alignment::Horizontal::Center) .align_x(Alignment::Center)
.width(width) .width(width)
.height(height) .height(height)
//.spacing(16) //.spacing(16)
.padding(12), .padding(12),
) )
.on_press(Msg::Close) .on_press(Msg::Close)
//.align_items(iced::Alignment::Center) //.align_items(Alignment::Center)
.into() .into()
} }