Implement stable serialization and restoration for dock layouts, including auto-hidden and floating panels

- Add `persistence.rs` for stable serialization of dock layouts without runtime identifiers.
- Introduce `preview.rs` for geometry handling of dock drop previews.
- Create `sizing.rs` to manage content-aware sizing policies and constraint solving for dock panels.
- Implement `welcome.rs` to provide a welcome surface when no documents are open, featuring New and Open actions.
This commit is contained in:
2026-07-16 22:10:22 +03:00
parent 1240d25011
commit b09795ccff
72 changed files with 11898 additions and 3115 deletions
+125 -42
View File
@@ -1,13 +1,15 @@
#![allow(dead_code)]
pub use hcie_protocol::{Layer, BlendMode};
pub use hcie_brush_engine::{BrushTip, BrushStyle};
use hcie_blend::blend_pixels;
use hcie_brush_engine::{brush_spacing_pixels, jitter_offset};
pub use hcie_brush_engine::{BrushStyle, BrushTip};
pub use hcie_protocol::{BlendMode, Layer};
pub fn draw_brush_stamp(
layer: &mut Layer,
cx: f32, cy: f32,
stamp: &[u8], stamp_diameter: usize,
cx: f32,
cy: f32,
stamp: &[u8],
stamp_diameter: usize,
color: [u8; 4],
mask: Option<&[u8]>,
) {
@@ -27,15 +29,21 @@ pub fn draw_brush_stamp(
if let Some(m) = mask {
let idx = (py_u * layer.width + px_u) as usize;
if m.get(idx).copied().unwrap_or(0) == 0 { continue; }
if m.get(idx).copied().unwrap_or(0) == 0 {
continue;
}
}
let stamp_alpha = stamp[sy * stamp_diameter + sx] as f32 / 255.0;
if stamp_alpha <= 0.0 { continue; }
if stamp_alpha <= 0.0 {
continue;
}
let dst = layer.get_pixel(px_u, py_u);
let src_color: [u8; 4] = [
color[0], color[1], color[2],
color[0],
color[1],
color[2],
(color[3] as f32 * stamp_alpha).round() as u8,
];
let out = blend_pixels(dst, src_color, hcie_protocol::BlendMode::Normal.into(), 1.0);
@@ -54,7 +62,9 @@ pub fn draw_brush_stroke(
mut stroke_mask: Option<&mut [u8]>,
bg_pixels: Option<&[u8]>,
) {
if points.is_empty() { return; }
if points.is_empty() {
return;
}
let spacing = brush_spacing_pixels(tip.size, tip.spacing);
let use_color_variant = tip.color_variant && tip.variant_amount > 0.0;
@@ -89,13 +99,26 @@ pub fn draw_brush_stroke(
color
};
let first_px_color = [
first_color[0], first_color[1], first_color[2],
first_color[0],
first_color[1],
first_color[2],
(first_color[3] as f32 * first_opacity).round() as u8,
];
hcie_brush_engine::draw_dab_capped_with_stamp(
&mut layer.pixels, layer.width, layer.height,
first_x, first_y, first_size, tip.hardness, first_px_color, 1.0, is_eraser, mask,
stroke_mask.as_deref_mut(), bg_pixels, tip.opacity,
&mut layer.pixels,
layer.width,
layer.height,
first_x,
first_y,
first_size,
tip.hardness,
first_px_color,
1.0,
is_eraser,
mask,
stroke_mask.as_deref_mut(),
bg_pixels,
tip.opacity,
stamp_ref,
);
@@ -103,7 +126,9 @@ pub fn draw_brush_stroke(
let dx = p.0 - last_p.0;
let dy = p.1 - last_p.1;
let dist = (dx * dx + dy * dy).sqrt();
if dist == 0.0 { continue; }
if dist == 0.0 {
continue;
}
let steps = ((dist / spacing).max(1.0)).ceil() as i32;
let step_x = dx / steps as f32;
@@ -127,13 +152,26 @@ pub fn draw_brush_stroke(
color
};
let px_color = [
dab_color[0], dab_color[1], dab_color[2],
dab_color[0],
dab_color[1],
dab_color[2],
(dab_color[3] as f32 * pressure_opacity).round() as u8,
];
hcie_brush_engine::draw_dab_capped_with_stamp(
&mut layer.pixels, layer.width, layer.height,
final_x, final_y, effective_size, tip.hardness, px_color, 1.0, is_eraser, mask,
stroke_mask.as_deref_mut(), bg_pixels, tip.opacity,
&mut layer.pixels,
layer.width,
layer.height,
final_x,
final_y,
effective_size,
tip.hardness,
px_color,
1.0,
is_eraser,
mask,
stroke_mask.as_deref_mut(),
bg_pixels,
tip.opacity,
stamp_ref,
);
}
@@ -144,7 +182,10 @@ pub fn draw_brush_stroke(
pub fn draw_line(
layer: &mut Layer,
x0: f32, y0: f32, x1: f32, y1: f32,
x0: f32,
y0: f32,
x1: f32,
y1: f32,
color: [u8; 4],
width: f32,
mask: Option<&[u8]>,
@@ -152,7 +193,9 @@ pub fn draw_line(
let dx = x1 - x0;
let dy = y1 - y0;
let dist = (dx * dx + dy * dy).sqrt();
if dist == 0.0 { return; }
if dist == 0.0 {
return;
}
let steps = (dist * 2.0).max(1.0).ceil() as i32;
for i in 0..=steps {
@@ -165,29 +208,44 @@ pub fn draw_line(
pub fn draw_filled_circle(
layer: &mut Layer,
cx: f32, cy: f32, r: f32,
cx: f32,
cy: f32,
r: f32,
color: [u8; 4],
mask: Option<&[u8]>,
) {
let r_i = r.ceil() as i32;
for dy in -r_i..=r_i {
let py = (cy + dy as f32).round() as i32;
if py < 0 || py >= layer.height as i32 { continue; }
if py < 0 || py >= layer.height as i32 {
continue;
}
let dx_max = (r * r - dy as f32 * dy as f32).sqrt();
let dx_i = dx_max.ceil() as i32;
for dx in -dx_i..=dx_i {
let px = (cx + dx as f32).round() as i32;
if px < 0 || px >= layer.width as i32 { continue; }
if px < 0 || px >= layer.width as i32 {
continue;
}
if let Some(m) = mask {
let idx = (py as u32 * layer.width + px as u32) as usize;
if m.get(idx).copied().unwrap_or(0) == 0 { continue; }
if m.get(idx).copied().unwrap_or(0) == 0 {
continue;
}
}
let dist = ((dx as f32).powi(2) + (dy as f32).powi(2)).sqrt();
let alpha_t = 1.0 - (dist - (r - 1.0)).max(0.0).min(1.0);
if alpha_t <= 0.0 { continue; }
let src = [color[0], color[1], color[2], (color[3] as f32 * alpha_t).round() as u8];
if alpha_t <= 0.0 {
continue;
}
let src = [
color[0],
color[1],
color[2],
(color[3] as f32 * alpha_t).round() as u8,
];
let dst = layer.get_pixel(px as u32, py as u32);
let out = blend_pixels(dst, src, hcie_protocol::BlendMode::Normal.into(), 1.0);
layer.set_pixel(px as u32, py as u32, out);
@@ -197,20 +255,25 @@ pub fn draw_filled_circle(
pub fn draw_filled_rect(
layer: &mut Layer,
x1: f32, y1: f32, x2: f32, y2: f32,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
color: [u8; 4],
mask: Option<&[u8]>,
) {
let x_start = x1.min(x2).max(0.0).floor() as u32;
let x_end = x1.max(x2).min(layer.width as f32).ceil() as u32;
let x_end = x1.max(x2).min(layer.width as f32).ceil() as u32;
let y_start = y1.min(y2).max(0.0).floor() as u32;
let y_end = y1.max(y2).min(layer.height as f32).ceil() as u32;
let y_end = y1.max(y2).min(layer.height as f32).ceil() as u32;
for y in y_start..y_end {
for x in x_start..x_end {
if let Some(m) = mask {
let idx = (y * layer.width + x) as usize;
if m.get(idx).copied().unwrap_or(0) == 0 { continue; }
if m.get(idx).copied().unwrap_or(0) == 0 {
continue;
}
}
let dst = layer.get_pixel(x, y);
let out = blend_pixels(dst, color, hcie_protocol::BlendMode::Normal.into(), 1.0);
@@ -221,14 +284,17 @@ pub fn draw_filled_rect(
pub fn draw_filled_ellipse(
layer: &mut Layer,
cx: f32, cy: f32, rx: f32, ry: f32,
cx: f32,
cy: f32,
rx: f32,
ry: f32,
color: [u8; 4],
mask: Option<&[u8]>,
) {
let x_start = (cx - rx).max(0.0).floor() as u32;
let x_end = (cx + rx).min(layer.width as f32).ceil() as u32;
let x_end = (cx + rx).min(layer.width as f32).ceil() as u32;
let y_start = (cy - ry).max(0.0).floor() as u32;
let y_end = (cy + ry).min(layer.height as f32).ceil() as u32;
let y_end = (cy + ry).min(layer.height as f32).ceil() as u32;
for y in y_start..y_end {
for x in x_start..x_end {
@@ -238,7 +304,9 @@ pub fn draw_filled_ellipse(
if dist <= 1.0 {
if let Some(m) = mask {
let idx = (y * layer.width + x) as usize;
if m.get(idx).copied().unwrap_or(0) == 0 { continue; }
if m.get(idx).copied().unwrap_or(0) == 0 {
continue;
}
}
let dst = layer.get_pixel(x, y);
let out = blend_pixels(dst, color, hcie_protocol::BlendMode::Normal.into(), 1.0);
@@ -250,14 +318,17 @@ pub fn draw_filled_ellipse(
pub fn flood_fill(
layer: &mut Layer,
x: u32, y: u32,
x: u32,
y: u32,
fill_color: [u8; 4],
tolerance: u8,
mask: Option<&[u8]>,
) {
if let Some(m) = mask {
let idx = (y * layer.width + x) as usize;
if m.get(idx).copied().unwrap_or(0) == 0 { return; }
if m.get(idx).copied().unwrap_or(0) == 0 {
return;
}
}
let start_color = layer.get_pixel(x, y);
@@ -271,19 +342,31 @@ pub fn flood_fill(
while let Some((px, py)) = stack.pop() {
let c = layer.get_pixel(px, py);
if !color_match(&c, &start_color, tolerance) { continue; }
if !color_match(&c, &start_color, tolerance) {
continue;
}
if let Some(m) = mask {
let idx = (py * w + px) as usize;
if m.get(idx).copied().unwrap_or(0) == 0 { continue; }
if m.get(idx).copied().unwrap_or(0) == 0 {
continue;
}
}
layer.set_pixel(px, py, fill_color);
if px > 0 { stack.push((px - 1, py)); }
if px + 1 < w { stack.push((px + 1, py)); }
if py > 0 { stack.push((px, py - 1)); }
if py + 1 < h { stack.push((px, py + 1)); }
if px > 0 {
stack.push((px - 1, py));
}
if px + 1 < w {
stack.push((px + 1, py));
}
if py > 0 {
stack.push((px, py - 1));
}
if py + 1 < h {
stack.push((px, py + 1));
}
}
}
@@ -294,4 +377,4 @@ fn color_match(a: &[u8; 4], b: &[u8; 4], tolerance: u8) -> bool {
let diff_b = (a[2] as i32 - b[2] as i32).abs();
let diff_a = (a[3] as i32 - b[3] as i32).abs();
diff_r <= tol && diff_g <= tol && diff_b <= tol && diff_a <= tol
}
}