mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-30 10:03:56 +01:00
Layers: close the R + click list when the document changes
This commit is contained in:
1 parent
4b2729ee71
commit
671cdb3c5b
2 files changed
+20
-3
No files matched your search
@@ -46,6 +46,8 @@ pub struct LayerPickList {
|
||||
bounds: Rect,
|
||||
/// The layers there, top first, each with the channels it changes there
|
||||
rows: Vec<(LayerId, Vec<Channel>)>,
|
||||
/// The document revision the rows were read at: any change, or another project, closes the list
|
||||
revision: u64,
|
||||
/// The list's first frame: its top row takes the keyboard focus
|
||||
opening: bool,
|
||||
/// Closed by a press outside it: until every button is up, that press neither paints nor reopens it
|
||||
@@ -59,7 +61,9 @@ type HoverLabel = ((usize, (u32, u32), u64, ViewMode), String);
|
||||
pub(crate) fn click(app: &mut TextureCraftApp, at: Pos2, point: Vec2, bounds: Rect) {
|
||||
let viewport = app.session.viewport;
|
||||
match app.session.layers_under(point, viewport) {
|
||||
Ok((_, rows)) if rows.len() > 1 => app.layer_pick_list = Some(LayerPickList { at, point, bounds, rows, opening: true, closing: false }),
|
||||
Ok((_, rows)) if rows.len() > 1 => {
|
||||
app.layer_pick_list = Some(LayerPickList { at, point, bounds, rows, revision: app.session.revision, opening: true, closing: false });
|
||||
}
|
||||
_ => {
|
||||
app.run("layer.pickAt", json!({"x": point.x, "y": point.y, "viewport": [viewport.x, viewport.y]}));
|
||||
}
|
||||
@@ -99,13 +103,13 @@ fn area_id() -> egui::Id {
|
||||
egui::Id::unique("layer_pick_list")
|
||||
}
|
||||
|
||||
/// Draws the open list; a row click selects its layer, Esc or a press outside closes it
|
||||
/// Draws the open list; a row click selects its layer; Esc, a press outside or a document change closes it
|
||||
pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
let (any_down, pressed_at, escape) =
|
||||
ctx.input(|input| (input.pointer.any_down(), input.pointer.press_origin().filter(|_| input.pointer.any_pressed()), input.key_pressed(Key::Escape)));
|
||||
let shown = ctx.memory(|memory| memory.area_rect(area_id()));
|
||||
match &mut app.layer_pick_list {
|
||||
Some(_) if app.ui.mode != Mode::Painting || escape => app.layer_pick_list = None,
|
||||
Some(list) if app.ui.mode != Mode::Painting || escape || list.revision != app.session.revision => app.layer_pick_list = None,
|
||||
Some(list) if list.closing => {
|
||||
if !any_down {
|
||||
app.layer_pick_list = None;
|
||||
|
||||
@@ -896,6 +896,19 @@ fn the_layer_pick_list_takes_escape_and_its_closing_press_before_an_armed_point_
|
||||
assert!(armed(&h));
|
||||
}
|
||||
|
||||
/// The list names layers of the stack it was opened on: an edit, an undo or another project closes it
|
||||
#[test]
|
||||
fn the_layer_pick_list_closes_when_the_document_changes() {
|
||||
let (mut h, _) = harness();
|
||||
two_fills(&mut h);
|
||||
open_pick_list(&mut h);
|
||||
|
||||
execute(&mut h.state_mut().session, "edit.undo", &Value::Null).unwrap();
|
||||
h.run_steps(SETTLE_FRAMES);
|
||||
|
||||
assert!(h.state().layer_pick_list.is_none());
|
||||
}
|
||||
|
||||
/// In the split view, a press on the 2D view that closes the list paints nothing there
|
||||
#[test]
|
||||
fn a_press_on_the_2d_view_that_closes_the_layer_pick_list_does_not_paint() {
|
||||
|
||||
Reference in new issue
Block a user