Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

M4: Effects panel (blend mode, opacity, drop shadow settings)

Brandon Thomas270bb83831c9
diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs
index 70a997c5d..c672f1784 100644
--- a/crates/ui-egui/src/dock.rs
+++ b/crates/ui-egui/src/dock.rs
@@ -15,6 +15,7 @@ pub const ICON_PANELS: &[(&str, &str, &str)] = &[
("stroke", "Stroke", "panel-stroke"),
("swatches", "Swatches", "panel-swatches"),
("color", "Color", "panel-color"),
+ ("effects", "Effects", "panel-effects"),
("paragraphStyles", "Paragraph Styles", "panel-pstyles"),
("characterStyles", "Character Styles", "panel-cstyles"),
("character", "Character", "panel-character"),
@@ -114,6 +115,7 @@ pub fn flyout(app: &mut DesignApp, ctx: &egui::Context) {
"textWrap" => panels::properties::wrap_panel(app, ui),
"align" => panels::properties::align_panel(app, ui),
"color" => panels::swatches::color_panel(app, ui),
+ "effects" => panels::properties::effects_panel(app, ui),
"links" => panels::properties::links_panel(app, ui),
_ => panels::properties::info_panel(app, ui),
});
diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs
index 0094e2a42..cb08e0988 100644
--- a/crates/ui-egui/src/panels/properties.rs
+++ b/crates/ui-egui/src/panels/properties.rs
@@ -594,3 +594,71 @@ pub fn info_panel(app: &mut DesignApp, ui: &mut egui::Ui) {
}
ui.label(egui::RichText::new(format!("Render {:.1} ms", app.perf.render_ms)).color(t.text_dim));
}
+
+pub fn effects_panel(app: &mut DesignApp, ui: &mut egui::Ui) {
+ let Some(st) = app.session.active() else { return };
+ let Some(it) = st.selection.items.first().and_then(|i| st.doc.item(*i)).cloned() else {
+ ui.label("Select an object.");
+ return;
+ };
+ use designcraft_color::BlendMode as B;
+ const MODES: [B; 16] = [
+ B::Normal,
+ B::Multiply,
+ B::Screen,
+ B::Overlay,
+ B::SoftLight,
+ B::HardLight,
+ B::ColorDodge,
+ B::ColorBurn,
+ B::Darken,
+ B::Lighten,
+ B::Difference,
+ B::Exclusion,
+ B::Hue,
+ B::Saturation,
+ B::Color,
+ B::Luminosity,
+ ];
+ ui.horizontal(|ui| {
+ egui::ComboBox::from_id_salt("blend").selected_text(it.blend.label()).width(130.0).show_ui(ui, |ui| {
+ for m in MODES {
+ if ui.selectable_label(m == it.blend, m.label()).clicked() {
+ let _ = app.run("object.opacity", json!({"opacity": it.opacity, "blend": m}));
+ }
+ }
+ });
+ caption(ui, "Opacity");
+ if let Some(v) = number(ui, "eop", Some(it.opacity as f64 * 100.0), "%", 46.0, 0) {
+ let _ = app.run("object.opacity", json!({"opacity": (v / 100.0).clamp(0.0, 1.0)}));
+ }
+ });
+ divider(ui);
+ let ds = it.effects.drop_shadow.clone();
+ let mut on = ds.on;
+ if ui.checkbox(&mut on, "Drop Shadow").changed() {
+ let _ = app.run("object.dropShadow", json!({"on": on}));
+ }
+ if ds.on {
+ egui::Grid::new("dsg").num_columns(4).spacing(vec2(6.0, 4.0)).show(ui, |ui| {
+ caption(ui, "Distance");
+ if let Some(v) = number(ui, "dsd", Some(ds.distance), " pt", 56.0, 1) {
+ let _ = app.run("object.dropShadow", json!({"on": true, "distance": v}));
+ }
+ caption(ui, "Angle");
+ if let Some(v) = number(ui, "dsa", Some(ds.angle), "°", 50.0, 0) {
+ let _ = app.run("object.dropShadow", json!({"on": true, "angle": v}));
+ }
+ ui.end_row();
+ caption(ui, "Opacity");
+ if let Some(v) = number(ui, "dso", Some(ds.opacity as f64 * 100.0), "%", 56.0, 0) {
+ let _ = app.run("object.dropShadow", json!({"on": true, "opacity": v / 100.0}));
+ }
+ caption(ui, "Size");
+ if let Some(v) = number(ui, "dss", Some(ds.size), " pt", 50.0, 1) {
+ let _ = app.run("object.dropShadow", json!({"on": true, "size": v}));
+ }
+ ui.end_row();
+ });
+ }
+}