git clone https://garage44.eu/jeroen/pinnacle.gitcartopolis-agent · 2026-11-30T15:14:08Z
feat(settings): choose the language from a dropdown The language page had a row per language with a Use button. It is now one dropdown, as a language is chosen on the web: a tap opens the languages over the page, a tap on one uses it. The access demo opens it and takes a picture of the list before choosing Nederlands.
programs/src/bin/settings.rs | 76 ++++++++++++++++++++++++++++++++++++--------
xtask/src/main.rs | 5 +++
2 files changed, 67 insertions(+), 14 deletions(-)
diff --git a/programs/src/bin/settings.rs b/programs/src/bin/settings.rs
index 4a987c6..7fcc4e5 100644
--- a/programs/src/bin/settings.rs
+++ b/programs/src/bin/settings.rs
@@ -151,6 +151,17 @@ struct Row {
/// A slider at this percent: the sound's volume or the screen's
/// brightness.
slider: Option<(Slider, u8)>,
+ /// A dropdown to choose from.
+ choice: Option<Choice>,
+}
+
+/// A dropdown's options, the one chosen, its name (as the page announces
+/// it) and the action choosing option `i` does.
+struct Choice {
+ name: &'static str,
+ options: Vec<&'static str>,
+ chosen: usize,
+ action: fn(usize) -> Action,
}
fn row(label: &str, value: String) -> Row {
@@ -160,6 +171,14 @@ fn row(label: &str, value: String) -> Row {
button: None,
switch: None,
slider: None,
+ choice: None,
+ }
+}
+
+fn choose(label: &str, choice: Choice) -> Row {
+ Row {
+ choice: Some(choice),
+ ..row(label, String::new())
}
}
@@ -539,22 +558,22 @@ fn sections(width: i32, height: i32) -> Vec<Section> {
]
}
-/// The language page: each language with Use, the one in use said; then
-/// a date and a number as it writes them.
+/// The language page: the language in use, chosen from a dropdown; then a
+/// date and a number as it writes them.
fn language_page() -> Vec<Section> {
let now = pinnacle_locale::current();
- let mut rows: Vec<Row> = Language::ALL
- .iter()
- .enumerate()
- .map(|(i, &l)| {
- if l == now {
- row(l.name(), String::from(t("In use")))
- } else {
- with(l.name(), String::new(), t("Use"), Action::SetLanguage(i))
- }
- })
- .collect();
- rows.push(with("", String::new(), t("Back"), Action::Back));
+ let rows = alloc::vec![
+ choose(
+ t("Language"),
+ Choice {
+ name: "language-choice",
+ options: Language::ALL.iter().map(|l| l.name()).collect(),
+ chosen: Language::ALL.iter().position(|&l| l == now).unwrap_or(0),
+ action: Action::SetLanguage,
+ },
+ ),
+ with("", String::new(), t("Back"), Action::Back),
+ ];
let seconds = match pinnacle_rt::clock() {
0 => pinnacle_rt::time() / 1000,
s => s,
@@ -1687,6 +1706,35 @@ fn page(title: &str, sections: &[Section], tapped: &Signal<Option<Action>>) -> V
),
);
}
+ if let Some(choice) = &row.choice {
+ let tapped = tapped.clone();
+ let action = choice.action;
+ let mut select = el("select")
+ .class("m-select__native")
+ .attr("aria-label", row.label.clone())
+ .attr("data-name", choice.name);
+ for (i, label) in choice.options.iter().enumerate() {
+ select = select.child(
+ el("option")
+ .attr("value", alloc::format!("{i}"))
+ .attr("data-name", name_of(action(i)))
+ .child(*label),
+ );
+ }
+ let select = select
+ .prop("selectedIndex", alloc::format!("{}", choice.chosen))
+ .on("change", move |e| {
+ if let Some(i) = e.selected_index.and_then(|i| usize::try_from(i).ok()) {
+ tapped.set(Some(action(i)));
+ }
+ });
+ item = item.child(
+ el("div")
+ .class("m-select")
+ .attr("style", "flex: 1; min-width: 200px")
+ .child(select),
+ );
+ }
if let Some((label, action)) = row.button {
let tapped = tapped.clone();
item = item.child(
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 3b8b80a..6b98191 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -5444,6 +5444,11 @@ fn access_demo() -> Result {
s.tap_named(BUTTON, "language")?;
s.wait_for("settings: language")?;
+ // The language is chosen from a dropdown: its options open over the
+ // page, each row named for the language it chooses.
+ s.tap_named(BUTTON, "language-choice")?;
+ s.find_named(&format!("{BUTTON}language-nl"))?;
+ s.shot(&dir.join("2-languages.png"))?;
s.tap_named(BUTTON, "language-nl")?;
s.wait_for(&format!("{PREFS}language nl"))?;
s.shot(&dir.join("2-taal.png"))?;