Fixed button wrapping in settings -> shortcuts
Moorly CI / windows-build (push) Successful in 3m29s
Moorly CI / linux-build (push) Successful in 4m11s

This commit is contained in:
Squid committed 2026-11-08 21:16:51 +01:00
1 parent e0de7a43f0
commit e7afad602b
1 file changed
+62 -39
+62 -39
View File
@@ -27,6 +27,11 @@ mod theme;
mod tray;
const MENUBAR_HEIGHT: f32 = 40.0;
/// Minimum window size keeps the settings shortcut rows on one line.
const MIN_WINDOW_WIDTH: f32 = 860.0;
const MIN_WINDOW_HEIGHT: f32 = 600.0;
/// Width the settings content pane needs for the widest controls.
const SETTINGS_CONTENT_MIN_WIDTH: f32 = 600.0;
/// Settings heading sizes: tab title, sub-section header, normal text, caption.
const SETTINGS_H1_SIZE: f32 = 22.0;
const SETTINGS_H2_SIZE: f32 = 18.0;
@@ -95,12 +100,24 @@ fn main() -> iced::Result {
}
/// Opens the first window and gives it the Start tab when configured.
fn boot() -> (Moorly, Task<Message>) {
let mut state = Moorly::default();
let settings = window::Settings {
/// Window settings shared by every Moorly window, including the minimum size
/// the settings page needs to lay out its controls on one row.
fn window_settings(size: Size, position: Option<Point>) -> window::Settings {
window::Settings {
size: Size::new(
size.width.max(MIN_WINDOW_WIDTH),
size.height.max(MIN_WINDOW_HEIGHT),
),
position: position.map_or(window::Position::Default, window::Position::Specific),
min_size: Some(Size::new(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT)),
exit_on_close_request: false,
..window::Settings::default()
};
}
}
fn boot() -> (Moorly, Task<Message>) {
let mut state = Moorly::default();
let settings = window_settings(window::Settings::default().size, None);
let size = settings.size;
let (id, task) = window::open(settings);
state
@@ -6315,14 +6332,7 @@ fn show_main_window(state: &mut Moorly) -> Task<Message> {
/// Wayland cannot unmap or restore an existing toplevel, so the hidden window
/// is recreated from its saved UI state.
fn reopen_main_window(state: &mut Moorly, window_state: WindowState) -> Task<Message> {
let settings = window::Settings {
size: window_state.size,
position: window_state
.position
.map_or(window::Position::Default, window::Position::Specific),
exit_on_close_request: false,
..window::Settings::default()
};
let settings = window_settings(window_state.size, window_state.position);
let (id, open) = window::open(settings);
state.windows.insert(id, window_state);
@@ -6923,12 +6933,7 @@ fn detach_tab(
let size = Size::new(900.0, 600.0);
let position =
global.map(|point| Point::new((point.x - 100.0).max(0.0), (point.y - 20.0).max(0.0)));
let settings = window::Settings {
size,
position: position.map_or(window::Position::Default, window::Position::Specific),
exit_on_close_request: false,
..window::Settings::default()
};
let settings = window_settings(size, position);
let (id, open) = window::open(settings);
state
.windows
@@ -8163,12 +8168,8 @@ fn shortcut_row(
.on_press(Message::OpenShortcutCapture(action))
.style(theme::outlined_option),
]
// Let the buttons drop to the next line in a narrow window instead of
// pushing the "..." button outside the pane.
.spacing(8)
.align_y(Alignment::Center)
.wrap()
.vertical_spacing(8)
.into()
}
@@ -9846,6 +9847,19 @@ fn profile_context_menu(
)
}
fn settings_dirty(state: &Moorly) -> bool {
state.show_start_tab_draft != state.show_start_tab
|| state.fade_settings_draft != state.fade_settings
|| state.hide_tab_close_draft != state.hide_tab_close
|| state.show_new_session_button_draft != state.show_new_session_button
|| state.show_command_palette_description_draft != state.show_command_palette_description
|| state.typography_draft != state.typography
|| state.command_palette_enabled_draft != state.command_palette_enabled
|| state.close_to_tray_draft != state.close_to_tray
|| state.theme_choice != state.saved_theme_choice
|| state.shortcuts != state.saved_shortcuts
}
fn settings_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
let accent = state.colors[ColorOption::Accent.index()];
let text_color = state.colors[ColorOption::Text.index()];
@@ -9968,7 +9982,9 @@ fn settings_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
let panel_width = state
.windows
.get(&window)
.map(|window_state| (window_state.size.width * 0.5).max(400.0) + menu_width)
.map(|window_state| {
(window_state.size.width * 0.5).max(SETTINGS_CONTENT_MIN_WIDTH) + menu_width
})
.unwrap_or(400.0 + menu_width);
let frame = container(frame).width(panel_width).height(Length::Fill);
let frame = container(frame)
@@ -9976,17 +9992,7 @@ fn settings_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
.height(Length::Fill)
.align_x(Alignment::Center);
let dirty = state.show_start_tab_draft != state.show_start_tab
|| state.fade_settings_draft != state.fade_settings
|| state.hide_tab_close_draft != state.hide_tab_close
|| state.show_new_session_button_draft != state.show_new_session_button
|| state.show_command_palette_description_draft != state.show_command_palette_description
|| state.typography_draft != state.typography
|| state.command_palette_enabled_draft != state.command_palette_enabled
|| state.theme_choice != state.saved_theme_choice
|| state.shortcuts != state.saved_shortcuts;
let page: Element<'_, Message> = if dirty {
let page: Element<'_, Message> = if settings_dirty(state) {
let bar = container(
row![
text("There is unsaved changes"),
@@ -10303,11 +10309,7 @@ fn run_profile(
let tab = Tab::Terminal(id);
if new_window {
let settings = window::Settings {
size,
exit_on_close_request: false,
..window::Settings::default()
};
let settings = window_settings(size, None);
let (id, open) = window::open(settings);
state
.windows
@@ -11448,6 +11450,27 @@ mod tests {
assert_eq!(state.show_start_tab_draft, state.show_start_tab);
}
#[test]
fn close_to_tray_changes_wait_for_save_or_undo() {
let mut state = state();
assert!(!super::settings_dirty(&state));
let _ = update(&mut state, Message::SetCloseToTray(true));
assert!(!state.close_to_tray);
assert!(state.close_to_tray_draft);
assert!(super::settings_dirty(&state));
let _ = update(&mut state, Message::UndoChanges);
assert_eq!(state.close_to_tray_draft, state.close_to_tray);
assert!(!super::settings_dirty(&state));
let _ = update(&mut state, Message::SetCloseToTray(true));
super::apply_settings(&mut state);
assert!(state.close_to_tray);
assert_eq!(state.close_to_tray_draft, state.close_to_tray);
assert!(!super::settings_dirty(&state));
}
#[test]
fn hiding_tab_close_waits_for_save_or_undo() {
let mut state = state();