Skip to content

Commit

Permalink
wip: Shadows in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
last-partizan committed Jul 6, 2022
1 parent 53581ae commit 0139c6f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
40 changes: 33 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use smithay_client_toolkit::{
};

pub mod theme;
use theme::{ColorTheme, BORDER_SIZE, HEADER_SIZE};
use theme::{ColorTheme, GradientPostion, BORDER_SIZE, HEADER_SIZE};

mod buttons;
use buttons::{ButtonKind, Buttons};
Expand Down Expand Up @@ -407,6 +407,18 @@ impl AdwaitaFrame {
) {
let mut pixmap = PixmapMut::from_bytes(canvas, header_width, header_height)?;
pixmap.fill(Color::TRANSPARENT);
// FIXME: Almost works
pixmap.fill_rect(
Rect::from_xywh(
BORDER_SIZE as f32,
0.0,
(header_width - BORDER_SIZE * 2) as f32,
BORDER_SIZE as f32,
)?,
&colors.border_gradient(GradientPostion::TOP),
Transform::identity(),
None,
);

if let Some(title_text) = self.title_text.as_mut() {
title_text.update_scale(header_scale);
Expand Down Expand Up @@ -479,17 +491,19 @@ impl AdwaitaFrame {

let size = 1.0;
let x = BORDER_SIZE as f32 * bottom_scale as f32 - 1.0;
let y = w as f32 - BORDER_SIZE as f32 * 2.0 * bottom_scale as f32 + 2.0;
pixmap.fill_rect(
Rect::from_xywh(
x,
0.0,
w as f32 - BORDER_SIZE as f32 * 2.0 * bottom_scale as f32 + 2.0,
size,
)?,
Rect::from_xywh(x, 0.0, y, size)?,
&border_paint,
Transform::identity(),
None,
);
pixmap.fill_rect(
Rect::from_xywh(x, 0.0, y, BORDER_SIZE as f32)?,
&colors.border_gradient(GradientPostion::BOTTOM),
Transform::identity(),
None,
);

decoration
.bottom
Expand Down Expand Up @@ -538,6 +552,12 @@ impl AdwaitaFrame {
Transform::identity(),
None,
);
pixmap.fill_rect(
Rect::from_xywh(0.0, 0.0, BORDER_SIZE as f32, h as f32)?,
&colors.border_gradient(GradientPostion::LEFT),
Transform::identity(),
None,
);

decoration
.left
Expand Down Expand Up @@ -581,6 +601,12 @@ impl AdwaitaFrame {
Transform::identity(),
None,
);
pixmap.fill_rect(
Rect::from_xywh(0.0, 0.0, BORDER_SIZE as f32, h as f32)?,
&colors.border_gradient(GradientPostion::RIGHT),
Transform::identity(),
None,
);

decoration.right.subsurface.set_position(width as i32, 0);
decoration.right.surface.attach(Some(&buffer), 0, 0);
Expand Down
43 changes: 41 additions & 2 deletions src/theme.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use smithay_client_toolkit::window::WindowState;

pub use tiny_skia::Color;
use tiny_skia::{Paint, Shader};
use tiny_skia::{GradientStop, LinearGradient, Paint, Point, Shader, SpreadMode, Transform};

pub(crate) const BORDER_SIZE: u32 = 10;
pub(crate) const BORDER_SIZE: u32 = 20;
pub(crate) const HEADER_SIZE: u32 = 35;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -54,6 +54,45 @@ impl ColorMap {
..Default::default()
}
}

pub(crate) fn border_gradient(&self, pos: GradientPostion) -> Paint {
let h = BORDER_SIZE;
let (start_x, start_y, stop_x, stop_y) = match pos {
GradientPostion::LEFT => (h, 0, 0, 0),
GradientPostion::TOP => (0, h, 0, 0),
GradientPostion::RIGHT => (0, 0, h, 0),
GradientPostion::BOTTOM => (0, 0, 0, h),
};
let shadow = LinearGradient::new(
Point {
x: start_x as f32,
y: start_y as f32,
},
Point {
x: stop_x as f32,
y: stop_y as f32,
},
vec![
GradientStop::new(0.0, Color::from_rgba(0.0, 0.0, 0.0, 0.3).unwrap()),
GradientStop::new(1.0, Color::TRANSPARENT),
],
SpreadMode::Repeat,
Transform::identity(),
)
.unwrap();

Paint {
shader: shadow,
..Default::default()
}
}
}

pub enum GradientPostion {
LEFT,
TOP,
RIGHT,
BOTTOM,
}

#[derive(Debug, Clone)]
Expand Down

0 comments on commit 0139c6f

Please sign in to comment.