Charts · Navigation · Forms: band names widen a sideways chart's gutter; Pagination takes a size, speaks the locale and jumps to a typed page
- A horizontal chart's gutter grows to its widest band name, floored at the theme gutter and capped at half the chart; a name past the cap ends in an ellipsis (#10). - Pagination's previous and next tooltips read i18n (English and zh-CN built in, app catalogs override); `.size(ControlSize)` sizes every control, Sm by default; `.jump()` adds a Go to field (#11). - NumberInput keys the owner's value as shown: a draft survives a blur, a value set while focused lands when focus leaves, and an echo of its own commit is no new value. A ranged field holds room for its widest bound through `Input::least`.
This commit is contained in:
1 parent
2ce336895c
commit
bd3772ad54
17 files changed
+438
-51
No files matched your search
@@ -1,4 +1,7 @@
|
||||
use super::{parse, settle};
|
||||
use gpui::{Context, Entity, IntoElement, Render, TestAppContext, VisualTestContext, Window};
|
||||
|
||||
use super::{NumberInput, parse, settle};
|
||||
use crate::{forms::bind_keys, theme::Theme};
|
||||
|
||||
#[test]
|
||||
fn parses_grouped_and_typographic_minus_and_refuses_junk() {
|
||||
@@ -29,3 +32,92 @@ fn settle_rounds_before_it_clamps() {
|
||||
fn settle_refuses_a_range_without_a_number_at_its_precision() {
|
||||
settle(0.25, 0.21, 0.29, 1);
|
||||
}
|
||||
|
||||
/// A field whose owner keeps each commit and shows `precision` places.
|
||||
struct Owned {
|
||||
value: f64,
|
||||
precision: usize,
|
||||
commits: Vec<f64>,
|
||||
}
|
||||
|
||||
impl Render for Owned {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let view = cx.entity();
|
||||
NumberInput::new("owned", self.value)
|
||||
.precision(self.precision)
|
||||
.on_commit(move |value, _, cx| {
|
||||
view.update(cx, |owned, cx| {
|
||||
owned.commits.push(value);
|
||||
owned.value = value;
|
||||
cx.notify();
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn owned(
|
||||
value: f64,
|
||||
precision: usize,
|
||||
cx: &mut TestAppContext,
|
||||
) -> (Entity<Owned>, &mut VisualTestContext) {
|
||||
cx.update(|cx| {
|
||||
Theme::init(cx);
|
||||
bind_keys(cx);
|
||||
});
|
||||
let (view, cx) = cx.add_window_view(move |_, _| Owned {
|
||||
value,
|
||||
precision,
|
||||
commits: Vec::new(),
|
||||
});
|
||||
cx.update(|window, _| window.activate_window());
|
||||
cx.run_until_parked();
|
||||
(view, cx)
|
||||
}
|
||||
|
||||
fn commits(view: &Entity<Owned>, cx: &mut VisualTestContext) -> Vec<f64> {
|
||||
view.read_with(cx, |owned, _| owned.commits.clone())
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_value_the_owner_sets_while_focused_shows_once_focus_leaves(cx: &mut TestAppContext) {
|
||||
let (view, cx) = owned(4.0, 0, cx);
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
view.update(cx, |owned, cx| {
|
||||
owned.value = 42.0;
|
||||
cx.notify();
|
||||
});
|
||||
cx.run_until_parked();
|
||||
cx.update(|window, cx| window.blur(cx));
|
||||
cx.run_until_parked();
|
||||
assert_eq!(commits(&view, cx), [42.0]);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn new_places_reformat_the_same_value(cx: &mut TestAppContext) {
|
||||
let (view, cx) = owned(1.25, 0, cx);
|
||||
view.update(cx, |owned, cx| {
|
||||
owned.precision = 2;
|
||||
cx.notify();
|
||||
});
|
||||
cx.run_until_parked();
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("enter");
|
||||
assert_eq!(commits(&view, cx), [1.25], "the field shows 1.25, not 1");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_owner_echo_of_a_commit_keeps_the_next_draft(cx: &mut TestAppContext) {
|
||||
let (view, cx) = owned(4.0, 0, cx);
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
for typed in ["12", "18"] {
|
||||
cx.simulate_keystrokes("secondary-a");
|
||||
cx.simulate_input(typed);
|
||||
if typed == "12" {
|
||||
cx.simulate_keystrokes("enter");
|
||||
cx.run_until_parked();
|
||||
}
|
||||
}
|
||||
cx.update(|window, cx| window.blur(cx));
|
||||
cx.run_until_parked();
|
||||
assert_eq!(commits(&view, cx), [12.0, 18.0]);
|
||||
}
|
||||
Reference in new issue
Block a user