mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
3ace97660f
* Added the better color averaging code (tested & functional) * rustfmt * Make Color f32 0..1, clarify premul/unpremul * Fix imports and test name * Premultiply gradient colors matching CSS * Fix indentation * fixup * Add gradient image --------- Co-authored-by: K's Thinkpad <K.T.Kraft@protonmail.com>
54 lines
1.6 KiB
Rust
54 lines
1.6 KiB
Rust
use niri::render_helpers::border::BorderRenderElement;
|
|
use niri_config::{
|
|
Color, CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation,
|
|
};
|
|
use smithay::backend::renderer::element::RenderElement;
|
|
use smithay::backend::renderer::gles::GlesRenderer;
|
|
use smithay::utils::{Logical, Physical, Rectangle, Size};
|
|
|
|
use super::TestCase;
|
|
|
|
pub struct GradientSrgbLinear {
|
|
gradient_format: GradientInterpolation,
|
|
}
|
|
|
|
impl GradientSrgbLinear {
|
|
pub fn new(_size: Size<i32, Logical>) -> Self {
|
|
Self {
|
|
gradient_format: GradientInterpolation {
|
|
color_space: GradientColorSpace::SrgbLinear,
|
|
hue_interpolation: HueInterpolation::Shorter,
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
impl TestCase for GradientSrgbLinear {
|
|
fn render(
|
|
&mut self,
|
|
_renderer: &mut GlesRenderer,
|
|
size: Size<i32, Physical>,
|
|
) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {
|
|
let (a, b) = (size.w / 6, size.h / 3);
|
|
let size = (size.w - a * 2, size.h - b * 2);
|
|
let area = Rectangle::from_loc_and_size((a, b), size).to_f64();
|
|
|
|
[BorderRenderElement::new(
|
|
area.size,
|
|
Rectangle::from_loc_and_size((0., 0.), area.size),
|
|
self.gradient_format,
|
|
Color::new_unpremul(1., 0., 0., 1.),
|
|
Color::new_unpremul(0., 1., 0., 1.),
|
|
0.,
|
|
Rectangle::from_loc_and_size((0., 0.), area.size),
|
|
0.,
|
|
CornerRadius::default(),
|
|
1.,
|
|
)
|
|
.with_location(area.loc)]
|
|
.into_iter()
|
|
.map(|elem| Box::new(elem) as _)
|
|
.collect()
|
|
}
|
|
}
|