public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 12/14] tui: views: form: allow attaching user-defined data to children
Date: Tue, 14 Oct 2025 15:21:57 +0200	[thread overview]
Message-ID: <20251014132207.1171073-13-c.heiss@proxmox.com> (raw)
In-Reply-To: <20251014132207.1171073-1-c.heiss@proxmox.com>

Allows storing (typesafe) arbitrary data together with each child.

No functional changes for existing code.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 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::<InstallerState>().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<T: View> MultiDiskOptionsView<T> {
 
         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<f64> for DiskSizeEditView {
     }
 }
 
-pub struct FormView {
+pub struct FormView<UDT = ()> {
     view: LinearLayout,
+    user_data: HashMap<usize, UDT>,
 }
 
-impl FormView {
+impl<UDT> FormView<UDT> {
     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::<T>()
     }
 
+    pub fn get_child_with_data<T: View>(&self, index: usize) -> Option<(&T, &UDT)> {
+        let view = self
+            .view
+            .get_child(1)?
+            .downcast_ref::<ResizedView<LinearLayout>>()?
+            .get_inner()
+            .get_child(index)?
+            .downcast_ref::<T>()?;
+
+        let data = self.user_data.get(&index)?;
+        Some((view, data))
+    }
+
     pub fn get_child_mut<T: View>(&mut self, index: usize) -> Option<&mut T> {
         self.view
             .get_child_mut(1)?
@@ -509,7 +532,7 @@ impl FormView {
     }
 }
 
-impl ViewWrapper for FormView {
+impl<UDT: Send + Sync + 'static> ViewWrapper for FormView<UDT> {
     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


  parent reply	other threads:[~2025-10-14 13:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 13:21 [pve-devel] [PATCH installer 00/14] support network interface name pinning Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 01/14] test: parse-kernel-cmdline: fix module import statement Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 02/14] install: add support for network interface name pinning Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 03/14] run env: network: add kernel driver name to network interface info Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 04/14] common: utils: fix clippy warnings Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 05/14] common: setup: simplify network address list serialization Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 06/14] common: implement support for `network_interface_pin_map` config Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 07/14] auto: add support for pinning network interface names Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 08/14] assistant: verify network settings in `validate-answer` subcommand Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 09/14] post-hook: avoid redundant Option<bool> for (de-)serialization Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 10/14] post-hook: add network interface name and pinning status Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 11/14] tui: views: move network options view to own module Christoph Heiss
2025-10-14 13:21 ` Christoph Heiss [this message]
2025-10-14 13:21 ` [pve-devel] [PATCH installer 13/14] tui: add support for pinning network interface names Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 14/14] gui: " Christoph Heiss
2025-10-14 15:04   ` Maximiliano Sandoval
2025-10-16 12:01     ` 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=20251014132207.1171073-13-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal