mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
framework: button presses read through contract::clicked; the command registry names layers as runtime::egui::areas::LayerKey; Pasteboard declares its overlay (its rename story covers Open); rename_field returns the TextField for callers to show; the tool host's cancel mapping no longer names the pipeline's Gesture; quantities declared on roundness and a field's named number; fixed sample and paste-picture colours from Srgba and the test kit
This commit is contained in:
@@ -153,7 +153,7 @@ pub struct TipEllipse<'a> {
|
||||
common: Common,
|
||||
value: Bind<'a, TipAngle>,
|
||||
/// The least roundness a dot drag, an Alt+arrow step and the drawn ellipse reach; 0 draws the flat tip as a line.
|
||||
#[prop]
|
||||
#[prop(quantity = "minor axis over major")]
|
||||
least_roundness: f64,
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ fn slice_bar_locked(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// fields keep what was typed while it shows.
|
||||
fn dialog_story<D: StackDialog + 'static>(ui: &mut Ui, data: &mut StoryData, opener: &'static str, make: impl FnOnce() -> D) -> StoryOutput {
|
||||
let open = data.note::<Option<D>>("dialog", None);
|
||||
if Button::new(opener).show(ui).response.clicked() {
|
||||
if craft_ui::contract::clicked(&Button::new(opener).show(ui)) {
|
||||
*open = Some(make());
|
||||
}
|
||||
if let Some(dialog) = open.as_mut() {
|
||||
|
||||
@@ -8,6 +8,7 @@ use std::sync::Arc;
|
||||
|
||||
use craft_behavior::{DisplayOrder, IconId, ItemSource, Preview, Selection};
|
||||
use craft_font_catalog::Catalog;
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::buttons::{Button, IconButton, ToggleButton};
|
||||
use craft_ui::choice::{Radio, RadioGroup};
|
||||
use craft_ui::contract::overlay::Dismiss;
|
||||
@@ -374,8 +375,8 @@ fn face_thumb<'a>(
|
||||
return;
|
||||
}
|
||||
let ink = if on_white {
|
||||
cx.painter.rect_filled(rect, 0.0, Color32::WHITE);
|
||||
DataColor::new(Color32::BLACK)
|
||||
cx.painter.rect_filled(rect, 0.0, Color32::from(Srgba::WHITE));
|
||||
DataColor::new(Color32::from(Srgba::BLACK))
|
||||
} else {
|
||||
DataColor::new(cx.ink())
|
||||
};
|
||||
|
||||
@@ -961,11 +961,11 @@ impl<'a> LayerFilterBar<'a> {
|
||||
.popup(PopupKind::Menu)
|
||||
.show(ui);
|
||||
let mut open = cx.memory::<FilterPopup>().open;
|
||||
if button.clicked() {
|
||||
if craft_ui::contract::clicked(&button) {
|
||||
open = !open;
|
||||
}
|
||||
Popover::new(words.filter.clone(), Bind::bound(&mut open)).opened_by(&button).show(ui, |ui, _| {
|
||||
if Button::new(words.clear_all.clone()).enabled(ticked).show(ui).clicked() {
|
||||
if craft_ui::contract::clicked(&Button::new(words.clear_all.clone()).enabled(ticked).show(ui)) {
|
||||
next.objects.clear();
|
||||
next.states.clear();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use super::space::canvas_space;
|
||||
use crate::contract::overlay::{Dismiss, LayerRole, Outside};
|
||||
use crate::contract::{
|
||||
Access, Bind, Common, Component, Cx, MeasureCx, Name, NoValue, Outcome, Overlay, OverlayUi, Overlays as _, PaintUi, PartsCx, Pointer as _,
|
||||
Props as _, Rename, Role,
|
||||
Props as _, Rename, Role, Show as _,
|
||||
};
|
||||
use crate::primitives::{Checker, CheckerArea, PaintShape, PaintSlot, Rule, StrokeWidth, TextRun, paint_surround};
|
||||
use crate::runtime::env::Label;
|
||||
@@ -208,7 +208,7 @@ impl Outcome for PasteboardOutput {
|
||||
/// page edges and names paint in place, over the pictures. The canvas must be given a view; without one nothing is
|
||||
/// shown.
|
||||
#[derive(crate::contract::Component, crate::contract::Props)]
|
||||
#[component(canvas_control, content_painter)]
|
||||
#[component(canvas_control, content_painter, overlay)]
|
||||
pub struct Pasteboard<'a> {
|
||||
#[common]
|
||||
common: Common,
|
||||
@@ -569,7 +569,7 @@ impl Component for Pasteboard<'_> {
|
||||
let (open, field) = (state.open.as_ref()?, field?);
|
||||
let size = field.size();
|
||||
let at = Rect::from_min_size(ui.max_rect().min, size);
|
||||
Some(crate::text::rename_field(ui, Bind::bound(&mut draft), at, &open.name))
|
||||
Some(crate::text::rename_field(Bind::bound(&mut draft), &open.name).show_at(ui, at))
|
||||
});
|
||||
let Some(open) = state.open else { return };
|
||||
// `None`: the popup is not shown yet (it opens at the end of the pass that began the rename).
|
||||
|
||||
@@ -132,7 +132,7 @@ fn long_page_names(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
}
|
||||
|
||||
/// A double press on a page's name opens its rename field.
|
||||
#[story(Pasteboard<'static>, covers = [Default], drive = Drive::Custom(rename_first_name))]
|
||||
#[story(Pasteboard<'static>, covers = [Open], drive = Drive::Custom(rename_first_name))]
|
||||
fn renaming_a_page_name(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let view = view_values(data, 0.0);
|
||||
let border = border_of(data, PageBorder::DropShadow);
|
||||
|
||||
@@ -953,10 +953,10 @@ fn cancel_reason(reason: PressCancel) -> CancelReason {
|
||||
match reason {
|
||||
PressCancel::Escape => CancelReason::Escape,
|
||||
PressCancel::FocusLost => CancelReason::Blur,
|
||||
PressCancel::Disabled => CancelReason::Dismissed,
|
||||
PressCancel::Host => CancelReason::HostChanged,
|
||||
PressCancel::Gesture => CancelReason::Dismissed,
|
||||
_ => CancelReason::Removed,
|
||||
PressCancel::Removed => CancelReason::Removed,
|
||||
// A part turned disabled, or a second finger landing on the canvas, dismisses the gesture.
|
||||
_ => CancelReason::Dismissed,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@ pub(crate) use board::{fire_bound, fire_resolved, resolve_bound, resolve_scoped}
|
||||
pub(crate) use board::{keymap_built, queued_for};
|
||||
|
||||
use crate::contract::{MemoKey, MemoProps, PlainData, Revision, Tracked};
|
||||
use crate::runtime::egui::{areas, pass};
|
||||
use crate::runtime::egui::areas::{self, LayerKey};
|
||||
use crate::runtime::egui::pass;
|
||||
use crate::runtime::env::Label;
|
||||
use crate::runtime::memory::Facts;
|
||||
use crate::runtime::overlay;
|
||||
@@ -633,7 +634,7 @@ pub fn holder(ctx: &Context, chord: &Chord) -> Option<CommandRef> {
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct ShownFact {
|
||||
command: CommandRef,
|
||||
layer: egui::LayerId,
|
||||
layer: LayerKey,
|
||||
rect: egui::Rect,
|
||||
label: Label,
|
||||
holder: bool,
|
||||
@@ -651,13 +652,13 @@ impl Shift for ShownFact {
|
||||
}
|
||||
|
||||
/// Registers `command` as shown for the next pass of the running viewport.
|
||||
fn register_shown(ctx: &Context, layer: egui::LayerId, rect: egui::Rect, label: Label, command: &CommandRef, holder: bool) {
|
||||
fn register_shown(ctx: &Context, layer: LayerKey, rect: egui::Rect, label: Label, command: &CommandRef, holder: bool) {
|
||||
Facts::register(ctx, ShownFact { command: command.clone(), layer, rect, label, holder });
|
||||
}
|
||||
|
||||
/// Records that a container at `rect` holds `commands`, for this pass and viewport. Not [`CommandInput::holds`], which
|
||||
/// turns hold bindings on.
|
||||
pub fn holds(ctx: &Context, layer: egui::LayerId, rect: egui::Rect, commands: &[CommandRef], label: Label) {
|
||||
pub fn holds(ctx: &Context, layer: LayerKey, rect: egui::Rect, commands: &[CommandRef], label: Label) {
|
||||
for command in commands {
|
||||
register_shown(ctx, layer, rect, label.clone(), command, true);
|
||||
}
|
||||
@@ -666,7 +667,7 @@ pub fn holds(ctx: &Context, layer: egui::LayerId, rect: egui::Rect, commands: &[
|
||||
/// Records that the bound component of `command` was shown at `rect` in `layer`, with `label`, for this pass and
|
||||
/// viewport: the report step calls it for a component wholly inside its clip.
|
||||
// PLAN: the caller is the report step (menus-w3); until it lands nothing in this crate calls it.
|
||||
pub(crate) fn note_shown(ctx: &Context, layer: egui::LayerId, rect: egui::Rect, label: Label, command: &CommandRef) {
|
||||
pub(crate) fn note_shown(ctx: &Context, layer: LayerKey, rect: egui::Rect, label: Label, command: &CommandRef) {
|
||||
register_shown(ctx, layer, rect, label, command, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ fn a_host_canvas_reads_the_clipboard_of_its_edit_set_with_nothing_focused() {
|
||||
/// `textless_paste` reads it in that pass only.
|
||||
#[trial]
|
||||
fn a_paste_with_no_text_is_the_paste_chord_and_reads_as_textless() {
|
||||
let picture = Event::PasteImage(Arc::new(egui::ColorImage::filled([1, 1], egui::Color32::WHITE)));
|
||||
let picture = Event::PasteImage(Arc::new(crate::testing::pictures::sample_picture(1, [1, 1])));
|
||||
assert!(!clipboard_with_canvas(KeyUse::CANVAS, picture.clone()).1.is_empty(), "the picture's paste fires the app's Paste");
|
||||
let read = Rc::new(Cell::new(false));
|
||||
let seen = Rc::clone(&read);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! Stories of `ParamDialog`.
|
||||
|
||||
use super::{HostedParamDialog, ParamDialog, ParamLayout, ParamPresets};
|
||||
use crate::contract::Bind;
|
||||
use crate::buttons::Button;
|
||||
use crate::contract::{Bind, Show as _};
|
||||
use crate::dialog::StackDialog as _;
|
||||
use crate::dialog::stories::hosted_with;
|
||||
use crate::patterns::form_dialogs::{DialogFields, Param, ParamKind};
|
||||
@@ -117,7 +118,7 @@ fn hosted_param_dialog_with_a_refused_ok(ui: &mut Ui, data: &mut StoryData) -> S
|
||||
/// The open state of a story's dialog, which starts closed: a button opens it.
|
||||
fn opener<'d>(ui: &mut Ui, data: &'d mut StoryData) -> &'d mut bool {
|
||||
let open = data.value("open", false);
|
||||
if ui.button("Open").clicked() {
|
||||
if crate::contract::clicked(&Button::new("Open").show(ui)) {
|
||||
*open = true;
|
||||
}
|
||||
open
|
||||
|
||||
@@ -7,7 +7,7 @@ use super::predicate::{DropTest, RowTest, RowText};
|
||||
use super::{ListRow, RowEvent};
|
||||
use crate::contract::{
|
||||
Access, ActivateOn, Bind, BindMut, Collection, CollectionProps, CollectionResponse, ColumnLayout, Common, Component, ContainerProps, Cx,
|
||||
DropKind, EdgePress, EditResponse, HoverLead, LeadOnOpen, ListDrag, Props as _, Role, RowState, SelectMode, Sizing,
|
||||
DropKind, EdgePress, EditResponse, HoverLead, LeadOnOpen, ListDrag, Props as _, Role, RowState, SelectMode, Show as _, Sizing,
|
||||
};
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::style::{ComponentStyle, StyleCx};
|
||||
@@ -279,7 +279,7 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for List<'_, K> {
|
||||
}
|
||||
|
||||
fn rename_editor(&mut self, ui: &mut Ui, draft: Bind<'_, String>, label: Rect, name: &str) -> Option<EditResponse<String>> {
|
||||
Some(crate::text::rename_field(ui, draft, label, name))
|
||||
Some(crate::text::rename_field(draft, name).show_at(ui, label))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ use super::{
|
||||
};
|
||||
use crate::buttons::Button;
|
||||
use crate::contract::{
|
||||
Bind, CollectionEvent, ColumnSpec, Entry, Outcome as _, ScrollAnchor, Show as _, ShowCollection as _, ShowContainer as _, ToggleColumn,
|
||||
ToggleEdit, WordSetCx as _, request_rename,
|
||||
Bind, CollectionEvent, ColumnSpec, Entry, ScrollAnchor, Show as _, ShowCollection as _, ShowContainer as _, ToggleColumn, ToggleEdit,
|
||||
WordSetCx as _, request_rename,
|
||||
};
|
||||
use crate::layout_components::Stack;
|
||||
use crate::menu::Menu;
|
||||
@@ -629,7 +629,7 @@ fn list_follows_end(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let count = data.value("count", 12_usize);
|
||||
let mut shown = StoryOutput::default();
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
if Button::new("Add a row").show(ui).response().clicked() {
|
||||
if crate::contract::clicked(&Button::new("Add a row").show(ui)) {
|
||||
*count += 1;
|
||||
}
|
||||
let names = names(*count);
|
||||
|
||||
@@ -247,7 +247,7 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for Table<'_, K> {
|
||||
}
|
||||
|
||||
fn rename_editor(&mut self, ui: &mut Ui, draft: Bind<'_, String>, label: Rect, name: &str) -> Option<EditResponse<String>> {
|
||||
Some(crate::text::rename_field(ui, draft, label, name))
|
||||
Some(crate::text::rename_field(draft, name).show_at(ui, label))
|
||||
}
|
||||
|
||||
fn hosts_header(&self, column: &ColumnKey) -> bool {
|
||||
|
||||
@@ -25,7 +25,7 @@ pub use text_field::TextField;
|
||||
pub use words::TextWords;
|
||||
pub use zoom_field::{InvalidZoom, ZoomField, ZoomFieldOutput};
|
||||
|
||||
use crate::contract::{Bind, EditResponse};
|
||||
use crate::contract::Bind;
|
||||
use crate::primitives::TextKey;
|
||||
use crate::style::{ComponentStyle, IconLook, Ink, StyleCx, SurfaceLook};
|
||||
use craft_behavior::{Insets, Metrics, PartKey};
|
||||
@@ -122,7 +122,6 @@ fn text_part<V>() -> TextKey<V> {
|
||||
|
||||
/// The text field every collection's `rename_editor` and the canvas `Pasteboard`'s page-name rename show over a label:
|
||||
/// it selects the name on focus, so typing replaces it.
|
||||
pub fn rename_field(ui: &mut egui::Ui, draft: Bind<'_, String>, label: egui::Rect, name: &str) -> EditResponse<String> {
|
||||
use crate::contract::Show as _;
|
||||
TextField::new(name.to_owned(), draft).select_on_focus().show_at(ui, label)
|
||||
pub fn rename_field<'a>(draft: Bind<'a, String>, name: &str) -> TextField<'a> {
|
||||
TextField::new(name.to_owned(), draft).select_on_focus()
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ pub struct NumberField<'a, V: NumberValue + 'static = Option<f64>> {
|
||||
fixed_decimals: Option<usize>,
|
||||
/// The number the held name stands for: while the value is a name, the field shows this number in parentheses in
|
||||
/// place of the name's label; the presets row keeps the label.
|
||||
#[prop]
|
||||
#[prop(quantity = "field value")]
|
||||
#[allow(dead_code)]
|
||||
// PLAN: `Ruled::format`'s named arm (rule.rs, appearance-w3) must show this number; the field passes it on once `Ruled` carries it
|
||||
name_number: Option<f64>,
|
||||
|
||||
@@ -15,7 +15,7 @@ use super::{CaptionPlace, CardText, Tile, TilePartEvent, ZoomStep};
|
||||
use crate::contract::{
|
||||
Access, Bind, BindMut, Collection, CollectionEvent, CollectionProps, CollectionResponse, ColumnKind, ColumnSpec, Common, Component,
|
||||
ContainerProps, Cx, DropKind, EditResponse, Focus as _, ListDrag, Meta as _, NoValue, Notch, Outcome, PaintUi, PartsCx, Pointer as _, Props as _,
|
||||
Role, RowHeight, RowState, SelectMode, Sizing, SpaceAction, SweepApply, SweepStep, ToggleColumn, section_part,
|
||||
Role, RowHeight, RowState, SelectMode, Show as _, Sizing, SpaceAction, SweepApply, SweepStep, ToggleColumn, section_part,
|
||||
};
|
||||
use crate::controls::disclosure::Disclosure;
|
||||
use crate::list::{DropTest, ListRow, ListRowStyle, RowTest, ThumbSize};
|
||||
@@ -906,6 +906,6 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for TileGrid<'_, K
|
||||
}
|
||||
|
||||
fn rename_editor(&mut self, ui: &mut Ui, draft: Bind<'_, String>, label: Rect, name: &str) -> Option<EditResponse<String>> {
|
||||
Some(crate::text::rename_field(ui, draft, label, name))
|
||||
Some(crate::text::rename_field(draft, name).show_at(ui, label))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user