From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 625741FF0B4 for ; Tue, 08 Sep 2026 12:19:09 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 435BE2164F; Tue, 08 Sep 2026 12:18:20 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Subject: [PATCH installer 13/15] tui: views: add widget for displaying a group of checkboxes Date: Tue, 8 Sep 2026 12:16:27 +0200 Message-ID: <20260908101647.1057780-14-c.heiss@proxmox.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260908101647.1057780-1-c.heiss@proxmox.com> References: <20260908101647.1057780-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: 1788862678152 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.348 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: 35DLG3OBJKA5WCNQAAR5YDYPG4SU67AG X-Message-ID-Hash: 35DLG3OBJKA5WCNQAAR5YDYPG4SU67AG 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. Signed-off-by: Christoph Heiss --- proxmox-tui-installer/src/views/mod.rs | 106 ++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/proxmox-tui-installer/src/views/mod.rs b/proxmox-tui-installer/src/views/mod.rs index a343e60..b4896e2 100644 --- a/proxmox-tui-installer/src/views/mod.rs +++ b/proxmox-tui-installer/src/views/mod.rs @@ -5,7 +5,9 @@ use cursive::{ event::{Event, EventResult}, theme::BaseColor, view::{Resizable, ViewWrapper}, - views::{EditView, LinearLayout, NamedView, ResizedView, SelectView, TextView}, + views::{ + Checkbox, DummyView, EditView, LinearLayout, NamedView, ResizedView, SelectView, TextView, + }, }; mod bootdisk; @@ -626,3 +628,105 @@ 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) { + for i in 0..self.view.len() { + 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.55.0