From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id C82971FF16F for ; Tue, 14 Oct 2025 15:23:12 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D7B084062; Tue, 14 Oct 2025 15:22:52 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Tue, 14 Oct 2025 15:21:57 +0200 Message-ID: <20251014132207.1171073-13-c.heiss@proxmox.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014132207.1171073-1-c.heiss@proxmox.com> References: <20251014132207.1171073-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1760448096072 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.038 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH installer 12/14] tui: views: form: allow attaching user-defined data to children X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Allows storing (typesafe) arbitrary data together with each child. No functional changes for existing code. Signed-off-by: Christoph Heiss --- proxmox-tui-installer/src/main.rs | 2 +- proxmox-tui-installer/src/views/bootdisk.rs | 6 ++-- proxmox-tui-installer/src/views/mod.rs | 33 +++++++++++++++++---- proxmox-tui-installer/src/views/network.rs | 2 +- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs index b24f90b..fce9fc2 100644 --- a/proxmox-tui-installer/src/main.rs +++ b/proxmox-tui-installer/src/main.rs @@ -420,7 +420,7 @@ fn password_dialog(siv: &mut Cursive) -> InstallerView { let state = siv.user_data::().unwrap(); let options = &state.options.password; - let inner = FormView::new() + let inner = FormView::<()>::new() .child( "Root password [at least 8 characters]", EditView::new().secret(), diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs index 9f6d235..3566814 100644 --- a/proxmox-tui-installer/src/views/bootdisk.rs +++ b/proxmox-tui-installer/src/views/bootdisk.rs @@ -47,7 +47,7 @@ impl BootdiskOptionsView { pub fn new(siv: &mut Cursive, runinfo: &RuntimeInfo, options: &BootdiskOptions) -> Self { let advanced_options = Arc::new(Mutex::new(options.clone())); - let bootdisk_form = FormView::new() + let bootdisk_form = FormView::<()>::new() .child( "Target harddisk", target_bootdisk_selectview( @@ -152,7 +152,7 @@ impl AdvancedBootdiskOptionsView { let mut view = LinearLayout::vertical() .child(DummyView.full_width()) - .child(FormView::new().child("Filesystem", fstype_select)) + .child(FormView::<()>::new().child("Filesystem", fstype_select)) .child(DummyView.full_width()); // Create the appropriate (inner) advanced options view @@ -493,7 +493,7 @@ impl MultiDiskOptionsView { selectable_disks.push(("-- do not use --".to_owned(), None)); - let mut disk_form = FormView::new(); + let mut disk_form = FormView::<()>::new(); for (i, _) in avail_disks.iter().enumerate() { disk_form.add_child( &format!("Harddisk {i}"), diff --git a/proxmox-tui-installer/src/views/mod.rs b/proxmox-tui-installer/src/views/mod.rs index 43ca999..5723fed 100644 --- a/proxmox-tui-installer/src/views/mod.rs +++ b/proxmox-tui-installer/src/views/mod.rs @@ -1,4 +1,4 @@ -use std::{net::IpAddr, str::FromStr, sync::Arc}; +use std::{collections::HashMap, net::IpAddr, str::FromStr, sync::Arc}; use cursive::{ Printer, Rect, Vec2, View, @@ -414,17 +414,21 @@ impl FormViewGetValue for DiskSizeEditView { } } -pub struct FormView { +pub struct FormView { view: LinearLayout, + user_data: HashMap, } -impl FormView { +impl FormView { pub fn new() -> Self { let view = LinearLayout::horizontal() .child(LinearLayout::vertical().full_width()) .child(LinearLayout::vertical().full_width()); - Self { view } + Self { + view, + user_data: HashMap::new(), + } } pub fn add_child(&mut self, label: &str, view: impl View) { @@ -432,6 +436,12 @@ impl FormView { self.add_to_column(1, view); } + pub fn add_child_with_data(&mut self, label: &str, view: impl View, data: UDT) { + self.add_to_column(0, TextView::new(format!("{label}: ")).no_wrap()); + self.add_to_column(1, view); + self.user_data.insert(self.len() - 1, data); + } + pub fn child(mut self, label: &str, view: impl View) -> Self { self.add_child(label, view); self @@ -453,6 +463,19 @@ impl FormView { .downcast_ref::() } + pub fn get_child_with_data(&self, index: usize) -> Option<(&T, &UDT)> { + let view = self + .view + .get_child(1)? + .downcast_ref::>()? + .get_inner() + .get_child(index)? + .downcast_ref::()?; + + let data = self.user_data.get(&index)?; + Some((view, data)) + } + pub fn get_child_mut(&mut self, index: usize) -> Option<&mut T> { self.view .get_child_mut(1)? @@ -509,7 +532,7 @@ impl FormView { } } -impl ViewWrapper for FormView { +impl ViewWrapper for FormView { cursive::wrap_impl!(self.view: LinearLayout); fn wrap_important_area(&self, size: Vec2) -> Rect { diff --git a/proxmox-tui-installer/src/views/network.rs b/proxmox-tui-installer/src/views/network.rs index 5e3e258..960c25e 100644 --- a/proxmox-tui-installer/src/views/network.rs +++ b/proxmox-tui-installer/src/views/network.rs @@ -33,7 +33,7 @@ impl NetworkOptionsView { ifaces_selection.set_selection(selected); - let view = FormView::new() + let form = FormView::<()>::new() .child("Management interface", ifaces_selection) .child( "Hostname (FQDN)", -- 2.51.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel