From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 20EC78630 for ; Wed, 21 Jun 2023 16:48:16 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0A49E1F6EA for ; Wed, 21 Jun 2023 16:48:16 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 21 Jun 2023 16:48:15 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8E8A842651 for ; Wed, 21 Jun 2023 16:48:14 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Wed, 21 Jun 2023 16:48:13 +0200 Message-Id: <20230621144813.2317113-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH] tui: focus next button by default 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: , X-List-Received-Date: Wed, 21 Jun 2023 14:48:16 -0000 except the password dialog, since the user must provide input to do that, we have to set the focus index on all relevant views Signed-off-by: Dominik Csapak --- not sure if this is the correct approach, also the extra parameter feels slightly wrong, but didn't found a nicer way to do this any errors from focusing will be ignrored, but that shouldn't happen anyway until we add/remove buttons and the index changes alternatively we could create a second 'new_with_focus_next' (or 'without') that gets called respectively, but also seems a bit weird for that proxmox-tui-installer/src/main.rs | 101 +++++++++++++++--------------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs index 20cb31b..5eaba7f 100644 --- a/proxmox-tui-installer/src/main.rs +++ b/proxmox-tui-installer/src/main.rs @@ -63,21 +63,21 @@ impl InstallerView { state: &InstallerState, view: T, next_cb: Box, + focus_next: bool, ) -> Self { - let inner = LinearLayout::vertical() + let mut bbar = LinearLayout::horizontal() + .child(abort_install_button()) + .child(DummyView.full_width()) + .child(Button::new("Previous", switch_to_prev_screen)) + .child(DummyView) + .child(Button::new("Next", next_cb)); + let _ = bbar.set_focus_index(4); // ignore errors + let mut inner = LinearLayout::vertical() .child(PaddedView::lrtb(0, 0, 1, 1, view)) - .child(PaddedView::lrtb( - 1, - 1, - 0, - 0, - LinearLayout::horizontal() - .child(abort_install_button()) - .child(DummyView.full_width()) - .child(Button::new("Previous", switch_to_prev_screen)) - .child(DummyView) - .child(Button::new("Next", next_cb)), - )); + .child(PaddedView::lrtb(1, 1, 0, 0, bbar)); + if focus_next { + let _ = inner.set_focus_index(1); // ignore errors + } Self::with_raw(state, inner) } @@ -378,7 +378,15 @@ fn get_eula() -> String { fn license_dialog(siv: &mut Cursive) -> InstallerView { let state = siv.user_data::().unwrap(); - let inner = LinearLayout::vertical() + let mut bbar = LinearLayout::horizontal() + .child(abort_install_button()) + .child(DummyView.full_width()) + .child(Button::new("I agree", |siv| { + switch_to_next_screen(siv, InstallerStep::Bootdisk, &bootdisk_dialog) + })); + let _ = bbar.set_focus_index(2); // ignore errors + + let mut inner = LinearLayout::vertical() .child(PaddedView::lrtb( 0, 0, @@ -389,18 +397,9 @@ fn license_dialog(siv: &mut Cursive) -> InstallerView { .child(Panel::new(ScrollView::new( TextView::new(get_eula()).center(), ))) - .child(PaddedView::lrtb( - 1, - 1, - 1, - 0, - LinearLayout::horizontal() - .child(abort_install_button()) - .child(DummyView.full_width()) - .child(Button::new("I agree", |siv| { - switch_to_next_screen(siv, InstallerStep::Bootdisk, &bootdisk_dialog) - })), - )); + .child(PaddedView::lrtb(1, 1, 1, 0, bbar)); + + let _ = inner.set_focus_index(2); // ignore errors InstallerView::with_raw(state, inner) } @@ -428,6 +427,7 @@ fn bootdisk_dialog(siv: &mut Cursive) -> InstallerView { _ => siv.add_layer(Dialog::info("Invalid values")), } }), + true, ) } @@ -453,6 +453,7 @@ fn timezone_dialog(siv: &mut Cursive) -> InstallerView { _ => siv.add_layer(Dialog::info("Invalid values")), } }), + true, ) } @@ -518,6 +519,7 @@ fn password_dialog(siv: &mut Cursive) -> InstallerView { _ => siv.add_layer(Dialog::info("Invalid values")), } }), + false, ) } @@ -613,6 +615,7 @@ fn network_dialog(siv: &mut Cursive) -> InstallerView { _ => siv.add_layer(Dialog::info("Invalid values")), } }), + true, ) } @@ -643,7 +646,27 @@ impl TableViewItem for SummaryOption { fn summary_dialog(siv: &mut Cursive) -> InstallerView { let state = siv.user_data::().unwrap(); - let inner = LinearLayout::vertical() + let mut bbar = LinearLayout::horizontal() + .child(abort_install_button()) + .child(DummyView.full_width()) + .child(Button::new("Previous", switch_to_prev_screen)) + .child(DummyView) + .child(Button::new("Install", |siv| { + let autoreboot = siv + .find_name("reboot-after-install") + .map(|v: ViewRef| v.is_checked()) + .unwrap_or_default(); + + siv.with_user_data(|state: &mut InstallerState| { + state.options.autoreboot = autoreboot; + }); + + switch_to_next_screen(siv, InstallerStep::Install, &install_progress_dialog); + })); + + let _ = bbar.set_focus_index(4); // ignore errors + + let mut inner = LinearLayout::vertical() .child(PaddedView::lrtb( 0, 0, @@ -665,29 +688,9 @@ fn summary_dialog(siv: &mut Cursive) -> InstallerView { ) .child(DummyView.full_width()), ) - .child(PaddedView::lrtb( - 1, - 1, - 1, - 0, - LinearLayout::horizontal() - .child(abort_install_button()) - .child(DummyView.full_width()) - .child(Button::new("Previous", switch_to_prev_screen)) - .child(DummyView) - .child(Button::new("Install", |siv| { - let autoreboot = siv - .find_name("reboot-after-install") - .map(|v: ViewRef| v.is_checked()) - .unwrap_or_default(); + .child(PaddedView::lrtb(1, 1, 1, 0, bbar)); - siv.with_user_data(|state: &mut InstallerState| { - state.options.autoreboot = autoreboot; - }); - - switch_to_next_screen(siv, InstallerStep::Install, &install_progress_dialog); - })), - )); + let _ = inner.set_focus_index(2); // ignore errors InstallerView::with_raw(state, inner) } -- 2.30.2