diff options
| author | Joakim Hulthe <joakim@hulthe.net> | 2025-02-24 18:16:56 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2025-03-05 23:32:20 +0100 |
| commit | 0b0204f19e3df35fa09ec295477260a1e3d52f61 (patch) | |
| tree | 008977e97f9cc8b77f4559df0f378f3ef847ef6b | |
| parent | 8cf0ca78ab4f23cabe255fe15b34f905a0c98e83 (diff) | |
| download | mullvadvpn-0b0204f19e3df35fa09ec295477260a1e3d52f61.tar.xz mullvadvpn-0b0204f19e3df35fa09ec295477260a1e3d52f61.zip | |
Fix installer text positions on macos
| -rw-r--r-- | installer-downloader/src/cacao_impl/delegate.rs | 21 | ||||
| -rw-r--r-- | installer-downloader/src/cacao_impl/ui.rs | 49 |
2 files changed, 58 insertions, 12 deletions
diff --git a/installer-downloader/src/cacao_impl/delegate.rs b/installer-downloader/src/cacao_impl/delegate.rs index 84a80a5f20..73ace8d4c6 100644 --- a/installer-downloader/src/cacao_impl/delegate.rs +++ b/installer-downloader/src/cacao_impl/delegate.rs @@ -1,6 +1,9 @@ use std::sync::{Arc, Mutex}; -use cacao::{control::Control, layout::Layout}; +use cacao::{ + control::Control, + layout::{Layout, LayoutConstraint}, +}; use super::ui::{Action, AppWindow, ErrorView}; use crate::delegate::{AppDelegate, AppDelegateQueue}; @@ -42,6 +45,22 @@ impl AppDelegate for AppWindow { fn set_download_text(&mut self, text: &str) { self.download_text.set_text(text); + + // If there is a download_text, move status_text up to make room + + let offset = if text.is_empty() { 59.0 } else { 39.0 }; + + if let Some(previous_constraint) = self.status_text_position_y.take() { + LayoutConstraint::deactivate(&[previous_constraint]); + } + + let new_constraint = self + .status_text + .top + .constraint_equal_to(&self.main_view.top) + .offset(offset); + self.status_text_position_y = Some(new_constraint.clone()); + LayoutConstraint::activate(&[new_constraint]); } fn show_download_progress(&mut self) { diff --git a/installer-downloader/src/cacao_impl/ui.rs b/installer-downloader/src/cacao_impl/ui.rs index b38dbd02d6..fb2476fe71 100644 --- a/installer-downloader/src/cacao_impl/ui.rs +++ b/installer-downloader/src/cacao_impl/ui.rs @@ -68,7 +68,7 @@ impl AppDelegate for AppImpl { self.window.show(); let delegate = self.window.delegate.as_ref().unwrap(); - delegate.inner.borrow().layout(); + delegate.inner.borrow_mut().layout(); } fn should_terminate_after_last_window_closed(&self) -> bool { @@ -156,6 +156,9 @@ pub struct AppWindow { pub progress: ProgressIndicator, pub status_text: Label, + /// The y position constraint of [Self::status_text]. + /// This exists because we need to shift it up when download_text is revealed. + pub status_text_position_y: Option<LayoutConstraint>, pub error_view: Option<ErrorView>, pub error_retry_callback: Option<Arc<Mutex<ErrorViewClickCallback>>>, @@ -200,7 +203,7 @@ impl Default for CancelButton { } impl AppWindow { - pub fn layout(&self) { + pub fn layout(&mut self) { self.banner_logo_view.set_image(&LOGO); self.banner_logo_text_view.set_image(&LOGO_TEXT); self.banner.set_background_color(&*BANNER_COLOR); @@ -297,11 +300,22 @@ impl AppWindow { self.beta_link.set_attributed_text(attr_text); self.main_view.add_subview(&self.beta_link); + let status_text_position_y = self.status_text_position_y.get_or_insert_with(|| { + self.status_text + .top + .constraint_equal_to(&self.main_view.top) + .offset(59.) + }); + LayoutConstraint::activate(&[ + status_text_position_y.clone(), + self.status_text + .center_x + .constraint_equal_to(&self.main_view.center_x), self.download_text .top .constraint_equal_to(&self.status_text.bottom) - .offset(16.), + .offset(4.), self.download_text .center_x .constraint_equal_to(&self.main_view.center_x), @@ -311,13 +325,19 @@ impl AppWindow { .constraint_equal_to(&self.main_view.center_x), self.download_button .button - .top - .constraint_equal_to(&self.status_text.bottom) - .offset(16.), + .center_y + .constraint_equal_to(&self.main_view.center_y), + self.download_button + .button + .width + .constraint_equal_to_constant(213.), + self.download_button + .button + .height + .constraint_equal_to_constant(22.), self.progress .top - .constraint_equal_to(&self.download_button.button.top) - .offset(32.), + .constraint_equal_to(&self.download_text.bottom), self.progress .left .constraint_equal_to(&self.main_view.left) @@ -326,7 +346,7 @@ impl AppWindow { .right .constraint_equal_to(&self.main_view.right) .offset(-30.), - self.progress.height.constraint_equal_to_constant(16.0f64), + self.progress.height.constraint_equal_to_constant(36.), self.cancel_button .button .center_x @@ -334,8 +354,15 @@ impl AppWindow { self.cancel_button .button .top - .constraint_equal_to(&self.progress.bottom) - .offset(16.), + .constraint_equal_to(&self.progress.bottom), + self.cancel_button + .button + .width + .constraint_equal_to_constant(213.), + self.cancel_button + .button + .height + .constraint_equal_to_constant(22.), self.beta_link_preface .bottom .constraint_equal_to(&self.main_view.bottom) |
