Move drag surface view into a function
It's a bit clearer this way.
This commit is contained in:
parent
8e7e81bdcf
commit
e9e6cc275b
2 changed files with 37 additions and 28 deletions
24
src/main.rs
24
src/main.rs
|
|
@ -659,28 +659,8 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
if let Some((drag_id, drag_surface, size)) = &self.drag_surface {
|
if let Some((drag_id, drag_surface, size)) = &self.drag_surface {
|
||||||
if drag_id == &id {
|
if drag_id == &id {
|
||||||
match drag_surface {
|
if let Some(element) = view::drag_surface(self, drag_surface, *size) {
|
||||||
DragSurface::Workspace { handle, output } => {
|
return element;
|
||||||
if let Some(workspace) =
|
|
||||||
self.workspaces.iter().find(|x| &x.handle == handle)
|
|
||||||
{
|
|
||||||
let item = view::workspace_item(workspace, output, false);
|
|
||||||
return widget::container(item)
|
|
||||||
.height(iced::Length::Fixed(size.height))
|
|
||||||
.width(iced::Length::Fixed(size.width))
|
|
||||||
.into();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DragSurface::Toplevel { handle, .. } => {
|
|
||||||
if let Some(toplevel) = self.toplevels.iter().find(|x| &x.handle == handle)
|
|
||||||
{
|
|
||||||
let item = view::toplevel_preview(toplevel, true);
|
|
||||||
return widget::container(item)
|
|
||||||
.height(iced::Length::Fixed(size.height))
|
|
||||||
.width(iced::Length::Fixed(size.width))
|
|
||||||
.into();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use cosmic::{
|
||||||
self,
|
self,
|
||||||
advanced::layout::flex::Axis,
|
advanced::layout::flex::Axis,
|
||||||
widget::{column, row},
|
widget::{column, row},
|
||||||
Border,
|
Border, Size,
|
||||||
},
|
},
|
||||||
iced_core::Shadow,
|
iced_core::Shadow,
|
||||||
iced_sctk::subsurface_widget::Subsurface,
|
iced_sctk::subsurface_widget::Subsurface,
|
||||||
|
|
@ -83,6 +83,38 @@ pub(crate) fn layer_surface<'a>(
|
||||||
crate::widgets::image_bg(container, bg).into()
|
crate::widgets::image_bg(container, bg).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn drag_surface<'a>(
|
||||||
|
app: &'a App,
|
||||||
|
drag_surface: &DragSurface,
|
||||||
|
size: Size,
|
||||||
|
) -> Option<cosmic::Element<'a, Msg>> {
|
||||||
|
match drag_surface {
|
||||||
|
DragSurface::Workspace { handle, output } => {
|
||||||
|
if let Some(workspace) = app.workspaces.iter().find(|x| &x.handle == handle) {
|
||||||
|
let item = workspace_item(workspace, output, false);
|
||||||
|
return Some(
|
||||||
|
widget::container(item)
|
||||||
|
.height(iced::Length::Fixed(size.height))
|
||||||
|
.width(iced::Length::Fixed(size.width))
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DragSurface::Toplevel { handle, .. } => {
|
||||||
|
if let Some(toplevel) = app.toplevels.iter().find(|x| &x.handle == handle) {
|
||||||
|
let item = toplevel_preview(toplevel, true);
|
||||||
|
return Some(
|
||||||
|
widget::container(item)
|
||||||
|
.height(iced::Length::Fixed(size.height))
|
||||||
|
.width(iced::Length::Fixed(size.width))
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
fn close_button(on_press: Msg) -> cosmic::Element<'static, Msg> {
|
fn close_button(on_press: Msg) -> cosmic::Element<'static, Msg> {
|
||||||
widget::container(
|
widget::container(
|
||||||
widget::button(widget::icon::from_name("window-close-symbolic").size(16))
|
widget::button(widget::icon::from_name("window-close-symbolic").size(16))
|
||||||
|
|
@ -112,7 +144,7 @@ fn workspace_item_appearance(
|
||||||
appearance
|
appearance
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn workspace_item<'a>(
|
fn workspace_item<'a>(
|
||||||
workspace: &'a Workspace,
|
workspace: &'a Workspace,
|
||||||
output: &wl_output::WlOutput,
|
output: &wl_output::WlOutput,
|
||||||
is_drop_target: bool,
|
is_drop_target: bool,
|
||||||
|
|
@ -255,10 +287,7 @@ fn workspaces_sidebar<'a>(
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn toplevel_preview(
|
fn toplevel_preview(toplevel: &Toplevel, is_being_dragged: bool) -> cosmic::Element<Msg> {
|
||||||
toplevel: &Toplevel,
|
|
||||||
is_being_dragged: bool,
|
|
||||||
) -> cosmic::Element<Msg> {
|
|
||||||
let label = widget::text(&toplevel.info.title);
|
let label = widget::text(&toplevel.info.title);
|
||||||
let label = if let Some(icon) = &toplevel.icon {
|
let label = if let Some(icon) = &toplevel.icon {
|
||||||
row![widget::icon(widget::icon::from_path(icon.clone())), label].spacing(4)
|
row![widget::icon(widget::icon::from_path(icon.clone())), label].spacing(4)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue