mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-26 09:20:46 +01:00
Properties: the panel keeps its scroll place per layer, titles an effect by its type, and an empty panel shows its note
This commit is contained in:
1 parent
c6ab3aa586
commit
d31604cc97
9 files changed
+145
-20
No files matched your search
@@ -328,7 +328,7 @@ impl Default for ToolState {
|
||||
}
|
||||
|
||||
/// What is selected in the layer stack.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
|
||||
pub enum StackTarget {
|
||||
#[default]
|
||||
Content,
|
||||
|
||||
+42
-15
@@ -1798,7 +1798,8 @@ pub(crate) fn properties_title(app: &TextureCraftApp) -> String {
|
||||
let what = match (app.session.selected_layer().and_then(|id| project.layers.get(&id)), app.session.target) {
|
||||
// Polygon fill keeps its own properties wherever it can fill
|
||||
_ if tool == Tool::PolygonFill && tool_usable => tr(tool.label()).to_string(),
|
||||
(Some(_), StackTarget::Effect(effect)) => project.effect(effect).map(|(_, found)| found.name.clone()).unwrap_or_default(),
|
||||
// The effect's type, not its own name (every filter reads "Filter")
|
||||
(Some(_), StackTarget::Effect(effect)) => project.effect(effect).map(|(_, found)| tr(effect_type_label(&found.kind)).to_string()).unwrap_or_default(),
|
||||
(Some(layer), StackTarget::Content) if matches!(layer.kind, LayerKind::Fill(_)) => tr("Fill").to_string(),
|
||||
(Some(layer), StackTarget::Content) if layer.is_group() => tr("Folder").to_string(),
|
||||
(Some(layer), StackTarget::Content) if layer.instance_source().is_some() => tr("Instance").to_string(),
|
||||
@@ -1809,44 +1810,70 @@ pub(crate) fn properties_title(app: &TextureCraftApp) -> String {
|
||||
format!("{} - {what}", tr("Properties"))
|
||||
}
|
||||
|
||||
/// The name of effect type `kind` in the Properties title
|
||||
fn effect_type_label(kind: &EffectKind) -> &'static str {
|
||||
match kind {
|
||||
EffectKind::Filter(_) => n_("Filter"),
|
||||
other => other.name(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn properties(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
// A floating scroll bar would cover the right-aligned slider values and section reset icons
|
||||
ui.spacing_mut().scroll = egui::style::ScrollStyle::solid();
|
||||
egui::ScrollArea::vertical().id_salt("props").auto_shrink([false, false]).show(ui, |ui| properties_contents(app, ui));
|
||||
egui::ScrollArea::vertical().id_salt(("props", properties_place(app))).auto_shrink([false, false]).show(ui, |ui| properties_contents(app, ui));
|
||||
}
|
||||
|
||||
/// What the docked Properties list keeps its own scroll place for: the selected layer and the part of it edited, none for the tool
|
||||
fn properties_place(app: &TextureCraftApp) -> Option<(LayerId, StackTarget)> {
|
||||
// A short panel in between would clamp a shared place back to the top; a greyed tool shows the layer's own sheet
|
||||
if app.session.tool.tool == Tool::PolygonFill && app.session.tool_usable(Tool::PolygonFill) {
|
||||
return None;
|
||||
}
|
||||
|
||||
app.session.selected_layer().map(|layer| (layer, app.session.target))
|
||||
}
|
||||
|
||||
/// Room around the Properties rows not yet laid out by the property sheet: the sheet's side padding, so both start under the panel's name
|
||||
const LEGACY_BODY_MARGIN: egui::Margin = egui::Margin::symmetric(crate::property_sheet::PAD as i8, 4);
|
||||
|
||||
/// Lays out `body` with the other panels' margin
|
||||
fn legacy_body(ui: &mut Ui, body: impl FnOnce(&mut Ui)) {
|
||||
egui::Frame::new().inner_margin(LEGACY_BODY_MARGIN).show(ui, body);
|
||||
}
|
||||
|
||||
/// What the Properties panel edits: polygon fill's own settings, the selected effect, fill, folder, instance or mask, else the tool (or a hint to select a layer when it can't act)
|
||||
pub(crate) fn properties_contents(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
let tokens = Tokens::get(ui.ctx());
|
||||
if !app.session.project_open {
|
||||
ui.label(RichText::new(tr("No properties found")).color(tokens.text_dim));
|
||||
crate::widgets::empty_note(ui, tr("No properties found"));
|
||||
return;
|
||||
}
|
||||
|
||||
let selected = app.session.selected_layer().and_then(|id| app.session.doc.project.layers.get(&id).cloned());
|
||||
let tool = app.session.tool.tool;
|
||||
let tool_usable = app.session.tool_usable(tool);
|
||||
let tokens = Tokens::get(ui.ctx());
|
||||
|
||||
match (&selected, app.session.target) {
|
||||
// Polygon fill shows its own settings and says what it fills into, wherever it can fill
|
||||
_ if tool == Tool::PolygonFill && tool_usable => polygon_fill_properties(app, ui),
|
||||
(Some(layer), StackTarget::Effect(effect)) => effect_properties(app, ui, layer, effect),
|
||||
(Some(layer), StackTarget::Content) if matches!(layer.kind, LayerKind::Fill(_)) => fill_properties(app, ui, layer),
|
||||
(Some(layer), StackTarget::Content) if layer.is_group() => {
|
||||
_ if tool == Tool::PolygonFill && tool_usable => legacy_body(ui, |ui| polygon_fill_properties(app, ui)),
|
||||
(Some(layer), StackTarget::Effect(effect)) => legacy_body(ui, |ui| effect_properties(app, ui, layer, effect)),
|
||||
(Some(layer), StackTarget::Content) if matches!(layer.kind, LayerKind::Fill(_)) => legacy_body(ui, |ui| fill_properties(app, ui, layer)),
|
||||
(Some(layer), StackTarget::Content) if layer.is_group() => legacy_body(ui, |ui| {
|
||||
ui.label(RichText::new(tr("A folder blends its children (pass-through). Set per-channel opacity in the layer rows.")).color(tokens.text_dim));
|
||||
}
|
||||
(Some(layer), StackTarget::Content) if layer.instance_source().is_some() => instance_properties(app, ui, layer),
|
||||
(Some(layer), StackTarget::Mask) => {
|
||||
}),
|
||||
(Some(layer), StackTarget::Content) if layer.instance_source().is_some() => legacy_body(ui, |ui| instance_properties(app, ui, layer)),
|
||||
(Some(layer), StackTarget::Mask) => legacy_body(ui, |ui| {
|
||||
height_mask_section(app, ui, layer);
|
||||
if tool_usable {
|
||||
ui.separator();
|
||||
tool_properties(app, ui);
|
||||
}
|
||||
}
|
||||
(None, _) if !tool_usable => {
|
||||
}),
|
||||
(None, _) if !tool_usable => legacy_body(ui, |ui| {
|
||||
ui.label(RichText::new(tr("Select a layer to paint on")).color(tokens.text_dim));
|
||||
}
|
||||
_ => tool_properties(app, ui),
|
||||
}),
|
||||
_ => legacy_body(ui, |ui| tool_properties(app, ui)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ mod path_surface_cache;
|
||||
mod pattern_panel;
|
||||
mod pattern_target;
|
||||
pub mod pbr_import;
|
||||
mod popup_drag;
|
||||
mod preview_image;
|
||||
mod preview_request;
|
||||
mod preview_worker;
|
||||
@@ -76,6 +77,7 @@ pub mod profile;
|
||||
mod project_config;
|
||||
pub mod project_form;
|
||||
pub mod properties_popup;
|
||||
mod property_sheet;
|
||||
mod query_field;
|
||||
mod rail_popup;
|
||||
pub mod render_mode;
|
||||
@@ -1053,6 +1055,9 @@ impl eframe::App for TextureCraftApp {
|
||||
self.ui.mode = state::Mode::Painting;
|
||||
}
|
||||
|
||||
// Before any popup draws, so one a drag closes is gone from this frame
|
||||
popup_drag::close_on_drag_outside(&ctx);
|
||||
|
||||
if !self.ui.hide_ui {
|
||||
titlebar::show(self, ui);
|
||||
banner(self, ui);
|
||||
|
||||
@@ -495,6 +495,22 @@ fn gradient(painter: &egui::Painter, rect: egui::Rect, rgb: impl Fn(f32, f32) ->
|
||||
painter.add(mesh);
|
||||
}
|
||||
|
||||
/// From a panel body's top to its empty note's lettering: the reference's gap under the header's name
|
||||
const EMPTY_NOTE_TOP: f32 = 9.0;
|
||||
|
||||
/// The line an empty panel shows instead of its contents ("No properties found"): under the header at its name's left edge, greyed as the disabled toolbar icons are
|
||||
pub(crate) fn empty_note(ui: &mut Ui, text: &str) {
|
||||
let tokens = Tokens::get(ui.ctx());
|
||||
ui.add_enabled_ui(false, |ui| {
|
||||
let font = egui::TextStyle::Body.resolve(ui.style());
|
||||
let galley = ui.painter().layout_no_wrap(text.to_owned(), font, tokens.text);
|
||||
let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), EMPTY_NOTE_TOP + galley.size().y), Sense::hover());
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Label, false, text));
|
||||
let at = egui::pos2(rect.left() + crate::docking::HEADER_TITLE_LEFT, rect.top() + EMPTY_NOTE_TOP);
|
||||
ui.painter().galley(at, galley, tokens.text);
|
||||
});
|
||||
}
|
||||
|
||||
/// Panel title row with optional trailing content.
|
||||
pub fn panel_header(ui: &mut Ui, title: &str, trailing: impl FnOnce(&mut Ui)) {
|
||||
ui.horizontal(|ui| {
|
||||
|
||||
@@ -105,8 +105,8 @@ fn the_empty_views_keep_the_view_picker_and_drop_the_camera_picker() {
|
||||
|
||||
assert!(!has_camera_picker(&empty), "no camera picker");
|
||||
|
||||
// The picker shows "Material" right of the tool shelf and the Assets panel: one per view in the split layout
|
||||
let pickers = painted(&empty).iter().filter(|(text, x)| text == "Material" && *x > 400.0).count();
|
||||
// The picker shows "Material" right of the tool shelf and the Assets panel and left of the right column: one per view in the split layout
|
||||
let pickers = painted(&empty).iter().filter(|(text, x)| text == "Material" && (300.0..1200.0).contains(x)).count();
|
||||
|
||||
assert_eq!(pickers, 2, "each of the two views keeps its view picker");
|
||||
|
||||
@@ -393,3 +393,12 @@ fn close_releases_the_layer_thumbnail_snapshot() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_empty_properties_note_starts_at_its_header_names_left_edge() {
|
||||
let harness = empty();
|
||||
let texts = painted(&harness);
|
||||
let left_of = |wanted: &str| texts.iter().find(|(text, _)| text == wanted).map(|(_, left)| *left).unwrap_or_else(|| panic!("{wanted} is painted"));
|
||||
|
||||
assert_eq!(left_of("No properties found"), left_of("PROPERTIES"));
|
||||
}
|
||||
@@ -20,8 +20,18 @@ fn harness() -> (Harness<'static, TextureCraftApp>, [LayerId; 4]) {
|
||||
(h, rows)
|
||||
}
|
||||
|
||||
/// Frames for a scroll to bring a row into view (it animates)
|
||||
const SCROLL_FRAMES: usize = 25;
|
||||
|
||||
/// Scrolls the row `name` into view: six rows overflow the Layers panel
|
||||
fn show_row(h: &mut Harness<'_, TextureCraftApp>, name: &str) {
|
||||
h.get_by_label(name).scroll_to_me();
|
||||
h.run_steps(SCROLL_FRAMES);
|
||||
}
|
||||
|
||||
/// Click the row `name` while `modifiers` are held (pressed before and released after the click).
|
||||
fn click(h: &mut Harness<'_, TextureCraftApp>, name: &str, modifiers: Modifiers) {
|
||||
show_row(h, name);
|
||||
let at: Pos2 = h.get_by_label(name).rect().center();
|
||||
h.event(Event::PointerMoved(at));
|
||||
h.event(Event::ModifiersChanged(modifiers));
|
||||
@@ -161,6 +171,7 @@ fn ctrl_a_leaves_text_fields_and_other_panels_alone() {
|
||||
|
||||
/// Right-click the row `name` and choose the menu item whose label starts with `item`.
|
||||
fn row_menu(h: &mut Harness<'_, TextureCraftApp>, name: &str, item: &str) {
|
||||
show_row(h, name);
|
||||
h.get_by_label(name).click_secondary();
|
||||
h.run_steps(3);
|
||||
h.get_by(|node| node.label().is_some_and(|label| label.starts_with(item))).click();
|
||||
|
||||
@@ -107,9 +107,17 @@ fn deeply_nested_effect_visibility_is_reachable_in_a_narrow_panel() {
|
||||
}
|
||||
let mut workspace = h.state().ui.dock.workspace().clone();
|
||||
let Some(Node::Split { second, .. }) = workspace.layout.root.as_mut() else { panic!("default columns") };
|
||||
let Node::Split { size, .. } = second.as_mut() else { panic!("viewport and right column") };
|
||||
let Node::Split { size, second: column, .. } = second.as_mut() else { panic!("viewport and right column") };
|
||||
*size = SplitSize::Ratio(0.99);
|
||||
|
||||
// Layers tall enough for the whole nested stack: the default gives most of the column to Properties
|
||||
let Node::Split { second: below_sets, .. } = column.as_mut() else { panic!("texture sets and the rest") };
|
||||
let Node::Split { size: layers_share, .. } = below_sets.as_mut() else { panic!("layers and properties") };
|
||||
*layers_share = SplitSize::Ratio(0.9);
|
||||
h.state_mut().ui.dock = Dock::from_value(serde_json::to_value(workspace).unwrap());
|
||||
|
||||
// Properties holds its column at its minimum width: without it the column narrows as far as Layers allows
|
||||
h.state_mut().ui.dock.close(texturecraft_ui_egui::docking::Panel::Properties);
|
||||
h.run_steps(4);
|
||||
|
||||
let row = h.get_by_label("Effect A").rect();
|
||||
|
||||
@@ -52,11 +52,14 @@ mod nav_buttons;
|
||||
mod new_project_baked_maps;
|
||||
mod new_project_window;
|
||||
mod output_templates;
|
||||
mod panel_header;
|
||||
mod path_in_view;
|
||||
mod path_list;
|
||||
mod pen_pressure;
|
||||
mod polygon_fill;
|
||||
mod popup_press_close;
|
||||
mod project_config;
|
||||
mod properties_min_width;
|
||||
mod properties_popup;
|
||||
mod rail;
|
||||
mod reference_order;
|
||||
@@ -93,3 +96,49 @@ mod stencil;
|
||||
mod symmetry;
|
||||
mod symmetry_2d;
|
||||
mod tile_generator_panel;
|
||||
|
||||
/// eframe's in-memory storage, shared by the tests that save and restore the UI state
|
||||
#[path = "../../src/ui_state_store/memory_storage.rs"]
|
||||
mod memory_storage;
|
||||
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use texturecraft_ui_egui::TextureCraftApp;
|
||||
|
||||
/// Window of the Properties tests: tall enough that a whole sheet shows without scrolling
|
||||
const PROPERTIES_WINDOW: egui::Vec2 = egui::vec2(1600.0, 1400.0);
|
||||
|
||||
// Small texture and bake sizes keep the sample session fast; the panels don't depend on them
|
||||
const TEXTURE_RESOLUTION: u32 = 256;
|
||||
const BAKE_RESOLUTION: u32 = 64;
|
||||
|
||||
/// Frames for the first layout and fonts to settle
|
||||
const STARTUP_FRAMES: usize = 4;
|
||||
|
||||
/// Frames for a click or key to reach the panels and its change to show
|
||||
const SETTLE_FRAMES: usize = 3;
|
||||
|
||||
/// Frames between the moves of a drag, and between a press and its release
|
||||
const DRAG_STEP_FRAMES: usize = 2;
|
||||
|
||||
/// Presses and releases the primary button at `at` without moving, as a pointer click does
|
||||
fn click_at(harness: &mut Harness<'_, TextureCraftApp>, at: egui::Pos2) {
|
||||
harness.hover_at(at);
|
||||
for pressed in [true, false] {
|
||||
harness.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE });
|
||||
harness.run_steps(1);
|
||||
}
|
||||
|
||||
harness.run_steps(SETTLE_FRAMES);
|
||||
}
|
||||
|
||||
/// The close button nearest the right of a docked panel's `title` (its tab or header title), on the same row
|
||||
fn panel_close_button(harness: &Harness<'_, TextureCraftApp>, title: egui::Rect) -> egui::Rect {
|
||||
harness
|
||||
.get_all_by_role(egui::Role::Button)
|
||||
.filter(|button| button.accesskit_node().label().as_deref() == Some("Close Panel"))
|
||||
.map(|button| button.rect())
|
||||
.filter(|close| close.min.x > title.max.x && title.y_range().contains(close.center().y))
|
||||
.min_by(|a, b| a.min.x.total_cmp(&b.min.x))
|
||||
.expect("a close button right of the title")
|
||||
}
|
||||
@@ -68,7 +68,7 @@ fn a_fill_layer_greys_the_paint_tools_and_shows_its_own_properties() {
|
||||
assert!(shelf_button_disabled(&harness, "Polygon fill (4)"));
|
||||
assert!(!shelf_button_selected(&harness, "Polygon fill (4)"), "the equipped tool doesn't show as selected while greyed");
|
||||
assert!(!shelf_button_disabled(&harness, "Geometry mask (8)"));
|
||||
assert!(shows_text(&harness, "Properties - Fill"), "a fill layer shows its fill whatever the tool");
|
||||
assert!(shows_text(&harness, "PROPERTIES - FILL"), "a fill layer shows its fill whatever the tool");
|
||||
assert!(!shows_text(&harness, "Size"), "a tool that can't act leaves the top bar");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user