fix(view): scaling behavior

This should prevent the pin button and text being getting pushed out with horizontal workspaces and when scaling vertical workspaces.
This commit is contained in:
Vukašin Vojinović 2025-04-30 12:41:53 +02:00 committed by Ian Douglas Scott
parent edd75b8121
commit f76e547540

View file

@ -238,10 +238,11 @@ 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 (image, image_height, image_width) = if let Some(img) = workspace.img.as_ref() { let (mut 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
@ -256,20 +257,19 @@ fn workspace_item(
(img.width, img.height) (img.width, img.height)
}; };
let fixed_size = 126.0;
if effective_width > effective_height { if effective_width > effective_height {
( (
// 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(126.0),
fixed_size, 126.0,
fixed_size * effective_width as f32 / effective_height as f32, 126.0 * 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(160),
fixed_size * effective_height as f32 / effective_width as f32, 160.0 * effective_height as f32 / effective_width as f32,
fixed_size, 160.0,
) )
} }
} else { } else {
@ -282,32 +282,27 @@ fn workspace_item(
) )
}; };
let workspace_name = row![ let workspace_footer = row![
widget::horizontal_space().width(Length::Fixed(if image_width < 160.0 { widget::horizontal_space().width(Length::Fixed(32.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)
.align_x(Alignment::Center), .align_x(Alignment::Center),
pin_button(workspace), pin_button(workspace),
]; ];
let content = crate::widgets::size_cross_nth( // Needed to prevent footer content getting pushed out when scaling on Vertical layout
vec![ if layout == WorkspaceLayout::Vertical {
image.height(Length::Fill).into(), image = image.height(Length::Fill);
iced::widget::Space::with_height(4.0).into(), }
workspace_name.into(), let content = column![image, workspace_footer]
], .spacing(4)
Axis::Vertical, .align_x(Alignment::Center)
0, // Size container to match image size .apply(widget::container)
) .max_height(image_height + 26.0)
.apply(widget::container) .max_width(image_width);
.max_height(image_height + 26.0);
let is_active = workspace.is_active() && !has_workspace_drag; let is_active = workspace.is_active() && !has_workspace_drag;
// TODO editable name? // TODO editable name?
@ -341,6 +336,7 @@ 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(),
@ -355,7 +351,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, true, true), workspace_item(other_workspace, other_output, layout, true, true),
placeholder, placeholder,
); );
dnd_destination_for_target(drop_target, placeholder.into(), Msg::DndWorkspaceDrop) dnd_destination_for_target(drop_target, placeholder.into(), Msg::DndWorkspaceDrop)
@ -364,6 +360,7 @@ 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,7 +372,13 @@ fn workspace_sidebar_entry<'a>(
iced::mouse::Interaction::Idle iced::mouse::Interaction::Idle
}; };
*/ */
let item = workspace_item(workspace, output, is_drop_target, has_workspace_drag); let item = workspace_item(
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(),
@ -406,7 +409,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, false, true), move || workspace_item(&workspace_clone, &output_clone, layout, false, true),
) )
} else { } else {
destination destination
@ -433,7 +436,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, false, true), move || workspace_item(&workspace_clone, &output_clone, layout, false, true),
); );
sidebar_entries.push(source); sidebar_entries.push(source);
continue; continue;
@ -459,11 +462,12 @@ 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)); sidebar_entries.push(workspace_drag_placeholder(workspace, output, layout));
} }
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(),