feat!: use more new adw 1.4 widgets

This commit is contained in:
Gabriele Musco 2023-09-24 14:27:06 +02:00
parent 376c7ce01f
commit f4b317251a
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE
5 changed files with 100 additions and 117 deletions

View file

@ -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 = &gtk::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 = &gtk::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 = &gtk::Button {
add_css_class: "pill",
set_halign: gtk::Align::Center,
set_label: "Close",

View file

@ -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::<gtk::Widget>()),
},
}
}

View file

@ -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 = &gtk::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),
}
}

View file

@ -72,8 +72,8 @@ pub fn path_row<F: Fn(Option<String>) + 'static + Clone>(
.title(title)
.subtitle_lines(0)
.activatable(true)
.icon_name(GString::from("folder-open-symbolic"))
.build();
row.add_prefix(&gtk::Image::from_icon_name("folder-open-symbolic"));
if let Some(d) = description {
row.set_subtitle(d);

View file

@ -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 = &gtk::Button {
set_label: "Save",
add_css_class: "suggested-action",
connect_clicked[sender] => move |_| {
sender.input(Self::Input::SaveProfile);
},
pack_end: save_btn = &gtk::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 {