From: Christoph Heiss <c.heiss@proxmox.com>
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 [thread overview]
Message-ID: <20260908101647.1057780-14-c.heiss@proxmox.com> (raw)
In-Reply-To: <20260908101647.1057780-1-c.heiss@proxmox.com>
Adds a simple view which displays multiple checkboxes, each optionally
associated with some user-defined data.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
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<UDT = ()> {
+ view: LinearLayout,
+ user_data: HashMap<usize, UDT>,
+}
+
+impl<UDT> CheckboxGroup<UDT> {
+ 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<Item = (bool, &UDT)> {
+ 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::<LinearLayout>())
+ .and_then(|v| v.get_child_mut(0))
+ .and_then(|v| v.downcast_mut::<Checkbox>())
+ {
+ 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::<LinearLayout>())
+ {
+ let checked = inner
+ .get_child(0)
+ .and_then(|v| v.downcast_ref::<Checkbox>())
+ .map(|v| v.is_checked())
+ .unwrap_or(false);
+
+ let label = inner
+ .get_child_mut(2)
+ .and_then(|v| v.downcast_mut::<TextView>());
+
+ let data = self.user_data.get_mut(&i);
+
+ if let (Some(label), Some(data)) = (label, data) {
+ callback(checked, label, data);
+ }
+ }
+ }
+ }
+}
+
+impl<UDT: Send + Sync + 'static> ViewWrapper for CheckboxGroup<UDT> {
+ cursive::wrap_impl!(self.view: LinearLayout);
+}
+
+pub struct CheckboxGroupIterator<'a, UDT> {
+ group: &'a CheckboxGroup<UDT>,
+ index: usize,
+}
+
+impl<'a, UDT> Iterator for CheckboxGroupIterator<'a, UDT> {
+ type Item = (bool, &'a UDT);
+
+ fn next(&mut self) -> Option<Self::Item> {
+ let checked = self
+ .group
+ .view
+ .get_child(self.index)?
+ .downcast_ref::<LinearLayout>()?
+ .get_child(0)?
+ .downcast_ref::<Checkbox>()?
+ .is_checked();
+
+ let data = self.group.user_data.get(&self.index)?;
+
+ self.index += 1;
+ Some((checked, data))
+ }
+}
--
2.55.0
next prev parent reply other threads:[~2026-09-08 10:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 10:16 [PATCH installer/proxmox 00/15] partially fix #2164: add bond setup across all installers Christoph Heiss
2026-09-08 10:16 ` [PATCH proxmox 01/15] installer-types: use `MacAddress` type where applicable Christoph Heiss
2026-09-08 10:16 ` [PATCH proxmox 02/15] installer-types: answer: add options for configuring management bond Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 03/15] install: run make tidy Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 04/15] tree-wide: use `MacAddress` type instead of string for MAC addresses Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 05/15] install: factor out /etc/network/interfaces setup into own subroutine Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 06/15] install: do not rely on interface name map to be fully populated Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 07/15] install: config: add option for setting up bond on management interface Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 08/15] install: network: set up management bond if requested Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 09/15] gui: network: factor out name pinning into advanced options dialog Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 10/15] gui: network: add bond setup options to " Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 11/15] auto: pass trough management network bond options to low-level installer Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 12/15] tui: drop long obsolete comment about logo formatting Christoph Heiss
2026-09-08 10:16 ` Christoph Heiss [this message]
2026-09-08 10:16 ` [PATCH installer 14/15] tui: network: factor out name pinning into advanced options dialog Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 15/15] tui: network: add bond setup options to advanced network dialog Christoph Heiss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260908101647.1057780-14-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.