shuyi_ui/widgets/ask/view.rs
1//! What a question shows, as plain data: no cells, glyphs, colours or
2//! positions. [`Ask::view`](super::Ask::view) builds it and a skin paints
3//! it ([`super::glyph::paint`] today).
4
5use crate::prelude::*;
6
7/// A question, as it is this frame.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct AskView<T> {
10 /// The question.
11 pub text: String,
12 /// The answers, in order; none for a question answered by its keys
13 /// alone ([`keys`](Self::keys)).
14 pub answers: Vec<AnswerView<T>>,
15 /// The line naming the keys that answer (a yes/no's "f yes / d no"),
16 /// shown instead of the answers.
17 pub keys: Option<String>,
18}
19
20impl<T: Copy> AskView<T> {
21 /// The answer in focus, if answers are shown.
22 pub fn focused(&self) -> Option<T> {
23 self.answers.iter().find(|a| a.focused).map(|a| a.answer)
24 }
25}
26
27/// One answer to a question.
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct AnswerView<T> {
30 /// Which answer it is.
31 pub answer: T,
32 /// Its name.
33 pub label: String,
34 /// Whether the cursor is on it.
35 pub focused: bool,
36}