element: Refactor remaining libcosmic elements for blur
This commit is contained in:
parent
6c76fdaa79
commit
db06770a6b
9 changed files with 444 additions and 142 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use crate::{
|
||||
backend::render::element::AsGlowRenderer,
|
||||
fl,
|
||||
utils::iced::{IcedElement, Program},
|
||||
utils::iced::{IcedElement, IcedRenderElement, Program},
|
||||
};
|
||||
|
||||
use calloop::LoopHandle;
|
||||
|
|
@ -13,15 +14,75 @@ use cosmic::{
|
|||
theme,
|
||||
widget::{icon::from_name, text},
|
||||
};
|
||||
use smithay::utils::Size;
|
||||
use smithay::{
|
||||
backend::renderer::ImportMem,
|
||||
desktop::space::SpaceElement,
|
||||
output::Output,
|
||||
utils::{Logical, Physical, Point, Rectangle, Scale, Size},
|
||||
};
|
||||
|
||||
pub type SwapIndicator = IcedElement<SwapIndicatorInternal>;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SwapIndicator {
|
||||
location: Point<i32, Logical>,
|
||||
elem: IcedElement<SwapIndicatorInternal>,
|
||||
}
|
||||
|
||||
pub fn swap_indicator(
|
||||
evlh: LoopHandle<'static, crate::state::State>,
|
||||
theme: cosmic::Theme,
|
||||
) -> SwapIndicator {
|
||||
SwapIndicator::new(SwapIndicatorInternal, Size::from((1, 1)), evlh, theme)
|
||||
impl SwapIndicator {
|
||||
pub fn new(
|
||||
evlh: LoopHandle<'static, crate::state::State>,
|
||||
mut theme: cosmic::Theme,
|
||||
) -> SwapIndicator {
|
||||
theme.transparent = theme.cosmic().frosted_system_interface;
|
||||
SwapIndicator {
|
||||
location: Point::default(),
|
||||
elem: IcedElement::new(SwapIndicatorInternal, Size::from((1, 1)), evlh, theme),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, size: Size<i32, Logical>) {
|
||||
let minimum = self.elem.minimum_size();
|
||||
let new_size = Size::<i32, Logical>::new(size.w.min(minimum.w), size.h.min(minimum.h));
|
||||
let location = Point::new(
|
||||
size.w.saturating_sub(new_size.w) / 2,
|
||||
size.h.saturating_sub(new_size.h) / 2,
|
||||
);
|
||||
self.elem.resize(new_size);
|
||||
self.location = location;
|
||||
}
|
||||
|
||||
pub fn push_render_elements<R>(
|
||||
&self,
|
||||
renderer: &mut R,
|
||||
location: Point<i32, Physical>,
|
||||
scale: Scale<f64>,
|
||||
alpha: f32,
|
||||
push_above: &mut dyn FnMut(IcedRenderElement<R>),
|
||||
push_below: Option<&mut dyn FnMut(IcedRenderElement<R>)>,
|
||||
) where
|
||||
R: AsGlowRenderer + ImportMem,
|
||||
R::TextureId: Send + Clone + 'static,
|
||||
{
|
||||
self.elem.push_render_elements(
|
||||
renderer,
|
||||
location + self.location.to_physical_precise_round(scale),
|
||||
scale,
|
||||
alpha,
|
||||
self.elem
|
||||
.with_theme(|theme| theme.cosmic().radius_s())
|
||||
.map(|x| x.round() as u8),
|
||||
push_above,
|
||||
push_below,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn output_enter(&self, output: &Output) {
|
||||
self.elem
|
||||
.output_enter(output, Rectangle::default() /*unused*/);
|
||||
}
|
||||
|
||||
pub fn output_leave(&self, output: &Output) {
|
||||
self.elem.output_leave(output);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SwapIndicatorInternal;
|
||||
|
|
@ -69,9 +130,6 @@ impl Program for SwapIndicatorInternal {
|
|||
}))
|
||||
.width(Length::Shrink)
|
||||
.height(Length::Shrink)
|
||||
.apply(container)
|
||||
.center_x(Length::Fill)
|
||||
.center_y(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue