mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 05:37:04 +00:00
Merge branch 'pdf-red2/fw-widgets' into area/fw-red-2
This commit is contained in:
@@ -460,7 +460,9 @@ pub(crate) fn run<C: Component>(
|
||||
if left_for_part {
|
||||
state.focused = false;
|
||||
}
|
||||
let commit_now = step.commit_now || (was_focused && left_for_part);
|
||||
// A window deactivation is no edit's end: the draft stays for the next Enter or a press elsewhere.
|
||||
let window_blur = was_focused && crate::runtime::pointer::with_pass_pointer(&ctx, |pointer| pointer.focus_lost);
|
||||
let commit_now = (step.commit_now || (was_focused && left_for_part)) && !window_blur;
|
||||
// Focus back from the edit menu finds the selection the part held for it, which the adapter put back.
|
||||
let back_from_menu = menu_held && state.held_selection.is_none();
|
||||
if out.focused && !left_for_part && !was_focused && !back_from_menu {
|
||||
@@ -473,20 +475,19 @@ pub(crate) fn run<C: Component>(
|
||||
if decl.options.complete.is_some() {
|
||||
drive_completions(cx, &mut state);
|
||||
}
|
||||
if window_blur && state.end == Some(End::Blur) {
|
||||
state.end = None;
|
||||
}
|
||||
if decl.options.holds_drafts {
|
||||
// A window deactivation leaves the draft for the next Enter or a press elsewhere (L-52).
|
||||
if state.end == Some(End::Blur) && crate::runtime::pointer::with_pass_pointer(&ctx, |pointer| pointer.focus_lost) {
|
||||
state.end = None;
|
||||
}
|
||||
// A press the focus service held for this part keeps focus; the draft shows as its value would.
|
||||
if state.end.is_none() && crate::runtime::focus::held_draft(&ctx) == Some(id) {
|
||||
state.end = Some(End::Rewrite { refuses: false });
|
||||
}
|
||||
}
|
||||
if commit_now {
|
||||
if window_blur {
|
||||
eprintln!(
|
||||
"DIAG text::number::a_window_blur_mid_typing_keeps_the_typed_draft: commit_now step={} was_focused={was_focused} left_for_part={left_for_part} holds_drafts={} end={:?}",
|
||||
step.commit_now, decl.options.holds_drafts, state.end
|
||||
"DIAG text::number::a_window_blur_mid_typing_keeps_the_typed_draft: window_blur end={:?} draft={:?} focused={}",
|
||||
state.end, state.draft, state.focused
|
||||
);
|
||||
}
|
||||
let resolved = resolve(&mut state, cx.value(), commit_now);
|
||||
|
||||
@@ -78,8 +78,9 @@ enum SearchStoryCommand {
|
||||
Open,
|
||||
}
|
||||
|
||||
/// The command-search opener: the search glyph, the placeholder and the chord of its command at the end.
|
||||
#[story(Button<'static>, covers = [], drive = Drive::Activate, group = "Playground", title = "Search")]
|
||||
/// The command-search opener: the search glyph, the placeholder and the chord of its command at the end. A command-bound
|
||||
/// button reports no click (the command fires instead), so the click-counting drive does not apply.
|
||||
#[story(Button<'static>, covers = [], drive = Drive::Never, group = "Playground", title = "Search")]
|
||||
fn button_search(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
Button::search(SearchStoryCommand::Open, "Search commands and settings").show(ui).into()
|
||||
}
|
||||
|
||||
@@ -95,10 +95,17 @@ fn calendar_popover_at_rect(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
}
|
||||
}
|
||||
|
||||
/// The calendar popover open from the first frame, hanging from its opener.
|
||||
#[story(CalendarPopover<'static>, covers = [], drive = Drive::Never)]
|
||||
/// Focuses the opener and presses Enter, which opens the popover.
|
||||
fn open_popover(fixture: &mut Fixture) {
|
||||
fixture.key(Key::Tab, Modifiers::NONE);
|
||||
fixture.key(Key::Enter, Modifiers::NONE);
|
||||
fixture.idle(4);
|
||||
}
|
||||
|
||||
/// The calendar popover, opened by its opener and hanging from it.
|
||||
#[story(CalendarPopover<'static>, covers = [Open], drive = Drive::Custom(open_popover))]
|
||||
fn calendar_popover_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut open = *data.value("open", true);
|
||||
let mut open = *data.value("open", false);
|
||||
let mut picked = *data.value("picked", Some(today()));
|
||||
let shown = Stack::new().show(ui, |ui, _| {
|
||||
let opener = Button::new("Choose a date").show(ui);
|
||||
@@ -109,7 +116,7 @@ fn calendar_popover_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
.show(ui, |_, _| {})
|
||||
.output
|
||||
});
|
||||
*data.value("open", true) = open;
|
||||
*data.value("open", false) = open;
|
||||
*data.value("picked", Some(today())) = picked;
|
||||
match shown.inner {
|
||||
Some(output) => output.into(),
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
mod stories;
|
||||
|
||||
use crate::contract::{
|
||||
Access, Bind, BindMut, Common, Component, Cx, Edit as _, MeasureCx, Name, Outcome, PaintUi, PartsCx, Pointer as _, Props as _, Role, SetPosition,
|
||||
Styled as _,
|
||||
Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, MeasureCx, Name, Outcome, PaintUi, PartsCx, Pointer as _, Props as _,
|
||||
Role, SetPosition, Styled as _,
|
||||
};
|
||||
use crate::primitives::{PaintShape, Span, TextRun};
|
||||
use crate::runtime::env::Label;
|
||||
@@ -13,6 +13,7 @@ use crate::style::{ComponentStyle, Flags, FocusLook, StyleColor, StyleCx, TextLo
|
||||
use craft_behavior::{Flow, Metrics, NavShape, PartKey, PartRef, Proposal, Roving, Sense, Value};
|
||||
use craft_theme::{Rgba, Stateful, States};
|
||||
use egui::{CornerRadius, Rect, Response, Ui, Vec2, pos2, vec2};
|
||||
use std::ops::Deref;
|
||||
|
||||
/// A word of the run: its text on its fill.
|
||||
const WORD: PartKey = PartKey::new("word");
|
||||
@@ -100,17 +101,30 @@ impl<'a, K: Value + 'static> WordRun<'a, K> {
|
||||
/// What a `WordRun` returns.
|
||||
#[non_exhaustive]
|
||||
pub struct WordRunOutput<K> {
|
||||
/// The run's response.
|
||||
pub response: Response,
|
||||
/// The edit response of the picked key.
|
||||
pub edit: EditResponse<Option<K>>,
|
||||
/// The key of the word picked in this pass.
|
||||
pub picked: Option<K>,
|
||||
}
|
||||
|
||||
impl<K> Deref for WordRunOutput<K> {
|
||||
type Target = EditResponse<Option<K>>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.edit
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: Value> Outcome for WordRunOutput<K> {
|
||||
type Value = Option<K>;
|
||||
|
||||
fn response(&self) -> &Response {
|
||||
&self.response
|
||||
&self.edit.response
|
||||
}
|
||||
|
||||
#[cfg(feature = "testing")]
|
||||
fn story_facts(&self) -> crate::testing::StoryOutput {
|
||||
self.edit.story_facts()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,10 +293,6 @@ impl<K: Value + 'static> Component for WordRun<'_, K> {
|
||||
fn update(&mut self, cx: &mut Cx<'_, Self>) {
|
||||
let Some(at) = (0..self.words.len()).find(|&at| cx.part_activated(Self::part(at)).is_some()) else { return };
|
||||
let key = self.words[at].key.clone();
|
||||
eprintln!(
|
||||
"DIAG suite::craft_ui_widgets::text::word_run::WordRun<'_, usize>::drives: activated word {at}, value {:?}",
|
||||
cx.value().map(|value| value.is_some())
|
||||
);
|
||||
self.picked = Some(key.clone());
|
||||
if cx.value().and_then(Option::as_ref) != Some(&key) {
|
||||
cx.set(Some(key));
|
||||
@@ -319,6 +329,6 @@ impl<K: Value + 'static> Component for WordRun<'_, K> {
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> WordRunOutput<K> {
|
||||
WordRunOutput { response: cx.response.clone(), picked: self.picked }
|
||||
WordRunOutput { picked: self.picked.clone(), edit: cx.edit_response() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,18 @@ fn the_wheel_over_an_open_popup_list_scrolls_the_list_and_not_the_surface_below(
|
||||
let on_page = fixture.by_label("Page 4").expect("the page shows its buttons").rect.center();
|
||||
fixture.frame(vec![pointer::moved(on_page)]);
|
||||
fixture.frame(vec![pointer::wheel(-60.0)]);
|
||||
eprintln!(
|
||||
"DIAG popover::popup::the_wheel_over_an_open_popup_list_scrolls_the_list_and_not_the_surface_below: after the wheel Open {:?} (was {:?}) Page 4 {:?} (was {on_page:?})",
|
||||
fixture.by_label("Open").map(|shown| shown.rect.min.y),
|
||||
opener.min.y,
|
||||
fixture.by_label("Page 4").map(|shown| shown.rect.center())
|
||||
);
|
||||
fixture.settle();
|
||||
eprintln!(
|
||||
"DIAG popover::popup::the_wheel_over_an_open_popup_list_scrolls_the_list_and_not_the_surface_below: settled Open {:?} list open {}",
|
||||
fixture.by_label("Open").map(|shown| shown.rect.min.y),
|
||||
open.get()
|
||||
);
|
||||
assert!(fixture.by_label("Open").is_none_or(|shown| shown.rect.min.y < opener.min.y - 1.0), "the wheel over the page scrolls it");
|
||||
}
|
||||
|
||||
@@ -171,6 +182,18 @@ fn a_resting_pointer_leaves_the_lead_where_the_keys_moved_it() {
|
||||
let rest = fixture.by_label(&row(3)).expect("the list shows its fourth row").rect.center();
|
||||
fixture.frame(vec![pointer::moved(rest)]).settle();
|
||||
fixture.key(Key::End, Modifiers::NONE).settle();
|
||||
eprintln!(
|
||||
"DIAG popover::popup::a_resting_pointer_leaves_the_lead_where_the_keys_moved_it: after End focused {:?} stop {:?} last row shown {} first row shown {}",
|
||||
fixture.focused(),
|
||||
fixture.focused_stop(),
|
||||
fixture.by_label(&row(ROWS - 1)).is_some(),
|
||||
fixture.by_label(&row(0)).is_some()
|
||||
);
|
||||
fixture.key(Key::Enter, Modifiers::NONE).settle();
|
||||
eprintln!(
|
||||
"DIAG popover::popup::a_resting_pointer_leaves_the_lead_where_the_keys_moved_it: after Enter open {} activated {:?}",
|
||||
open.get(),
|
||||
activated.borrow()
|
||||
);
|
||||
assert_eq!(*activated.borrow(), [ROWS - 1], "Enter picks the row End went to, not the one under the resting pointer");
|
||||
}
|
||||
|
||||
@@ -89,9 +89,9 @@ fn wrapped_right_to_left_lines_align_to_the_right_edge() {
|
||||
.collect();
|
||||
let right = spans.iter().map(|(_, right)| *right).fold(f32::NEG_INFINITY, f32::max);
|
||||
for ((left, end), (top, text, glyphs)) in spans.iter().zip(&rows) {
|
||||
let last = glyphs.last().map(|(chr, x, advance)| (*chr, *x, *advance));
|
||||
let outer = glyphs.iter().filter(|(chr, ..)| !chr.is_whitespace()).max_by(|a, b| (a.1 + a.2).total_cmp(&(b.1 + b.2)));
|
||||
eprintln!(
|
||||
"DIAG text::rtl_paragraph::wrapped_right_to_left_lines_align_to_the_right_edge: top {top} span {left}..{end} last glyph {last:?} text {text:?}"
|
||||
"DIAG text::rtl_paragraph::wrapped_right_to_left_lines_align_to_the_right_edge: top {top} span {left}..{end} rightmost ink glyph {outer:?} text {text:?}"
|
||||
);
|
||||
}
|
||||
for ((left, end), (_, text, _)) in spans.iter().zip(&rows) {
|
||||
|
||||
Reference in New Issue
Block a user