From f522afb14cfb3e686b8e44c0de0ac3576b67811f Mon Sep 17 00:00:00 2001 From: Christoph Heiss Date: Wed, 31 May 2023 10:44:05 +0200 Subject: [PATCH] tui: move abort/previous/next buttons into `InstallerView` Signed-off-by: Christoph Heiss --- proxmox-tui-installer/src/main.rs | 72 +++++++++++++++++-------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs index 2139b9f..a2fc0f9 100644 --- a/proxmox-tui-installer/src/main.rs +++ b/proxmox-tui-installer/src/main.rs @@ -31,7 +31,24 @@ struct InstallerView { } impl InstallerView { - pub fn new(view: T) -> Self { + pub fn new(view: T, next_cb: Box) -> Self { + let inner = LinearLayout::vertical().child(view).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("Next", next_cb)), + )); + + Self::with_raw(inner) + } + + pub fn with_raw(view: T) -> Self { let inner = LinearLayout::vertical() .child(PaddedView::lrtb(1, 1, 0, 1, TextView::new(LOGO).center())) .child(Dialog::around(view).title(TITLE)); @@ -217,7 +234,7 @@ fn license_dialog() -> InstallerView { .child(PaddedView::lrtb( 1, 1, - 0, + 1, 0, LinearLayout::horizontal() .child(abort_install_button()) @@ -225,7 +242,7 @@ fn license_dialog() -> InstallerView { .child(Button::new("I agree", add_next_screen(&bootdisk_dialog))), )); - InstallerView::new(inner) + InstallerView::with_raw(inner) } fn bootdisk_dialog(siv: &mut Cursive) -> InstallerView { @@ -277,37 +294,28 @@ fn bootdisk_dialog(siv: &mut Cursive) -> InstallerView { LinearLayout::horizontal() .child(LvmBootdiskOptionsView::new(&options.disks, &advanced)) .with_name("bootdisk-options"), - ) - .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("Next", |siv| { - let options = siv - .call_on_name("bootdisk-options", |v: &mut LinearLayout| { - v.get_child_mut(0)? - .downcast_mut::()? - .get_values() - .map(AdvancedBootdiskOptions::Lvm) - }) - .flatten() - .unwrap(); + ); - siv.with_user_data(|opts: &mut InstallerOptions| { - opts.bootdisk.advanced = options; - }); + InstallerView::new( + inner, + Box::new(|siv| { + let options = siv + .call_on_name("bootdisk-options", |v: &mut LinearLayout| { + v.get_child_mut(0)? + .downcast_mut::()? + .get_values() + .map(AdvancedBootdiskOptions::Lvm) + }) + .flatten() + .unwrap(); - add_next_screen(&location_and_tz_dialog)(siv) - })), - )); + siv.with_user_data(|opts: &mut InstallerOptions| { + opts.bootdisk.advanced = options; + }); - InstallerView::new(inner) + add_next_screen(&location_and_tz_dialog)(siv) + }), + ) } struct LvmBootdiskOptionsView { @@ -372,5 +380,5 @@ impl ViewWrapper for LvmBootdiskOptionsView { } fn location_and_tz_dialog(_: &mut Cursive) -> InstallerView { - InstallerView::new(DummyView) + InstallerView::new(DummyView, Box::new(|_| {})) }