mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 09:26:43 +00:00
Merge approved PhotoCraft PR #9597: fix(ui): the layer list doesn't move with no layer selected
Preserve current module structure and port the approved source/test changes to unique current locations.
This commit is contained in:
commit
8ffc427607
2 files changed
+69
-46
No files matched your search
@@ -178,3 +178,23 @@ fn opacity_and_fill_stay_visible_but_disabled_with_no_layer_selected() {
|
||||
assert!(node.accesskit_node().is_disabled(), "{name}: should be greyed out");
|
||||
}
|
||||
}
|
||||
|
||||
/// #9546: the layer list starts at the same place with or without a selected layer. With none,
|
||||
/// the greyed-out Blend/Opacity and Lock/Fill rows sat in one disabled wrapper, which added an
|
||||
/// item gap under them: in the themes whose docks keep item spacing (Studio, Classic) the first
|
||||
/// row moved down 6 points.
|
||||
#[test]
|
||||
fn layer_rows_do_not_move_when_no_layer_is_selected() {
|
||||
for theme in [crate::theme::ThemeKind::Studio, crate::theme::ThemeKind::Classic, crate::theme::ThemeKind::ProMedium] {
|
||||
let mut h = harness();
|
||||
PhotocraftApp::setup_context(&h.ctx, theme);
|
||||
h.run_steps(4);
|
||||
let row_top = |h: &Harness<'_, PhotocraftApp>| by_role(h, "Paint", Role::Button).map(|r| r.top());
|
||||
let selected = row_top(&h);
|
||||
h.state_mut().session.execute("select.deselectLayers", json!({})).unwrap();
|
||||
h.run_steps(4);
|
||||
let none = row_top(&h);
|
||||
assert!(selected.is_some(), "{theme:?}: the layer row");
|
||||
assert_eq!(none, selected, "{theme:?}: the row moved with no layer selected");
|
||||
}
|
||||
}
|
||||
@@ -49,56 +49,59 @@ pub(super) fn opacity_row_layout(available: f32, label_width: f32, gap: f32) ->
|
||||
/// greyed out at Normal, 100% and unlocked, instead of removing them (#8880). Same layout as the
|
||||
/// active layer's rows in `layers`.
|
||||
fn inactive_blend_rows(ui: &mut egui::Ui, pro: bool) {
|
||||
ui.add_enabled_ui(false, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let opacity_label = if pro { tl!("Opacity:") } else { tl!("Opacity") };
|
||||
let (blend_width, show_opacity_label) = opacity_row_layout(ui.available_width(), body_text_width(ui, opacity_label), ui.spacing().item_spacing.x);
|
||||
let mut m = BlendMode::Normal;
|
||||
let options = blend_options(false, m);
|
||||
widgets::dropdown_wheel_hovered(ui, "blend", tl!("Blend Mode"), &mut m, &options, blend_width);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let mut o = 100.0;
|
||||
widgets::popup_value_field(ui, opacity_label, &mut o, 0.0..=100.0, "%", LAYER_PCT_W);
|
||||
if show_opacity_label {
|
||||
scrub_pct_label(ui, opacity_label, &mut o, ui.available_width());
|
||||
// Each row is disabled on its own and laid out as the active layer's rows are: a disabled
|
||||
// wrapper around both added an item gap under the Fill row, which pushed the layer list down
|
||||
// in the themes whose docks keep item spacing (#9546).
|
||||
ui.horizontal(|ui| {
|
||||
ui.disable();
|
||||
let opacity_label = if pro { tl!("Opacity:") } else { tl!("Opacity") };
|
||||
let (blend_width, show_opacity_label) = opacity_row_layout(ui.available_width(), body_text_width(ui, opacity_label), ui.spacing().item_spacing.x);
|
||||
let mut m = BlendMode::Normal;
|
||||
let options = blend_options(false, m);
|
||||
widgets::dropdown_wheel_hovered(ui, "blend", tl!("Blend Mode"), &mut m, &options, blend_width);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let mut o = 100.0;
|
||||
widgets::popup_value_field(ui, opacity_label, &mut o, 0.0..=100.0, "%", LAYER_PCT_W);
|
||||
if show_opacity_label {
|
||||
scrub_pct_label(ui, opacity_label, &mut o, ui.available_width());
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space((theme::ROW_GAP - ui.spacing().item_spacing.y).max(0.0));
|
||||
ui.horizontal(|ui| {
|
||||
ui.disable();
|
||||
let lock_label = if pro { tl!("Lock:") } else { tl!("Lock") };
|
||||
let lang = crate::i18n::current();
|
||||
let fill_label = if pro { crate::i18n::tr_ctx(lang, "layers", "Fill:") } else { crate::i18n::tr_ctx(lang, "layers", "Fill") };
|
||||
let gap = ui.spacing().item_spacing.x;
|
||||
let icons_w = if pro { 5.0 * 20.0 + gap } else { 22.0 + gap };
|
||||
let fits = body_text_width(ui, lock_label) + icons_w + body_text_width(ui, fill_label) + LAYER_PCT_W + 2.0 * gap <= ui.available_width();
|
||||
if fits {
|
||||
label(ui, lock_label);
|
||||
}
|
||||
if pro {
|
||||
ui.scope(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
for (icon, tip) in [
|
||||
("grid-3x3", tl!("Lock transparent pixels")),
|
||||
("brush", tl!("Lock image pixels")),
|
||||
("move", tl!("Lock position")),
|
||||
("scan", tl!("Prevent auto-nesting in and out of Artboards and Frames")),
|
||||
("lock", tl!("Lock all")),
|
||||
] {
|
||||
icons::button(ui, icon, 20.0, false, tip);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
icons::button(ui, "lock-open", 22.0, false, tl!("Lock layer"));
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let mut f = 100.0;
|
||||
widgets::popup_value_field(ui, fill_label, &mut f, 0.0..=100.0, "%", LAYER_PCT_W);
|
||||
scrub_pct_label(ui, fill_label, &mut f, ui.available_width());
|
||||
});
|
||||
ui.add_space((theme::ROW_GAP - ui.spacing().item_spacing.y).max(0.0));
|
||||
ui.horizontal(|ui| {
|
||||
let lock_label = if pro { tl!("Lock:") } else { tl!("Lock") };
|
||||
let lang = crate::i18n::current();
|
||||
let fill_label = if pro { crate::i18n::tr_ctx(lang, "layers", "Fill:") } else { crate::i18n::tr_ctx(lang, "layers", "Fill") };
|
||||
let gap = ui.spacing().item_spacing.x;
|
||||
let icons_w = if pro { 5.0 * 20.0 + gap } else { 22.0 + gap };
|
||||
let fits = body_text_width(ui, lock_label) + icons_w + body_text_width(ui, fill_label) + LAYER_PCT_W + 2.0 * gap <= ui.available_width();
|
||||
if fits {
|
||||
label(ui, lock_label);
|
||||
}
|
||||
if pro {
|
||||
ui.scope(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
for (icon, tip) in [
|
||||
("grid-3x3", tl!("Lock transparent pixels")),
|
||||
("brush", tl!("Lock image pixels")),
|
||||
("move", tl!("Lock position")),
|
||||
("scan", tl!("Prevent auto-nesting in and out of Artboards and Frames")),
|
||||
("lock", tl!("Lock all")),
|
||||
] {
|
||||
icons::button(ui, icon, 20.0, false, tip);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
icons::button(ui, "lock-open", 22.0, false, tl!("Lock layer"));
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let mut f = 100.0;
|
||||
widgets::popup_value_field(ui, fill_label, &mut f, 0.0..=100.0, "%", LAYER_PCT_W);
|
||||
scrub_pct_label(ui, fill_label, &mut f, ui.available_width());
|
||||
});
|
||||
});
|
||||
ui.add_space(2.0);
|
||||
});
|
||||
ui.add_space(2.0);
|
||||
}
|
||||
|
||||
pub(super) fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
|
||||
Reference in new issue
Block a user