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
+181 -53
View File
@@ -1,4 +1,10 @@
#![allow(dead_code, unused_imports, unused_variables, unused_macros, unreachable_patterns)]
#![allow(
dead_code,
unused_imports,
unused_variables,
unused_macros,
unreachable_patterns
)]
use std::io::Write;
const SHADOW_RS: &str = "hcie-fx/src/emboss.rs";
@@ -39,7 +45,16 @@ fn main() {
let mut sty = hcie_protocol::effects::BevelStyle::InnerBevel;
for e in &layer.effects {
if let hcie_protocol::effects::LayerEffect::BevelEmboss {
enabled: true, depth, size, soften, angle, altitude, direction, technique, style, ..
enabled: true,
depth,
size,
soften,
angle,
altitude,
direction,
technique,
style,
..
} = e
{
d = *depth;
@@ -52,19 +67,43 @@ fn main() {
sty = style.clone();
}
}
(d, sz, sof, ang, alt,
match dir { hcie_protocol::effects::Direction::Up => hcie_fx::types::Direction::Up, _ => hcie_fx::types::Direction::Down },
match tech { hcie_protocol::effects::Technique::Smooth => hcie_fx::types::Technique::Smooth, hcie_protocol::effects::Technique::ChiselHard => hcie_fx::types::Technique::ChiselHard, _ => hcie_fx::types::Technique::ChiselSoft },
match sty {
hcie_protocol::effects::BevelStyle::InnerBevel => hcie_fx::types::BevelStyle::InnerBevel,
hcie_protocol::effects::BevelStyle::OuterBevel => hcie_fx::types::BevelStyle::OuterBevel,
hcie_protocol::effects::BevelStyle::Emboss => hcie_fx::types::BevelStyle::Emboss,
hcie_protocol::effects::BevelStyle::PillowEmboss => hcie_fx::types::BevelStyle::PillowEmboss,
_ => hcie_fx::types::BevelStyle::StrokeEmboss,
})
(
d,
sz,
sof,
ang,
alt,
match dir {
hcie_protocol::effects::Direction::Up => hcie_fx::types::Direction::Up,
_ => hcie_fx::types::Direction::Down,
},
match tech {
hcie_protocol::effects::Technique::Smooth => hcie_fx::types::Technique::Smooth,
hcie_protocol::effects::Technique::ChiselHard => {
hcie_fx::types::Technique::ChiselHard
}
_ => hcie_fx::types::Technique::ChiselSoft,
},
match sty {
hcie_protocol::effects::BevelStyle::InnerBevel => {
hcie_fx::types::BevelStyle::InnerBevel
}
hcie_protocol::effects::BevelStyle::OuterBevel => {
hcie_fx::types::BevelStyle::OuterBevel
}
hcie_protocol::effects::BevelStyle::Emboss => hcie_fx::types::BevelStyle::Emboss,
hcie_protocol::effects::BevelStyle::PillowEmboss => {
hcie_fx::types::BevelStyle::PillowEmboss
}
_ => hcie_fx::types::BevelStyle::StrokeEmboss,
},
)
};
println!("Emboss params: depth={}, size={}, soften={}, angle={}, altitude={}", depth, size, soften, angle, altitude);
println!(
"Emboss params: depth={}, size={}, soften={}, angle={}, altitude={}",
depth, size, soften, angle, altitude
);
println!("Image: {}x{}", w, h);
std::io::stdout().flush().ok();
@@ -81,28 +120,80 @@ fn main() {
println!("Phase 1: coarse grid ({} combos)", total);
std::io::stdout().flush().ok();
search(original.as_str(), before, after, &alpha, w, h, px, &ref_pixels, &layer.pixels,
depth, size, soften, angle, altitude, &direction, &technique, &style,
coarse_blur, coarse_hl, coarse_sh,
&mut best_mae, &mut best_code, &mut best_params);
search(
original.as_str(),
before,
after,
&alpha,
w,
h,
px,
&ref_pixels,
&layer.pixels,
depth,
size,
soften,
angle,
altitude,
&direction,
&technique,
&style,
coarse_blur,
coarse_hl,
coarse_sh,
&mut best_mae,
&mut best_code,
&mut best_params,
);
// Phase 2: fine grid around best
let (bb, bhl, bsh) = best_params;
let fine_blur: Vec<i32> = (bb - 4 ..= bb + 4).filter(|&v| v > 0).collect();
let fine_hl: Vec<f32> = ((bhl * 100.0 - 50.0) as i32 ..= (bhl * 100.0 + 50.0) as i32)
.step_by(5).map(|v| v as f32 / 100.0).filter(|&v| v > 0.0).collect();
let fine_sh: Vec<f32> = ((bsh * 100.0 - 50.0) as i32 ..= (bsh * 100.0 + 50.0) as i32)
.step_by(5).map(|v| v as f32 / 100.0).filter(|&v| v > 0.0).collect();
let fine_blur: Vec<i32> = (bb - 4..=bb + 4).filter(|&v| v > 0).collect();
let fine_hl: Vec<f32> = ((bhl * 100.0 - 50.0) as i32..=(bhl * 100.0 + 50.0) as i32)
.step_by(5)
.map(|v| v as f32 / 100.0)
.filter(|&v| v > 0.0)
.collect();
let fine_sh: Vec<f32> = ((bsh * 100.0 - 50.0) as i32..=(bsh * 100.0 + 50.0) as i32)
.step_by(5)
.map(|v| v as f32 / 100.0)
.filter(|&v| v > 0.0)
.collect();
println!("\nPhase 2: fine grid around best ({} x {} x {} = {} combos)",
fine_blur.len(), fine_hl.len(), fine_sh.len(),
fine_blur.len() * fine_hl.len() * fine_sh.len());
println!(
"\nPhase 2: fine grid around best ({} x {} x {} = {} combos)",
fine_blur.len(),
fine_hl.len(),
fine_sh.len(),
fine_blur.len() * fine_hl.len() * fine_sh.len()
);
std::io::stdout().flush().ok();
search(original.as_str(), before, after, &alpha, w, h, px, &ref_pixels, &layer.pixels,
depth, size, soften, angle, altitude, &direction, &technique, &style,
&fine_blur, &fine_hl, &fine_sh,
&mut best_mae, &mut best_code, &mut best_params);
search(
original.as_str(),
before,
after,
&alpha,
w,
h,
px,
&ref_pixels,
&layer.pixels,
depth,
size,
soften,
angle,
altitude,
&direction,
&technique,
&style,
&fine_blur,
&fine_hl,
&fine_sh,
&mut best_mae,
&mut best_code,
&mut best_params,
);
if best_mae < f64::MAX {
let (bb, bhl, bsh) = best_params;
@@ -167,7 +258,12 @@ fn main() {
std::fs::write(SHADOW_RS, &patched).expect("write final best");
println!("\nCompleted. Best code saved with MAE = {:.3} (blur={}, hl_scale={:.2}, sh_scale={:.2})",
best_mae, bb, bhl, bsh);
if let Ok(mut file) = std::fs::OpenOptions::new().create(true).write(true).truncate(true).open(RESULTS_FILE) {
if let Ok(mut file) = std::fs::OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(RESULTS_FILE)
{
let _ = writeln!(file, "=== Emboss Tuned ===\n Params: blur={}, hl_scale={:.2}, sh_scale={:.2}\n MAE: {:.3}",
bb, bhl, bsh, best_mae);
}
@@ -177,15 +273,28 @@ fn main() {
}
fn search(
_original: &str, _before: &str, _after: &str,
alpha: &[u8], w: u32, h: u32, px: usize, ref_pixels: &[u8],
_original: &str,
_before: &str,
_after: &str,
alpha: &[u8],
w: u32,
h: u32,
px: usize,
ref_pixels: &[u8],
src_pixels: &[u8],
depth: f32, size: f32, soften: f32, angle: f32, altitude: f32,
depth: f32,
size: f32,
soften: f32,
angle: f32,
altitude: f32,
direction: &hcie_fx::types::Direction,
technique: &hcie_fx::types::Technique,
style: &hcie_fx::types::BevelStyle,
blur_list: &[i32], hl_list: &[f32], sh_list: &[f32],
best_mae: &mut f64, _best_code: &mut String,
blur_list: &[i32],
hl_list: &[f32],
sh_list: &[f32],
best_mae: &mut f64,
_best_code: &mut String,
best_params: &mut (i32, f32, f32),
) {
let total = blur_list.len() * hl_list.len() * sh_list.len();
@@ -201,38 +310,57 @@ fn search(
}
let (hl_buf, sh_buf) = hcie_fx::tuned::generate_bevel_tuned(
alpha, w, h, depth, size, soften, angle, altitude,
direction, technique, style,
alpha, w, h, depth, size, soften, angle, altitude, direction, technique, style,
*blur, *hl_scale, *sh_scale, 1.0, 0.05,
);
let mut out = src_pixels.to_vec();
for i in 0..px {
let dst = [out[i*4], out[i*4+1], out[i*4+2], out[i*4+3]];
let hl_src = [hl_buf[i*4], hl_buf[i*4+1], hl_buf[i*4+2], hl_buf[i*4+3]];
let sh_src = [sh_buf[i*4], sh_buf[i*4+1], sh_buf[i*4+2], sh_buf[i*4+3]];
let blended = hcie_blend::blend_pixels(dst, hl_src, hcie_blend::BlendMode::Screen, 0.75);
let blended = hcie_blend::blend_pixels(blended, sh_src, hcie_blend::BlendMode::Multiply, 0.75);
out[i*4..i*4+4].copy_from_slice(&blended);
let dst = [out[i * 4], out[i * 4 + 1], out[i * 4 + 2], out[i * 4 + 3]];
let hl_src = [
hl_buf[i * 4],
hl_buf[i * 4 + 1],
hl_buf[i * 4 + 2],
hl_buf[i * 4 + 3],
];
let sh_src = [
sh_buf[i * 4],
sh_buf[i * 4 + 1],
sh_buf[i * 4 + 2],
sh_buf[i * 4 + 3],
];
let blended =
hcie_blend::blend_pixels(dst, hl_src, hcie_blend::BlendMode::Screen, 0.75);
let blended = hcie_blend::blend_pixels(
blended,
sh_src,
hcie_blend::BlendMode::Multiply,
0.75,
);
out[i * 4..i * 4 + 4].copy_from_slice(&blended);
}
let mut diff_sum = 0.0f64;
for i in 0..px {
let d = (0..4).map(|c| {
(out[i * 4 + c] as i32 - ref_pixels[i * 4 + c] as i32).abs() as f64
}).sum::<f64>();
let d = (0..4)
.map(|c| {
(out[i * 4 + c] as i32 - ref_pixels[i * 4 + c] as i32).abs() as f64
})
.sum::<f64>();
diff_sum += d;
}
let mae = diff_sum / px as f64 / 4.0;
if mae < *best_mae {
*best_mae = mae;
*best_params = (*blur, *hl_scale, *sh_scale);
println!("*** NEW BEST: {:.3} (blur={}, hl_scale={:.2}, sh_scale={:.2})",
best_mae, blur, hl_scale, sh_scale);
std::io::stdout().flush().ok();
}
*best_mae = mae;
*best_params = (*blur, *hl_scale, *sh_scale);
println!(
"*** NEW BEST: {:.3} (blur={}, hl_scale={:.2}, sh_scale={:.2})",
best_mae, blur, hl_scale, sh_scale
);
std::io::stdout().flush().ok();
}
}
}
}
}
}