Fix excessive vertical height taken by button

This commit is contained in:
Ian Douglas Scott 2023-12-14 16:29:45 -08:00
parent 1f4bed40fc
commit 0cebd30600
2 changed files with 18 additions and 11 deletions

View file

@ -115,22 +115,29 @@ fn workspaces_sidebar<'a>(
layout: WorkspaceLayout, layout: WorkspaceLayout,
amount: WorkspaceAmount, amount: WorkspaceAmount,
) -> cosmic::Element<'a, Msg> { ) -> cosmic::Element<'a, Msg> {
let mut sidebar_entries: Vec<_> = workspaces let sidebar_entries = workspaces
.map(|w| workspace_sidebar_entry(w, output)) .map(|w| workspace_sidebar_entry(w, output))
.collect(); .collect();
if amount != WorkspaceAmount::Dynamic {
sidebar_entries.push(
widget::button(widget::text("New Workspace"))
.on_press(Msg::NewWorkspace)
.into(),
);
}
let axis = match layout { let axis = match layout {
WorkspaceLayout::Vertical => Axis::Vertical, WorkspaceLayout::Vertical => Axis::Vertical,
WorkspaceLayout::Horizontal => Axis::Horizontal, WorkspaceLayout::Horizontal => Axis::Horizontal,
}; };
let sidebar_entries_container = crate::widgets::workspace_bar(sidebar_entries, axis); let sidebar_entries_container = crate::widgets::workspace_bar(sidebar_entries, axis);
widget::container(sidebar_entries_container) let new_workspace_button =
widget::button(widget::text("New Workspace")).on_press(Msg::NewWorkspace);
let bar: cosmic::Element<_> = if amount != WorkspaceAmount::Dynamic {
match layout {
WorkspaceLayout::Vertical => {
column![sidebar_entries_container, new_workspace_button,].into()
}
WorkspaceLayout::Horizontal => {
row![sidebar_entries_container, new_workspace_button,].into()
}
}
} else {
sidebar_entries_container.into()
};
widget::container(bar)
.width(iced::Length::Fill) .width(iced::Length::Fill)
.height(iced::Length::Fill) .height(iced::Length::Fill)
.into() .into()

View file

@ -62,11 +62,11 @@ pub struct WorkspaceBar<'a, Msg> {
impl<'a, Msg> Widget<Msg, cosmic::Renderer> for WorkspaceBar<'a, Msg> { impl<'a, Msg> Widget<Msg, cosmic::Renderer> for WorkspaceBar<'a, Msg> {
fn width(&self) -> Length { fn width(&self) -> Length {
Length::Shrink Length::Fill
} }
fn height(&self) -> Length { fn height(&self) -> Length {
Length::Shrink Length::Fill
} }
fn layout( fn layout(