From 6fa30214246f4a35ef6f1726ac33ff6c2ce98732 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Tue, 12 Sep 2023 07:45:33 +0200 Subject: [PATCH] feat: use cards for all views in main view --- data/style.css | 3 + src/ui/install_wivrn_box.rs | 21 ++---- src/ui/main_view.rs | 112 ++++++----------------------- src/ui/steam_launch_options_box.rs | 17 ++--- src/ui/util.rs | 23 ++++++ 5 files changed, 55 insertions(+), 121 deletions(-) diff --git a/data/style.css b/data/style.css index e69de29..b84d6de 100644 --- a/data/style.css +++ b/data/style.css @@ -0,0 +1,3 @@ +.padded { + padding: 18px; +} diff --git a/src/ui/install_wivrn_box.rs b/src/ui/install_wivrn_box.rs index 9adacc7..cd2e030 100644 --- a/src/ui/install_wivrn_box.rs +++ b/src/ui/install_wivrn_box.rs @@ -70,20 +70,15 @@ impl SimpleComponent for InstallWivrnBox { gtk::Box { set_orientation: gtk::Orientation::Vertical, set_spacing: 12, - set_margin_top: 12, - set_margin_bottom: 12, + set_margin_all: 12, + add_css_class: "card", + add_css_class: "padded", #[track = "model.changed(Self::selected_profile())"] set_visible: model.selected_profile.xrservice_type == XRServiceType::Wivrn, - gtk::Separator { - set_orientation: gtk::Orientation::Horizontal, - set_hexpand: true, - }, gtk::Label { add_css_class: "heading", set_hexpand: true, set_xalign: 0.0, - set_margin_start: 12, - set_margin_end: 12, set_label: "Install WiVRn APK", set_wrap: true, set_wrap_mode: gtk::pango::WrapMode::Word, @@ -91,22 +86,18 @@ impl SimpleComponent for InstallWivrnBox { gtk::Label { add_css_class: "dim-label", set_hexpand: true, - set_xalign: 0.0, - set_margin_start: 12, - set_margin_end: 12, set_label: concat!( "Install the WiVRn APK on your standalong Android headset. ", "You will need to enable Developer Mode on your headset, ", "then press the \"Install WiVRn\" button." ), + set_xalign: 0.0, set_wrap: true, set_wrap_mode: gtk::pango::WrapMode::Word, }, gtk::MenuButton { add_css_class: "suggested-action", set_label: "Install WiVRn", - set_margin_start: 12, - set_margin_end: 12, set_halign: gtk::Align::Start, #[track = "model.changed(Self::install_wivrn_status())"] set_sensitive: model.install_wivrn_status != InstallWivrnStatus::InProgress, @@ -114,8 +105,6 @@ impl SimpleComponent for InstallWivrnBox { }, gtk::Label { add_css_class: "error", - set_margin_start: 12, - set_margin_end: 12, set_xalign: 0.0, #[track = "model.changed(Self::install_wivrn_status())"] set_visible: matches!(&model.install_wivrn_status, InstallWivrnStatus::Done(Some(_))), @@ -127,8 +116,6 @@ impl SimpleComponent for InstallWivrnBox { }, gtk::Label { add_css_class: "success", - set_margin_start: 12, - set_margin_end: 12, set_xalign: 0.0, #[track = "model.changed(Self::install_wivrn_status())"] set_visible: model.install_wivrn_status == InstallWivrnStatus::Success, diff --git a/src/ui/main_view.rs b/src/ui/main_view.rs index 41ffb19..7254cf8 100644 --- a/src/ui/main_view.rs +++ b/src/ui/main_view.rs @@ -17,7 +17,7 @@ use crate::ui::app::{ DebugViewToggleAction, }; use crate::ui::profile_editor::ProfileEditorInit; -use crate::ui::util::limit_dropdown_width; +use crate::ui::util::{limit_dropdown_width, warning_heading}; use crate::xr_devices::XRDevices; use gtk::prelude::*; use relm4::adw::traits::MessageDialogExt; @@ -151,7 +151,7 @@ impl SimpleComponent for MainView { set_hexpand: true, set_vexpand: true, gtk::Box { - set_spacing: 12, + set_spacing: 6, set_margin_top: 12, set_margin_bottom: 12, set_orientation: gtk::Orientation::Vertical, @@ -195,8 +195,9 @@ impl SimpleComponent for MainView { set_hexpand: true, set_vexpand: false, set_spacing: 12, - set_margin_top: 12, - set_margin_bottom: 12, + set_margin_all: 12, + add_css_class: "card", + add_css_class: "padded", #[track = "model.changed(Self::selected_profile())"] set_visible: match mount_has_nosuid(model.selected_profile.prefix.as_str()) { Ok(b) => b, @@ -208,26 +209,7 @@ impl SimpleComponent for MainView { false }, }, - gtk::Separator { - set_orientation: gtk::Orientation::Horizontal, - set_hexpand: true, - }, - gtk::Box { - set_orientation: gtk::Orientation::Horizontal, - set_margin_start: 12, - set_margin_end: 12, - set_spacing: 12, - set_hexpand: true, - gtk::Image { - set_icon_name: Some("dialog-warning-symbolic"), - add_css_class: "warning", - }, - gtk::Label { - add_css_class: "warning", - add_css_class: "heading", - set_label: "Warning" - } - }, + warning_heading(), gtk::Label { set_label: concat!( "Your current prefix is inside a partition ", @@ -236,9 +218,8 @@ impl SimpleComponent for MainView { "and will cause noticeable stutter when running XR ", "applications." ), - set_margin_start: 12, - set_margin_end: 12, add_css_class: "warning", + set_xalign: 0.0, set_wrap: true, set_wrap_mode: gtk::pango::WrapMode::Word, } @@ -248,39 +229,20 @@ impl SimpleComponent for MainView { set_hexpand: true, set_vexpand: false, set_spacing: 12, - set_margin_top: 12, - set_margin_bottom: 12, + set_margin_all: 12, + add_css_class: "card", + add_css_class: "padded", #[track = "model.changed(Self::selected_profile())"] set_visible: model.selected_profile.lighthouse_driver == LighthouseDriver::SteamVR && !chaperone_info_exists(), - gtk::Separator { - set_orientation: gtk::Orientation::Horizontal, - set_hexpand: true, - }, - gtk::Box { - set_orientation: gtk::Orientation::Horizontal, - set_margin_start: 12, - set_margin_end: 12, - set_spacing: 12, - set_hexpand: true, - gtk::Image { - set_icon_name: Some("dialog-warning-symbolic"), - add_css_class: "warning", - }, - gtk::Label { - add_css_class: "warning", - add_css_class: "heading", - set_label: "Warning" - } - }, + warning_heading(), gtk::Label { set_label: concat!( "SteamVR room configuration not found.\n", "To use the SteamVR lighthouse driver, you ", "will need to run SteamVR and perform the room setup.", ), - set_margin_start: 12, - set_margin_end: 12, add_css_class: "warning", + set_xalign: 0.0, set_wrap: true, set_wrap_mode: gtk::pango::WrapMode::Word, } @@ -290,34 +252,16 @@ impl SimpleComponent for MainView { set_hexpand: true, set_vexpand: false, set_spacing: 12, - set_margin_top: 12, - set_margin_bottom: 12, + set_margin_all: 12, + add_css_class: "card", + add_css_class: "padded", #[track = "model.changed(Self::selected_profile())"] set_visible: match get_amd_gpu_power_profile() { None => false, Some(GpuPowerProfile::VR) => false, Some(_) => true, }, - gtk::Separator { - set_orientation: gtk::Orientation::Horizontal, - set_hexpand: true, - }, - gtk::Box { - set_orientation: gtk::Orientation::Horizontal, - set_margin_start: 12, - set_margin_end: 12, - set_spacing: 12, - set_hexpand: true, - gtk::Image { - set_icon_name: Some("dialog-warning-symbolic"), - add_css_class: "warning", - }, - gtk::Label { - add_css_class: "warning", - add_css_class: "heading", - set_label: "Warning" - } - }, + warning_heading(), gtk::Label { set_label: concat!( "Your AMD GPU Power Profile is not set to VR. ", @@ -325,15 +269,12 @@ impl SimpleComponent for MainView { "applications. Activate the VR profile witrh the ", "following command:", ), - set_margin_start: 12, - set_margin_end: 12, add_css_class: "warning", + set_xalign: 0.0, set_wrap: true, set_wrap_mode: gtk::pango::WrapMode::Word, }, gtk::Box { - set_margin_start: 12, - set_margin_end: 12, set_orientation: gtk::Orientation::Horizontal, set_spacing: 6, gtk::ScrolledWindow { @@ -380,8 +321,6 @@ impl SimpleComponent for MainView { }, }, gtk::Button { - set_margin_start: 12, - set_margin_end: 12, set_halign: gtk::Align::Start, set_label: "Refresh", connect_clicked[sender, profiles_dropdown] => move |_| { @@ -396,20 +335,15 @@ impl SimpleComponent for MainView { set_hexpand: true, set_vexpand: false, set_spacing: 12, - set_margin_top: 12, - set_margin_bottom: 12, + set_margin_all: 12, + add_css_class: "card", + add_css_class: "padded", #[track = "model.changed(Self::selected_profile())"] set_visible: model.selected_profile.lighthouse_driver == LighthouseDriver::Survive, - gtk::Separator { - set_orientation: gtk::Orientation::Horizontal, - set_hexpand: true, - }, gtk::Label { add_css_class: "heading", set_hexpand: true, set_xalign: 0.0, - set_margin_start: 12, - set_margin_end: 12, set_label: "Libsurvive Calibration", set_wrap: true, set_wrap_mode: gtk::pango::WrapMode::Word, @@ -417,22 +351,18 @@ impl SimpleComponent for MainView { gtk::Label { add_css_class: "dim-label", set_hexpand: true, - set_xalign: 0.0, - set_margin_start: 12, - set_margin_end: 12, set_label: concat!( "Libsurvive needs to import your SteamVR calibration to work ", "properly. You need to have used SteamVR with this setup ", "before to be able to import its calibration." ), + set_xalign: 0.0, set_wrap: true, set_wrap_mode: gtk::pango::WrapMode::Word, }, gtk::Button { add_css_class: "suggested-action", set_label: "Calibrate", - set_margin_start: 12, - set_margin_end: 12, set_halign: gtk::Align::Start, connect_clicked[sender] => move |_| { sender.output(Self::Output::OpenLibsurviveSetup).expect("Sender outut failed"); diff --git a/src/ui/steam_launch_options_box.rs b/src/ui/steam_launch_options_box.rs index 84d39f6..661021a 100644 --- a/src/ui/steam_launch_options_box.rs +++ b/src/ui/steam_launch_options_box.rs @@ -27,20 +27,15 @@ impl SimpleComponent for SteamLaunchOptionsBox { set_hexpand: true, set_vexpand: false, set_spacing: 12, - set_margin_top: 12, - set_margin_bottom: 12, + set_margin_all: 12, + add_css_class: "card", + add_css_class: "padded", #[track = "model.changed(Self::xrservice_active())"] set_visible: model.xrservice_active, - gtk::Separator { - set_orientation: gtk::Orientation::Horizontal, - set_hexpand: true, - }, gtk::Label { add_css_class: "heading", set_hexpand: true, set_xalign: 0.0, - set_margin_start: 12, - set_margin_end: 12, set_label: "Steam Launch Options", set_wrap: true, set_wrap_mode: gtk::pango::WrapMode::Word, @@ -48,19 +43,15 @@ impl SimpleComponent for SteamLaunchOptionsBox { gtk::Label { add_css_class: "dim-label", set_hexpand: true, - set_xalign: 0.0, - set_margin_start: 12, - set_margin_end: 12, set_label: format!( "Set this string in the launch options of Steam games, so that they can pick up the {app} runtime correctly", app = APP_NAME) .as_str(), + set_xalign: 0.0, set_wrap: true, set_wrap_mode: gtk::pango::WrapMode::Word, }, gtk::Box { - set_margin_start: 12, - set_margin_end: 12, set_orientation: gtk::Orientation::Horizontal, set_spacing: 6, gtk::ScrolledWindow { diff --git a/src/ui/util.rs b/src/ui/util.rs index 3530bd6..db23d92 100644 --- a/src/ui/util.rs +++ b/src/ui/util.rs @@ -21,3 +21,26 @@ pub fn limit_dropdown_width(dd: >k4::DropDown, chars: i32) { dd_child = nc; } } + +pub fn warning_heading() -> gtk4::Box { + let b = gtk4::Box::builder() + .orientation(gtk4::Orientation::Horizontal) + .spacing(12) + .hexpand(true) + .build(); + + b.append( + >k4::Image::builder() + .css_classes(["warning"]) + .icon_name("dialog-warning-symbolic") + .build(), + ); + b.append( + >k4::Label::builder() + .css_classes(["warning", "heading"]) + .label("Warning") + .build(), + ); + + b +}