Misc · Asking and learning: Submit never rests; radio labels wrap
Survey's Submit asks for any missing answer instead of resting, so no untick takes its focus handle out of the tree. Flashcards turn and go round, and a quiz pick clears its ask, through methods the tests reach; the poll's rows show which one holds the vote. forms::Radio's label wraps in its own block, as Checkbox's does, so a long one stays in a narrow box.
This commit is contained in:
1 parent
86c9de7d0a
commit
46aa381eee
9 files changed
+136
-56
No files matched your search
+32
-3
@@ -18,6 +18,18 @@ struct Deck {
|
||||
back: bool,
|
||||
}
|
||||
|
||||
impl Deck {
|
||||
fn turn(&mut self) {
|
||||
self.back = !self.back;
|
||||
}
|
||||
|
||||
/// Goes `by` cards round a deck of `count`, front up.
|
||||
fn go(&mut self, by: isize, count: usize) {
|
||||
self.at = (self.at as isize + by).rem_euclid(count as isize) as usize;
|
||||
self.back = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Cards with a question on the front and its answer on the back, one at a time: a press on the card turns it, and Previous and Next go round the deck, front up. Each face fades in.
|
||||
#[derive(IntoElement)]
|
||||
pub struct Flashcards {
|
||||
@@ -90,8 +102,7 @@ impl RenderOnce for Flashcards {
|
||||
let deck = deck.clone();
|
||||
move |_: &gpui::ClickEvent, _: &mut Window, cx: &mut App| {
|
||||
deck.update(cx, |deck, cx| {
|
||||
deck.at = (deck.at as isize + by).rem_euclid(count as isize) as usize;
|
||||
deck.back = false;
|
||||
deck.go(by, count);
|
||||
log::info!("flashcards: card {} of {count}", deck.at + 1);
|
||||
cx.notify();
|
||||
})
|
||||
@@ -117,7 +128,7 @@ impl RenderOnce for Flashcards {
|
||||
.cursor_pointer()
|
||||
.on_click(move |_, _, cx| {
|
||||
turned.update(cx, |deck, cx| {
|
||||
deck.back = !deck.back;
|
||||
deck.turn();
|
||||
log::info!(
|
||||
"flashcards: turned to the {}",
|
||||
if deck.back { "back" } else { "front" }
|
||||
@@ -152,3 +163,21 @@ impl RenderOnce for Flashcards {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Deck;
|
||||
|
||||
#[test]
|
||||
fn a_deck_turns_and_goes_round_front_up() {
|
||||
let mut deck = Deck::default();
|
||||
deck.turn();
|
||||
deck.turn();
|
||||
assert!(!deck.back, "a second press turns it back");
|
||||
deck.turn();
|
||||
deck.go(-1, 3);
|
||||
assert_eq!((deck.at, deck.back), (2, false));
|
||||
deck.go(1, 3);
|
||||
assert_eq!(deck.at, 0);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user