@@ -8,7 +8,8 @@ pub struct State {
88 snap: Snapshot,
99 connected: bool,
1010 pointer: (f32, f32),
11- prompt_at: Option<(f32, f32)>,
11+ /// Where the prompt is open, and the widget ticket it follows up on, if a card was clicked.
12+ prompt_at: Option<(f32, f32, Option<u32>)>,
1213 prompt: TextEdit,
1314 inbox: Arc<Mutex<Option<Option<Snapshot>>>>,
1415 /// The binary at launch and its mtime. Read once: after cargo replaces it,
@@ -55,20 +56,28 @@ pub fn poll(s: &mut State, _t: f64, _tx: &mut Tx) -> bool {
5556 }
5657
5758 fn submit(s: &mut State, tx: &mut Tx) {
58- if let Some((x, y)) = s.prompt_at.take() {
59+ if let Some((x, y, about)) = s.prompt_at.take() {
5960 let prompt = s.prompt.text.clone();
6061 s.prompt = TextEdit::new("");
61- if !prompt.trim().is_empty() && client::widget(&prompt, x, y).is_none() {
62+ if !prompt.trim().is_empty() && client::widget(&prompt, x, y, about).is_none() {
6263 eprintln!("conveyord isn't running; the prompt was not sent");
6364 }
6465 }
6566 tx.blur();
6667 }
6768
69+fn open_prompt(s: &mut State, x: f32, y: f32, about: Option<u32>) {
70+ s.prompt_at = Some((x, y, about));
71+ s.prompt = TextEdit::new("");
72+ s.prompt.focused = true;
73+}
74+
6875 /// Moves a widget with the pointer, and tells conveyord where it landed.
69-fn drag(s: &mut State, id: u32, d: &Drag) {
76+/// Ctrl+press instead opens a prompt about the widget.
77+fn drag(s: &mut State, id: u32, d: &Drag, tx: &Tx) {
7078 let Some(p) = s.snap.canvas.iter_mut().find(|p| p.ticket == id) else { return };
7179 match (d.phase, s.drag) {
80+ (Phase::Down, _) if tx.mods().ctrl => { let (x, y) = (p.x + d.x, p.y + d.y); open_prompt(s, x, y, Some(id)) }
7281 (Phase::Down, _) => s.drag = Some((p.x, p.y)),
7382 (Phase::Move, Some((x, y))) => (p.x, p.y) = ((x + d.dx).max(0.0), (y + d.dy).max(0.0)),
7483 (Phase::Up, Some((x, y))) => {
@@ -84,9 +93,13 @@ fn card(key: String, w: f32, h: f32) -> El {
8493 col().key(key).w(w).h(h).radius(10.0).fill(t.card).padding(12.0).gap(6.0)
8594 }
8695
96+fn state_color(state: &str) -> rune::Color {
97+ if state == "failed" || state == "parked" { tok::accent(3, true) } else { tok::accent(0, true) }
98+}
99+
87100 fn pending(id: u32, title: &str, state: &str) -> El {
88101 let t = tok::theme(true);
89- let color = if state == "failed" || state == "parked" { tok::accent(3, true) } else { tok::accent(0, true) };
102+ let color = state_color(state);
90103 card(format!("pending-{id}"), 260.0, 90.0).label(format!("widget #{id} {state}"))
91104 .child(text(format!("#{id} · {state}")).font(tok::type_::LABEL).color(color))
92105 .child(text(title.to_owned()).font(tok::type_::BODY).color(t.text).wrap())
@@ -95,23 +108,35 @@ fn pending(id: u32, title: &str, state: &str) -> El {
95108 fn placed(s: &State, cx: &widgets::api::Cx) -> Vec<El> {
96109 s.snap.canvas.iter().map(|p| {
97110 let built = p.widget.as_deref().and_then(|w| widgets::ALL.iter().find(|(n, _)| *n == w));
111+ let t = s.snap.tickets.iter().find(|t| t.project == "widgets" && t.id == p.ticket);
98112 let el = match built {
99- Some((name, w)) => card(format!("w-{}", p.ticket), w.size.0, w.size.1).label(format!("widget {name}")).child((w.view)(cx)),
113+ Some((name, w)) => {
114+ let card = card(format!("w-{}", p.ticket), w.size.0, w.size.1).label(format!("widget {name}")).child((w.view)(cx));
115+ // A follow-up in flight: the widget stays, with its ticket's state on top.
116+ match t.filter(|t| t.state != "done") {
117+ Some(t) => card.child(text(format!("#{} · {}", t.id, t.state)).font(tok::type_::LABEL).color(state_color(&t.state))
118+ .padding(4.0).radius(6.0).fill(tok::theme(true).bg).absolute(8.0, 8.0)),
119+ None => card,
120+ }
121+ }
100122 None => {
101- let t = s.snap.tickets.iter().find(|t| t.project == "widgets" && t.id == p.ticket);
102123 let state = match (&p.widget, t) { (Some(_), _) => "installing", (_, Some(t)) => t.state.as_str(), _ => "?" };
103124 pending(p.ticket, t.map_or("", |t| t.title.as_str()), state)
104125 }
105126 };
106127 let id = p.ticket;
107- el.absolute(p.x, p.y).on_drag(move |s: &mut State, d: &mut Drag, _: &mut Tx| drag(s, id, d))
128+ el.absolute(p.x, p.y).on_drag(move |s: &mut State, d: &mut Drag, tx: &mut Tx| drag(s, id, d, tx))
108129 }).collect()
109130 }
110131
111-fn prompt_box(s: &State, x: f32, y: f32) -> El {
132+fn prompt_box(s: &State, x: f32, y: f32, about: Option<u32>) -> El {
112133 let t = tok::theme(true);
134+ let heading = match about.and_then(|a| s.snap.canvas.iter().find(|p| p.ticket == a)) {
135+ Some(p) => format!("Change {}", p.widget.clone().unwrap_or_else(|| format!("#{}", p.ticket))),
136+ None => "New widget".into(),
137+ };
113138 card("prompt".into(), 360.0, 120.0).absolute(x, y).focus_ring(2.0, 0.0, tok::accent(0, true))
114- .child(text("New widget").font(tok::type_::LABEL).color(t.text_secondary))
139+ .child(text(heading).font(tok::type_::LABEL).color(t.text_secondary))
115140 .child(text_input(&s.prompt, TextStyle::new(14.0, 400.0)).key("prompt-input").label("Widget prompt").w_full().grow(1.0)
116141 .padding(6.0).radius(6.0).fill(t.bg).color(t.text).placeholder("A clock with the date… Enter to build, Shift+Enter for a new line, Esc to cancel", t.text_secondary)
117142 .on_edit(|s: &mut State| &mut s.prompt)
@@ -134,17 +159,13 @@ pub fn view(s: &State, _: &mut rune::Cx<State>) -> El {
134159 let mut canvas = el().key("canvas").role("canvas").label("Canvas").w_full().grow(1.0).min_h(0.0).fill(t.bg)
135160 .on_pointer_move_local(|s: &mut State, e: rune::PointerEvent, tx: &mut Tx| { s.pointer = (e.x, e.y); tx.live_only(); })
136161 .on_press_tx(|s: &mut State, tx: &mut Tx| {
137- if tx.mods().ctrl {
138- s.prompt_at = Some(s.pointer);
139- s.prompt = TextEdit::new("");
140- s.prompt.focused = true;
141- }
162+ if tx.mods().ctrl { open_prompt(s, s.pointer.0, s.pointer.1, None) }
142163 });
143164 if s.snap.canvas.is_empty() && s.prompt_at.is_none() {
144165 canvas = canvas.child(col().w_full().h_full().center().child(text("Ctrl+click anywhere to make a widget").color(t.text_secondary)));
145166 }
146167 for e in placed(s, &cx) { canvas = canvas.child(e); }
147- if let Some((x, y)) = s.prompt_at { canvas = canvas.child(prompt_box(s, x, y)); }
168+ if let Some((x, y, about)) = s.prompt_at { canvas = canvas.child(prompt_box(s, x, y, about)); }
148169 let status = if s.connected { String::new() } else { "conveyord isn't running".into() };
149170 col().key("root").w_full().h_full().fill(t.bg).child(titlebar::bar(status)).child(canvas)
150171 }