From f4b317251a109f01e584dec38aba7b7854a23f27 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Sun, 24 Sep 2023 14:27:06 +0200 Subject: [PATCH] feat!: use more new adw 1.4 widgets --- src/ui/build_window.rs | 133 +++++++++++++++--------------- src/ui/fbt_config_editor.rs | 26 ++---- src/ui/libsurvive_setup_window.rs | 32 ++++--- src/ui/preference_rows.rs | 2 +- src/ui/profile_editor.rs | 24 +++--- 5 files changed, 100 insertions(+), 117 deletions(-) diff --git a/src/ui/build_window.rs b/src/ui/build_window.rs index a0383ba..ba8056a 100644 --- a/src/ui/build_window.rs +++ b/src/ui/build_window.rs @@ -53,82 +53,83 @@ impl SimpleComponent for BuildWindow { set_modal: true, set_default_size: (520, 400), set_hide_on_close: true, - gtk::Box { + adw::ToolbarView { + set_top_bar_style: adw::ToolbarStyle::Flat, + set_bottom_bar_style: adw::ToolbarStyle::Flat, set_vexpand: true, set_hexpand: true, - set_orientation: gtk::Orientation::Vertical, - set_spacing: 12, - gtk::WindowHandle { - set_vexpand: false, - set_hexpand: true, - adw::HeaderBar { - set_show_end_title_buttons: false, - set_show_start_title_buttons: false, - add_css_class: "flat", - #[wrap(Some)] - set_title_widget: title_label = >k::Label { - #[track = "model.changed(BuildWindow::title())"] - set_markup: &model.title, - add_css_class: "title", - }, - } - }, - gtk::Box { - set_orientation: gtk::Orientation::Horizontal, - set_hexpand: true, - set_halign: gtk::Align::Center, - set_spacing: 12, - #[name(build_status_label)] - gtk::Label { - #[track = "model.changed(BuildWindow::build_status())"] - set_markup: match &model.build_status { - BuildStatus::Building => "Build in progress...".to_string(), - BuildStatus::Done => "Build done, you can close this window".to_string(), - BuildStatus::Error(code) => { - format!("Build failed: \"{c}\"", c = code) - } - }.as_str(), - add_css_class: "title-2", - set_wrap: true, - set_wrap_mode: gtk::pango::WrapMode::Word, - set_justify: gtk::Justification::Center, - }, - gtk::Button { - #[track = "model.changed(BuildWindow::build_status())"] - set_visible: match &model.build_status { - BuildStatus::Building => true, - _ => false, - }, - add_css_class: "destructive-action", - add_css_class: "circular", - set_icon_name: "window-close-symbolic", - set_tooltip_text: Some("Cancel build"), - connect_clicked[sender] => move |_| { - sender.output(Self::Output::CancelBuild); - } + add_top_bar: top_bar = &adw::HeaderBar { + set_show_end_title_buttons: false, + set_show_start_title_buttons: false, + #[wrap(Some)] + set_title_widget: title_label = &adw::WindowTitle { + #[track = "model.changed(BuildWindow::title())"] + set_title: &model.title, }, }, - #[name(scrolledwin)] - gtk::ScrolledWindow { - set_hexpand: true, + #[wrap(Some)] + set_content: content = >k::Box { + set_orientation: gtk::Orientation::Vertical, set_vexpand: true, + set_hexpand: true, set_margin_all: 12, - add_css_class: "card", - set_overflow: gtk::Overflow::Hidden, - #[name(textview)] - gtk::TextView { + gtk::Box { + set_orientation: gtk::Orientation::Horizontal, + set_hexpand: true, + set_halign: gtk::Align::Center, + set_spacing: 12, + #[name(build_status_label)] + gtk::Label { + #[track = "model.changed(BuildWindow::build_status())"] + set_markup: match &model.build_status { + BuildStatus::Building => "Build in progress...".to_string(), + BuildStatus::Done => "Build done, you can close this window".to_string(), + BuildStatus::Error(code) => { + format!("Build failed: \"{c}\"", c = code) + } + }.as_str(), + add_css_class: "title-2", + set_wrap: true, + set_wrap_mode: gtk::pango::WrapMode::Word, + set_justify: gtk::Justification::Center, + }, + gtk::Button { + #[track = "model.changed(BuildWindow::build_status())"] + set_visible: match &model.build_status { + BuildStatus::Building => true, + _ => false, + }, + add_css_class: "destructive-action", + add_css_class: "circular", + set_icon_name: "window-close-symbolic", + set_tooltip_text: Some("Cancel build"), + connect_clicked[sender] => move |_| { + sender.output(Self::Output::CancelBuild); + } + }, + }, + #[name(scrolledwin)] + gtk::ScrolledWindow { set_hexpand: true, set_vexpand: true, - set_editable: false, - set_monospace: true, - set_left_margin: 6, - set_right_margin: 6, - set_top_margin: 6, - set_bottom_margin: 6, - set_buffer: Some(&model.textbuf), + set_margin_all: 12, + add_css_class: "card", + set_overflow: gtk::Overflow::Hidden, + #[name(textview)] + gtk::TextView { + set_hexpand: true, + set_vexpand: true, + set_editable: false, + set_monospace: true, + set_left_margin: 6, + set_right_margin: 6, + set_top_margin: 6, + set_bottom_margin: 6, + set_buffer: Some(&model.textbuf), + }, }, }, - gtk::Button { + add_bottom_bar: bottom_bar = >k::Button { add_css_class: "pill", set_halign: gtk::Align::Center, set_label: "Close", diff --git a/src/ui/fbt_config_editor.rs b/src/ui/fbt_config_editor.rs index c1cc169..c81a536 100644 --- a/src/ui/fbt_config_editor.rs +++ b/src/ui/fbt_config_editor.rs @@ -7,10 +7,7 @@ use crate::{ withclones, }; use adw::prelude::*; -use relm4::{ - factory::{AsyncFactoryVecDeque, FactoryVecDeque}, - prelude::*, -}; +use relm4::{factory::AsyncFactoryVecDeque, prelude::*}; #[tracker::track] pub struct FbtConfigEditor { @@ -50,23 +47,16 @@ impl SimpleComponent for FbtConfigEditor { set_transient_for: Some(&init.root_win), set_default_height: 500, set_default_width: 600, - gtk::Box { - set_vexpand: true, - set_hexpand: true, - set_orientation: gtk::Orientation::Vertical, - gtk::WindowHandle { + adw::ToolbarView { + set_top_bar_style: adw::ToolbarStyle::Flat, + add_top_bar: headerbar = &adw::HeaderBar { set_vexpand: false, set_hexpand: true, - #[name(headerbar)] - adw::HeaderBar { - set_vexpand: false, - set_hexpand: true, - add_css_class: "flat", - pack_start: &add_btn, - pack_end: &save_btn, - }, + add_css_class: "flat", + pack_start: &add_btn, + pack_end: &save_btn, }, - append: model.tracker_role_groups.widget(), + set_content: Some(&model.tracker_role_groups.widget().clone().upcast::()), }, } } diff --git a/src/ui/libsurvive_setup_window.rs b/src/ui/libsurvive_setup_window.rs index ad34887..1f2fb7c 100644 --- a/src/ui/libsurvive_setup_window.rs +++ b/src/ui/libsurvive_setup_window.rs @@ -97,24 +97,18 @@ impl SimpleComponent for LibsurviveSetupWindow { set_modal: true, set_default_size: (520, 400), set_hide_on_close: true, - gtk::Box { - set_orientation: gtk::Orientation::Vertical, - set_hexpand: true, - set_vexpand: true, - set_spacing: 12, - set_margin_all: 12, - gtk::WindowHandle { - adw::HeaderBar { - add_css_class: "flat", - #[wrap(Some)] - set_title_widget: title_label = >k::Label { - set_label: "Setup Lighthouses", - add_css_class: "title", - }, - } + adw::ToolbarView { + set_top_bar_style: adw::ToolbarStyle::Flat, + set_bottom_bar_style: adw::ToolbarStyle::Flat, + add_top_bar: top_bar = &adw::HeaderBar { + add_css_class: "flat", + #[wrap(Some)] + set_title_widget: title_label = &adw::WindowTitle { + set_title: "Setup Lighthouses", + }, }, - #[name(carousel)] - adw::Carousel { + #[wrap(Some)] + set_content: carousel = &adw::Carousel { set_allow_long_swipes: false, set_allow_scroll_wheel: false, set_allow_mouse_drag: false, @@ -344,7 +338,9 @@ impl SimpleComponent for LibsurviveSetupWindow { } }, }, - adw::CarouselIndicatorDots { + add_bottom_bar: dots = &adw::CarouselIndicatorDots { + set_margin_top: 12, + set_margin_bottom: 12, set_carousel: Some(&carousel), } } diff --git a/src/ui/preference_rows.rs b/src/ui/preference_rows.rs index 65a2be4..0f28430 100644 --- a/src/ui/preference_rows.rs +++ b/src/ui/preference_rows.rs @@ -72,8 +72,8 @@ pub fn path_row) + 'static + Clone>( .title(title) .subtitle_lines(0) .activatable(true) - .icon_name(GString::from("folder-open-symbolic")) .build(); + row.add_prefix(>k::Image::from_icon_name("folder-open-symbolic")); if let Some(d) = description { row.set_subtitle(d); diff --git a/src/ui/profile_editor.rs b/src/ui/profile_editor.rs index 57fd93c..d37c0ac 100644 --- a/src/ui/profile_editor.rs +++ b/src/ui/profile_editor.rs @@ -55,26 +55,22 @@ impl SimpleComponent for ProfileEditor { set_title: Some(model.profile.borrow().name.as_str()), set_default_height: 500, set_default_width: 600, - gtk::Box { - set_orientation: gtk::Orientation::Vertical, + adw::ToolbarView { + set_top_bar_style: adw::ToolbarStyle::Flat, set_hexpand: true, set_vexpand: true, - gtk::WindowHandle { - set_hexpand: true, + add_top_bar: top_bar = &adw::HeaderBar { set_vexpand: false, - adw::HeaderBar { - set_vexpand: false, - add_css_class: "flat", - pack_end: save_btn = >k::Button { - set_label: "Save", - add_css_class: "suggested-action", - connect_clicked[sender] => move |_| { - sender.input(Self::Input::SaveProfile); - }, + pack_end: save_btn = >k::Button { + set_label: "Save", + add_css_class: "suggested-action", + connect_clicked[sender] => move |_| { + sender.input(Self::Input::SaveProfile); }, }, }, - adw::PreferencesPage { + #[wrap(Some)] + set_content: pref_page = &adw::PreferencesPage { set_hexpand: true, set_vexpand: true, add: maingrp = &adw::PreferencesGroup {