shuyi_ui/screens/profiles/view.rs
1//! What the profiles screen shows, as plain data: no cells, glyphs,
2//! colours or positions. The screen builds a [`ProfilesView`] each frame
3//! ([`ProfilesScreen::view`](super::ProfilesScreen::view)) and a skin
4//! paints it ([`super::glyph::paint`] today).
5
6use super::{DeleteChoice, RowKind};
7use crate::prelude::*;
8use crate::screens::options::LeaveChoice;
9pub use crate::widgets::name_entry::{GridView, TypingView};
10use crate::widgets::{AskView, MenuView};
11
12/// The whole screen, as it is this frame.
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct ProfilesView {
15 /// The screen's title.
16 pub title: String,
17 /// The profiles, in the order they were made, then the row that adds
18 /// one.
19 pub rows: Vec<RowView>,
20 /// The words that mark the profile in use.
21 pub current_mark: String,
22 /// What can be done to the focused profile, while that menu is open.
23 pub actions: Option<ActionsView>,
24 /// The typing box, while a name is typed on the keyboard.
25 pub typing: Option<TypingView>,
26 /// The letter grid, while a name is spelled on a controller.
27 pub grid: Option<GridView>,
28 /// The question asked on backing out of a name box, while it is open.
29 pub leaving: Option<AskView<LeaveChoice>>,
30 /// The question asked before deleting, while it is open.
31 pub deleting: Option<AskView<DeleteChoice>>,
32 /// A message for the player (something couldn't be done).
33 pub message: Option<String>,
34 /// The help line: what the keys do here.
35 pub help: String,
36}
37
38impl ProfilesView {
39 /// The focused row.
40 pub fn focused(&self) -> Option<&RowView> {
41 self.rows.iter().find(|r| r.focused)
42 }
43
44 /// The row of the profile in use.
45 pub fn current(&self) -> Option<&RowView> {
46 self.rows.iter().find(|r| r.current)
47 }
48}
49
50/// One row: a profile, or the row that adds one.
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct RowView {
53 /// Which row it is.
54 pub kind: RowKind,
55 /// The profile's name, or what the row does.
56 pub label: String,
57 /// Whether it is the profile in use.
58 pub current: bool,
59 /// Whether the cursor is on it.
60 pub focused: bool,
61 /// Whether Confirm does something there (no adding past the most
62 /// profiles).
63 pub enabled: bool,
64}
65
66/// The menu of what can be done to a profile.
67#[derive(Debug, Clone, PartialEq, Eq)]
68pub struct ActionsView {
69 /// The profile's name.
70 pub title: String,
71 /// What can be done, top to bottom: the labels are text keys, put in
72 /// the player's language when painted.
73 pub menu: MenuView,
74}