T44d Web · Hidden demos keep still, wide ones scroll whole, pastes read the web's clipboard
This commit is contained in:
26 files changed
+211
-101
No files matched your search
@@ -12,7 +12,7 @@ use gpui::{App, ClipboardItem, IntoElement, ParentElement, SharedString, Styled,
|
||||
|
||||
use crate::{
|
||||
probe::probe,
|
||||
ui::{keep, noise, row, section, set},
|
||||
ui::{keep, live, noise, row, section, set},
|
||||
};
|
||||
|
||||
const MONTHS: [&str; 12] = [
|
||||
@@ -176,7 +176,7 @@ pub fn realtime(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
cx,
|
||||
);
|
||||
let ticking = keep("stream-tick", || false, window, cx);
|
||||
if !*ticking.read(cx) && !cx.theme().reduced_motion {
|
||||
if !*ticking.read(cx) && !cx.theme().reduced_motion && live("RealtimeChart", cx) {
|
||||
set(&ticking, true, cx);
|
||||
let stream = stream.clone();
|
||||
cx.spawn(async move |cx| {
|
||||
|
||||
@@ -13,7 +13,7 @@ use gpui::{
|
||||
|
||||
use crate::{
|
||||
probe::probe,
|
||||
ui::{code, row, section, web_note},
|
||||
ui::{code, row, section, set},
|
||||
};
|
||||
|
||||
pub fn boxes(cx: &App) -> impl IntoElement + use<> {
|
||||
@@ -442,13 +442,9 @@ pub fn clipboard(window: &mut Window, cx: &mut App) -> impl IntoElement + use<>
|
||||
let muted = cx.theme().colors.fg_muted;
|
||||
section(
|
||||
"Clipboard",
|
||||
"write_to_clipboard and read_from_clipboard on App.",
|
||||
"write_to_clipboard and read_from_clipboard_async on App; a browser asks before it hands the clipboard over.",
|
||||
cx,
|
||||
)
|
||||
.children(web_note(
|
||||
"A browser reads its clipboard only as it pastes, into a field: on the web gpui's read_from_clipboard finds nothing, so Paste reports no text. Copy works.",
|
||||
cx,
|
||||
))
|
||||
.child(
|
||||
row()
|
||||
.gap_3()
|
||||
@@ -464,14 +460,18 @@ pub fn clipboard(window: &mut Window, cx: &mut App) -> impl IntoElement + use<>
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.icon(IconName::Clipboard)
|
||||
.on_click(move |_, _, cx| {
|
||||
let text = cx.read_from_clipboard().and_then(|item| item.text());
|
||||
pasted.update(cx, |pasted, cx| {
|
||||
*pasted = Some(match text {
|
||||
Some(text) => text.into(),
|
||||
None => "The clipboard holds no text.".into(),
|
||||
});
|
||||
cx.notify();
|
||||
let (read, pasted) = (cx.read_from_clipboard_async(), pasted.clone());
|
||||
cx.spawn(async move |cx| {
|
||||
let said: SharedString = match read.await {
|
||||
Ok(item) => match item.and_then(|item| item.text()) {
|
||||
Some(text) => text.into(),
|
||||
None => "The clipboard holds no text.".into(),
|
||||
},
|
||||
Err(error) => format!("The clipboard stayed shut: {error:?}").into(),
|
||||
};
|
||||
cx.update(|cx| set(&pasted, Some(said), cx));
|
||||
})
|
||||
.detach();
|
||||
}),
|
||||
)
|
||||
.when_some(shown, |row, text| {
|
||||
|
||||
@@ -8,7 +8,7 @@ use gpui::{App, IntoElement, ParentElement, SharedString, Styled, Window, div, p
|
||||
|
||||
use crate::{
|
||||
probe::probe,
|
||||
ui::{keep, section, set, web_note},
|
||||
ui::{keep, section, set},
|
||||
};
|
||||
|
||||
type Cells = HashMap<(usize, usize), SharedString>;
|
||||
@@ -35,10 +35,6 @@ pub fn data_grid(window: &mut Window, cx: &mut App) -> impl IntoElement + use<>
|
||||
"Cells to edit like a spreadsheet's. Arrows walk, Shift stretches a range, typing or a double press edits, Delete clears, and Cmd-C and Cmd-V copy and paste.",
|
||||
cx,
|
||||
)
|
||||
.children(web_note(
|
||||
"A browser reads its clipboard only as it pastes into a text field, so Cmd-V pastes no cells here.",
|
||||
cx,
|
||||
))
|
||||
.child(probe(
|
||||
"grid",
|
||||
div().child(
|
||||
|
||||
@@ -37,7 +37,7 @@ const SCRIPT: &[Step] = &[
|
||||
Step::Rest,
|
||||
];
|
||||
|
||||
/// A live shell natively; a browser runs no processes, so there it says so.
|
||||
/// A live shell natively; on the web, why not.
|
||||
fn live(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
let section = section(
|
||||
"Terminal / TerminalTabs / TerminalSplit / TerminalToolbar / ShellSelector / TerminalSearch / TerminalLink",
|
||||
|
||||
@@ -7,7 +7,7 @@ use ely_gpui_component::{
|
||||
};
|
||||
use gpui::{App, IntoElement, ParentElement, Styled, Task, Window, div};
|
||||
|
||||
use crate::ui::{row, section, specimen, specimens};
|
||||
use crate::ui::{live, row, section, specimen, specimens};
|
||||
|
||||
const STEP: Duration = Duration::from_millis(1600);
|
||||
const VALUES: [f64; 5] = [1_284.0, 1_917.0, 12_406.0, 9_998.0, 10_031.0];
|
||||
@@ -18,24 +18,12 @@ struct Ticker {
|
||||
}
|
||||
|
||||
pub fn animated_number(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
let ticker = window.use_keyed_state("type-ticker", cx, |window, cx| Ticker {
|
||||
index: 0,
|
||||
_task: cx.spawn_in(window, async move |ticker, cx| {
|
||||
loop {
|
||||
cx.background_executor().timer(STEP).await;
|
||||
let advanced = cx.update(|_, cx| {
|
||||
ticker.update(cx, |ticker: &mut Ticker, cx| {
|
||||
ticker.index = (ticker.index + 1) % VALUES.len();
|
||||
cx.notify();
|
||||
})
|
||||
});
|
||||
if advanced.and_then(|inner| inner).is_err() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}),
|
||||
});
|
||||
let value = VALUES[ticker.read(cx).index];
|
||||
let index = if live("AnimatedNumber", cx) {
|
||||
ticker(window, cx).read(cx).index
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let value = VALUES[index];
|
||||
section(
|
||||
"AnimatedNumber",
|
||||
"Digits roll by place; or the value counts up.",
|
||||
@@ -55,6 +43,27 @@ pub fn animated_number(window: &mut Window, cx: &mut App) -> impl IntoElement +
|
||||
)
|
||||
}
|
||||
|
||||
/// Steps through the values on a clock of its own.
|
||||
fn ticker(window: &mut Window, cx: &mut App) -> gpui::Entity<Ticker> {
|
||||
window.use_keyed_state("type-ticker", cx, |window, cx| Ticker {
|
||||
index: 0,
|
||||
_task: cx.spawn_in(window, async move |ticker, cx| {
|
||||
loop {
|
||||
cx.background_executor().timer(STEP).await;
|
||||
let advanced = cx.update(|_, cx| {
|
||||
ticker.update(cx, |ticker: &mut Ticker, cx| {
|
||||
ticker.index = (ticker.index + 1) % VALUES.len();
|
||||
cx.notify();
|
||||
})
|
||||
});
|
||||
if advanced.and_then(|inner| inner).is_err() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn typewriter(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
let take = window.use_keyed_state("type-take", cx, |_, _| 0usize);
|
||||
let lines = [
|
||||
|
||||
Reference in new issue
Block a user