mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
tfix3-f5: a tool command's key release fires it in the release phase (spring-loaded tools); framework tool pickers act on the press only
This commit is contained in:
@@ -71,7 +71,7 @@ use craft_ui::layout_components::Row;
|
||||
use craft_ui::patterns::form_dialogs::{FormDialogWords, ParamDialogWords};
|
||||
use craft_ui::primitives::{Checker, IconSpec};
|
||||
use craft_ui::rails::{LastUsed, RailTool, ToolRail, ToolSlot};
|
||||
use craft_ui::runtime::commands::{CommandSet as _, Commands as _};
|
||||
use craft_ui::runtime::commands::{CommandSet as _, Commands as _, FirePhase};
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use craft_ui::runtime::memory::{SaveKey, saved_value, set_saved_value};
|
||||
use craft_ui::runtime::pending::{Job, Pending};
|
||||
@@ -621,6 +621,10 @@ impl ContentAwareFillWorkspace {
|
||||
{
|
||||
while let Some((command, fired)) = cx.take_command::<FillCommands>() {
|
||||
if let Some(tool) = command.tool() {
|
||||
// A tool key's release picks nothing.
|
||||
if fired.phase == FirePhase::Release {
|
||||
continue;
|
||||
}
|
||||
let slot = slots.iter().find(|slot| slot.tools.iter().any(|entry| entry.id == tool));
|
||||
let tools: Vec<&RailTool<FillTool>> = slot.into_iter().flat_map(|slot| slot.tools.iter()).collect();
|
||||
let picked = slot.and_then(|slot| {
|
||||
|
||||
@@ -80,7 +80,7 @@ use craft_ui::dialog::{
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::primitives::Checker;
|
||||
use craft_ui::rails::{LastUsed, ToolRail};
|
||||
use craft_ui::runtime::commands::{CommandSet as _, Commands as _};
|
||||
use craft_ui::runtime::commands::{CommandSet as _, Commands as _, FirePhase};
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::runtime::memory::{SaveKey, saved_value, set_saved_value};
|
||||
use craft_ui::runtime::words::CommonWords;
|
||||
@@ -495,6 +495,10 @@ impl LiquifyWorkspace {
|
||||
{
|
||||
while let Some((command, fired)) = cx.take_command::<LiquifyCommands>() {
|
||||
if let Some(tool) = command.tool() {
|
||||
// A tool key's release picks nothing.
|
||||
if fired.phase == FirePhase::Release {
|
||||
continue;
|
||||
}
|
||||
let slot = slots.iter().find(|slot| slot.tools.iter().any(|entry| entry.id == tool));
|
||||
let tools: Vec<_> = slot.into_iter().flat_map(|slot| slot.tools.iter()).collect();
|
||||
let picked = slot.and_then(|slot| {
|
||||
|
||||
@@ -76,7 +76,7 @@ use craft_ui::dialog::{
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::primitives::Checker;
|
||||
use craft_ui::rails::{LastUsed, ToolRail};
|
||||
use craft_ui::runtime::commands::{CommandSet as _, Commands as _};
|
||||
use craft_ui::runtime::commands::{CommandSet as _, Commands as _, FirePhase};
|
||||
use craft_ui::runtime::edit::next_gesture_id;
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::runtime::memory::{SaveKey, saved_value, set_saved_value};
|
||||
@@ -548,6 +548,10 @@ impl SelectMaskWorkspace {
|
||||
|
||||
while let Some((command, fired)) = cx.take_command::<SelectMaskCommands>() {
|
||||
if let Some(tool) = command.tool() {
|
||||
// A tool key's release picks nothing.
|
||||
if fired.phase == FirePhase::Release {
|
||||
continue;
|
||||
}
|
||||
let slot = slots.iter().find(|slot| slot.tools.iter().any(|entry| entry.id == tool));
|
||||
let tools: Vec<_> = slot.into_iter().flat_map(|slot| slot.tools.iter()).collect();
|
||||
let picked = slot.and_then(|slot| {
|
||||
|
||||
@@ -60,7 +60,7 @@ use craft_ui::dialog::{
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::primitives::Checker;
|
||||
use craft_ui::rails::{LastUsed, RailTool, ToolRail, ToolSlot};
|
||||
use craft_ui::runtime::commands::{CommandSet as _, Commands as _};
|
||||
use craft_ui::runtime::commands::{CommandSet as _, Commands as _, FirePhase};
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::runtime::windows::WindowSpec;
|
||||
use craft_ui::runtime::words::CommonWords;
|
||||
@@ -410,7 +410,8 @@ impl FullWindowWorkspace for VanishingPointWorkspace {
|
||||
work.new_plane.open = true;
|
||||
continue;
|
||||
}
|
||||
let Some(pick) = command.pick() else { continue };
|
||||
// A tool key's release picks nothing.
|
||||
let Some(pick) = command.pick().filter(|_| fired.phase != FirePhase::Release) else { continue };
|
||||
let slot = slots.iter().find(|slot| slot.tools.iter().any(|entry| entry.id == pick));
|
||||
let tools: Vec<_> = slot.into_iter().flat_map(|slot| slot.tools.iter()).collect();
|
||||
let current = Pick::of(work.strip, work.editor.tool());
|
||||
|
||||
@@ -47,7 +47,7 @@ use craft_ui::layout_components::Row;
|
||||
use craft_ui::menu::{Menu, MenuItem};
|
||||
use craft_ui::patterns::form_dialogs::{Param, ParamDialog, ParamKind};
|
||||
use craft_ui::rails::{LastUsed, RailTool, ToolRail, ToolSlot};
|
||||
use craft_ui::runtime::commands::{CommandSet as _, Commands as _, Fired};
|
||||
use craft_ui::runtime::commands::{CommandSet as _, Commands as _, FirePhase, Fired};
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use craft_ui::runtime::pending::Job;
|
||||
use craft_ui::runtime::words::CommonWords;
|
||||
@@ -553,8 +553,11 @@ fn edit_name<'a>(words: &'a WideAngleWords, edit: &WideAngleConstraintEdit) -> &
|
||||
}
|
||||
}
|
||||
|
||||
/// The tool a fired tool command picks, through its slot's pick rule.
|
||||
/// The tool a fired tool command picks, through its slot's pick rule; a tool key's release picks nothing.
|
||||
fn pick(slots: &[ToolSlot<WideAngleTool>], command: WideAngleCommands, fired: &Fired, body: &Body) -> Option<WideAngleTool> {
|
||||
if fired.phase == FirePhase::Release {
|
||||
return None;
|
||||
}
|
||||
let tool = TOOL_SLOT.iter().find(|(_, c)| *c == command)?.0;
|
||||
let slot = slots.iter().find(|slot| slot.tools.iter().any(|t| t.id == tool))?;
|
||||
let visible: Vec<&RailTool<WideAngleTool>> = slot.tools.iter().collect();
|
||||
|
||||
@@ -11,7 +11,8 @@ pub enum CommandKind {
|
||||
/// Runs the command.
|
||||
Command,
|
||||
/// Selects a tool. Tools of one group share keys and cycle; tools without a group name form one
|
||||
/// group together.
|
||||
/// group together. The key's release fires the command again in the release phase, so an app can give back
|
||||
/// the previous tool when the key was only held (a spring-loaded tool).
|
||||
Tool {
|
||||
/// The group the tool belongs to; `None` joins the group of tools without one.
|
||||
group: Option<String>,
|
||||
|
||||
@@ -1202,7 +1202,9 @@ pub(crate) fn begin(ctx: &Context) {
|
||||
let target = if app { resolved.instance } else { instance };
|
||||
let key = shortcut.input.physical.or(shortcut.input.typed);
|
||||
with(ctx, |board| {
|
||||
if let Some(key) = key.filter(|_| board.def(&hit.command.id).is_some_and(|def| def.kind == CommandKind::Momentary)) {
|
||||
if let Some(key) = key.filter(|_| {
|
||||
board.def(&hit.command.id).is_some_and(|def| matches!(def.kind, CommandKind::Momentary | CommandKind::Tool { .. }))
|
||||
}) {
|
||||
board.held.retain(|held| held.key != key);
|
||||
board.held.push(Held { key, command: hit.command.clone(), target });
|
||||
}
|
||||
|
||||
@@ -157,7 +157,8 @@ pub enum FirePhase {
|
||||
Press,
|
||||
/// A repeat of a held key.
|
||||
Repeat,
|
||||
/// The release; momentary tools act here.
|
||||
/// The release of a momentary command's or a tool's key: a momentary command ends here, and a spring-loaded tool
|
||||
/// gives back the previous one.
|
||||
Release,
|
||||
}
|
||||
|
||||
|
||||
@@ -111,8 +111,11 @@ fn body(ui: &mut Ui, cx: &mut BodyCx<'_>, state: &mut MockState) {
|
||||
}
|
||||
}
|
||||
|
||||
while let Some((command, _)) = cx.take_command::<Tool>() {
|
||||
select(ui, state, command);
|
||||
while let Some((command, fired)) = cx.take_command::<Tool>() {
|
||||
// A tool key's release picks nothing.
|
||||
if fired.phase != commands::FirePhase::Release {
|
||||
select(ui, state, command);
|
||||
}
|
||||
}
|
||||
while let Some((key, _)) = cx.take_command::<ToolKey>() {
|
||||
match key {
|
||||
|
||||
@@ -20,6 +20,7 @@ use std::cell::{Cell, RefCell};
|
||||
const EXPORT: &str = "trialCatalog.export";
|
||||
const PEEK: &str = "trialCatalog.peek";
|
||||
const QUICK: &str = "trialCatalog.quick";
|
||||
const BRUSH: &str = "trialCatalog.brush";
|
||||
const RENAME: &str = "trialCatalog.rename";
|
||||
|
||||
/// An app-scope definition of `id` bound to `chord`.
|
||||
@@ -29,7 +30,12 @@ fn def(id: &str, label: &str, chord: &str) -> CommandDef {
|
||||
|
||||
/// The app's catalog at `generation`: from generation 2 on it also holds Rename.
|
||||
fn catalog(generation: u64) -> CommandInput {
|
||||
let mut defs = vec![def(EXPORT, "Export", "Cmd+Alt+U"), def(PEEK, "Peek", "F9").with_kind(CommandKind::Momentary), def(QUICK, "Quick Mask", "Q")];
|
||||
let mut defs = vec![
|
||||
def(EXPORT, "Export", "Cmd+Alt+U"),
|
||||
def(PEEK, "Peek", "F9").with_kind(CommandKind::Momentary),
|
||||
def(QUICK, "Quick Mask", "Q"),
|
||||
def(BRUSH, "Brush", "J").with_kind(CommandKind::Tool { group: None }),
|
||||
];
|
||||
if generation >= 2 {
|
||||
defs.push(def(RENAME, "Rename", "Cmd+Alt+P"));
|
||||
}
|
||||
@@ -45,8 +51,8 @@ fn hit(id: &str, phase: FirePhase) -> (String, Option<Id>, FirePhase) {
|
||||
(id.to_owned(), None, phase)
|
||||
}
|
||||
|
||||
/// A catalog command's chord fires it as an app command, with no target; a momentary catalog command fires again on
|
||||
/// its key's release; a plain-letter chord fires with nothing focused, and waits for the text while a text field has
|
||||
/// A catalog command's chord fires it as an app command, with no target; a momentary or tool catalog command fires
|
||||
/// again on its key's release; a plain-letter chord fires with nothing focused, and waits for the text while a text field has
|
||||
/// the focus, which types the letter.
|
||||
#[trial]
|
||||
fn an_app_catalog_command_fires_by_its_chord_and_a_focused_text_field_keeps_a_typing_chord() {
|
||||
@@ -76,6 +82,9 @@ fn an_app_catalog_command_fires_by_its_chord_and_a_focused_text_field_keeps_a_ty
|
||||
frames.frame(vec![key_press(Key::Q, Modifiers::NONE)], &mut show);
|
||||
frames.frame(vec![key_release(Key::Q, Modifiers::NONE)], &mut show);
|
||||
assert_eq!(fired(&frames), [hit(QUICK, FirePhase::Press)], "with nothing focused the plain chord fires");
|
||||
frames.frame(vec![key_press(Key::J, Modifiers::NONE)], &mut show);
|
||||
frames.frame(vec![key_release(Key::J, Modifiers::NONE)], &mut show);
|
||||
assert_eq!(fired(&frames), [hit(BRUSH, FirePhase::Press), hit(BRUSH, FirePhase::Release)], "a tool's key fires on press and release");
|
||||
|
||||
let at = field.get().center();
|
||||
frames.frame(vec![moved(at)], &mut show);
|
||||
|
||||
Reference in New Issue
Block a user