From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id C32EF1FF0AF for ; Fri, 06 Nov 2026 14:13:41 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 700E821786; Fri, 06 Nov 2026 14:12:38 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Subject: [PATCH installer v5 15/23] tui: views: add widget for displaying a group of checkboxes Date: Fri, 6 Nov 2026 14:10:44 +0100 Message-ID: <20261106131058.804870-16-c.heiss@proxmox.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261106131058.804870-1-c.heiss@proxmox.com> References: <20261106131058.804870-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1793970750704 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.153 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: EUPMBAJUTF5HLT4J3IJSBGLNEXG2J2XT X-Message-ID-Hash: EUPMBAJUTF5HLT4J3IJSBGLNEXG2J2XT X-MailFrom: c.heiss@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Adds a simple view which displays multiple checkboxes, each optionally associated with some user-defined data. No functional changes. Signed-off-by: Christoph Heiss --- Split this out into a separate commit to ease reviewing/applying. Changes v4 -> v5: * also enable/disable labels by matching the applied style Changes v3 -> v4: * no changes Changes v2 -> v3: * no changes Changes v1 -> v2: * no changes proxmox-tui-installer/src/views/mod.rs | 124 ++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 2 deletions(-) diff --git a/proxmox-tui-installer/src/views/mod.rs b/proxmox-tui-installer/src/views/mod.rs index a343e60..a73dde3 100644 --- a/proxmox-tui-installer/src/views/mod.rs +++ b/proxmox-tui-installer/src/views/mod.rs @@ -3,9 +3,11 @@ use std::{collections::HashMap, net::IpAddr, str::FromStr, sync::Arc}; use cursive::{ Printer, Rect, Vec2, View, event::{Event, EventResult}, - theme::BaseColor, + theme::{BaseColor, StyleType}, view::{Resizable, ViewWrapper}, - views::{EditView, LinearLayout, NamedView, ResizedView, SelectView, TextView}, + views::{ + Checkbox, DummyView, EditView, LinearLayout, NamedView, ResizedView, SelectView, TextView, + }, }; mod bootdisk; @@ -626,3 +628,121 @@ impl CidrAddressEditView { impl ViewWrapper for CidrAddressEditView { cursive::wrap_impl!(self.view: LinearLayout); } + +/// List of checkboxes, each with an associated label and optional user-defined +/// data for identifying its meaning. +pub struct CheckboxGroup { + view: LinearLayout, + user_data: HashMap, +} + +impl CheckboxGroup { + pub fn new() -> Self { + Self { + view: LinearLayout::vertical(), + user_data: HashMap::new(), + } + } + + pub fn add(&mut self, label: &str, checked: bool, data: UDT) { + self.user_data.insert(self.view.len(), data); + self.view.add_child( + LinearLayout::horizontal() + .child(Checkbox::new().with_checked(checked)) + .child(DummyView) + .child(TextView::new(label)), + ); + } + + pub fn entries(&self) -> impl Iterator { + CheckboxGroupIterator { + group: self, + index: 0, + } + } + + pub fn set_enabled(&mut self, enabled: bool) { + let label_style = if enabled { + StyleType::primary() + } else { + StyleType::secondary() + }; + + for i in 0..self.view.len() { + if let Some(label) = self + .view + .get_child_mut(i) + .and_then(|v| v.downcast_mut::()) + .and_then(|v| v.get_child_mut(2)) + .and_then(|v| v.downcast_mut::()) + { + label.set_style(label_style); + } + + if let Some(checkbox) = self + .view + .get_child_mut(i) + .and_then(|v| v.downcast_mut::()) + .and_then(|v| v.get_child_mut(0)) + .and_then(|v| v.downcast_mut::()) + { + checkbox.set_enabled(enabled); + } + } + } + + pub fn update_labels(&mut self, callback: &dyn Fn(bool, &mut TextView, &mut UDT)) { + for i in 0..self.view.len() { + if let Some(inner) = self + .view + .get_child_mut(i) + .and_then(|v| v.downcast_mut::()) + { + let checked = inner + .get_child(0) + .and_then(|v| v.downcast_ref::()) + .map(|v| v.is_checked()) + .unwrap_or(false); + + let label = inner + .get_child_mut(2) + .and_then(|v| v.downcast_mut::()); + + let data = self.user_data.get_mut(&i); + + if let (Some(label), Some(data)) = (label, data) { + callback(checked, label, data); + } + } + } + } +} + +impl ViewWrapper for CheckboxGroup { + cursive::wrap_impl!(self.view: LinearLayout); +} + +pub struct CheckboxGroupIterator<'a, UDT> { + group: &'a CheckboxGroup, + index: usize, +} + +impl<'a, UDT> Iterator for CheckboxGroupIterator<'a, UDT> { + type Item = (bool, &'a UDT); + + fn next(&mut self) -> Option { + let checked = self + .group + .view + .get_child(self.index)? + .downcast_ref::()? + .get_child(0)? + .downcast_ref::()? + .is_checked(); + + let data = self.group.user_data.get(&self.index)?; + + self.index += 1; + Some((checked, data)) + } +} -- 2.56.0