Unified label sizes
This commit is contained in:
1 parent
e8d6575ab3
commit
2106c88868
1 file changed
+121
-34
+121
-34
@@ -22,6 +22,11 @@ mod terminal;
|
||||
mod theme;
|
||||
|
||||
const MENUBAR_HEIGHT: f32 = 40.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;
|
||||
const SETTINGS_H3_SIZE: f32 = 16.0;
|
||||
const SETTINGS_CAPTION_SIZE: f32 = 13.0;
|
||||
/// Tab width bounds and gap, used to fit as many tabs as the strip allows.
|
||||
const TAB_MAX_WIDTH: f32 = 230.0;
|
||||
const TAB_MIN_WIDTH: f32 = 100.0;
|
||||
@@ -1469,6 +1474,8 @@ struct Moorly {
|
||||
fade_settings_draft: bool,
|
||||
hide_tab_close: bool,
|
||||
hide_tab_close_draft: bool,
|
||||
show_new_session_button: bool,
|
||||
show_new_session_button_draft: bool,
|
||||
command_palette_enabled: bool,
|
||||
command_palette_enabled_draft: bool,
|
||||
advanced_open: bool,
|
||||
@@ -1871,6 +1878,8 @@ struct AppearanceConfig {
|
||||
custom_theme_name: Option<String>,
|
||||
#[serde(default = "default_true")]
|
||||
hide_tab_close: bool,
|
||||
#[serde(default = "default_true")]
|
||||
show_new_session_button: bool,
|
||||
#[serde(default)]
|
||||
toast: ToastFile,
|
||||
}
|
||||
@@ -1882,6 +1891,7 @@ impl Default for AppearanceConfig {
|
||||
custom_theme: None,
|
||||
custom_theme_name: None,
|
||||
hide_tab_close: true,
|
||||
show_new_session_button: true,
|
||||
toast: ToastFile::default(),
|
||||
}
|
||||
}
|
||||
@@ -3550,6 +3560,7 @@ fn apply_settings(state: &mut Moorly) {
|
||||
state.show_start_tab = state.show_start_tab_draft;
|
||||
state.fade_settings = state.fade_settings_draft;
|
||||
state.hide_tab_close = state.hide_tab_close_draft;
|
||||
state.show_new_session_button = state.show_new_session_button_draft;
|
||||
state.command_palette_enabled = state.command_palette_enabled_draft;
|
||||
|
||||
state.saved_theme = state.theme;
|
||||
@@ -3565,6 +3576,12 @@ fn apply_settings(state: &mut Moorly) {
|
||||
};
|
||||
state.saved_shortcuts = state.shortcuts.clone();
|
||||
|
||||
if !state.show_new_session_button {
|
||||
for window_state in state.windows.values_mut() {
|
||||
window_state.quick_menu_open = false;
|
||||
}
|
||||
}
|
||||
|
||||
if !state.fade_settings {
|
||||
if let Some(pending) = state.pending_settings_section.take() {
|
||||
state.settings_section = pending;
|
||||
@@ -3578,6 +3595,7 @@ fn undo_settings(state: &mut Moorly) {
|
||||
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.command_palette_enabled_draft = state.command_palette_enabled;
|
||||
state.shortcuts = state.saved_shortcuts.clone();
|
||||
state.shortcut_capture = None;
|
||||
@@ -3638,6 +3656,7 @@ fn config_file(state: &Moorly) -> ConfigFile {
|
||||
ThemeChoice::BuiltIn(_) => None,
|
||||
},
|
||||
hide_tab_close: state.hide_tab_close,
|
||||
show_new_session_button: state.show_new_session_button,
|
||||
toast: ToastFile::from_colors(state.builtin_custom_toasts, &state.builtin_toast_colors),
|
||||
},
|
||||
shortcuts: ShortcutConfig {
|
||||
@@ -3689,6 +3708,7 @@ impl Default for Moorly {
|
||||
let show_start_tab = config.startup.show_start_tab;
|
||||
let fade_settings = config.general.fade_settings;
|
||||
let hide_tab_close = config.appearance.hide_tab_close;
|
||||
let show_new_session_button = config.appearance.show_new_session_button;
|
||||
let command_palette_enabled = config.command_palette.enabled;
|
||||
let shortcuts = Shortcuts {
|
||||
settings: Shortcut::parse(&config.shortcuts.settings),
|
||||
@@ -3729,6 +3749,8 @@ impl Default for Moorly {
|
||||
fade_settings_draft: fade_settings,
|
||||
hide_tab_close,
|
||||
hide_tab_close_draft: hide_tab_close,
|
||||
show_new_session_button,
|
||||
show_new_session_button_draft: show_new_session_button,
|
||||
command_palette_enabled,
|
||||
command_palette_enabled_draft: command_palette_enabled,
|
||||
advanced_open: false,
|
||||
@@ -3805,6 +3827,7 @@ enum Message {
|
||||
SetShowStartTab(bool),
|
||||
SetFadeSettings(bool),
|
||||
SetHideTabClose(bool),
|
||||
SetShowNewSessionButton(bool),
|
||||
SetCommandPaletteEnabled(bool),
|
||||
ToggleAdvanced,
|
||||
SetCustomToasts(bool),
|
||||
@@ -4426,6 +4449,7 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
||||
Message::SetShowStartTab(value) => state.show_start_tab_draft = value,
|
||||
Message::SetFadeSettings(value) => state.fade_settings_draft = value,
|
||||
Message::SetHideTabClose(value) => state.hide_tab_close_draft = value,
|
||||
Message::SetShowNewSessionButton(value) => state.show_new_session_button_draft = value,
|
||||
Message::SetCommandPaletteEnabled(value) => {
|
||||
state.command_palette_enabled_draft = value;
|
||||
}
|
||||
@@ -5133,13 +5157,20 @@ fn remove_window(state: &mut Moorly, window: window::Id) {
|
||||
|
||||
/// Width the tab strip gets after the quick-add button, scroll buttons and
|
||||
/// hamburger.
|
||||
fn tab_strip_width(window_width: f32) -> f32 {
|
||||
fn tab_strip_width(window_width: f32, show_new_session_button: bool) -> f32 {
|
||||
let quick_button = if show_new_session_button {
|
||||
HAMBURGER_WIDTH + TAB_SPACING
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
(window_width
|
||||
- TAB_STRIP_LEFT
|
||||
- MENUBAR_RIGHT_PADDING
|
||||
- 2.0 * SCROLL_BUTTON_WIDTH
|
||||
- 2.0 * HAMBURGER_WIDTH
|
||||
- 4.0 * TAB_SPACING)
|
||||
- HAMBURGER_WIDTH
|
||||
- 3.0 * TAB_SPACING
|
||||
- quick_button)
|
||||
.max(0.0)
|
||||
}
|
||||
|
||||
@@ -5151,8 +5182,8 @@ struct TabStripMetrics {
|
||||
offset: f32,
|
||||
}
|
||||
|
||||
fn tab_strip_metrics(window_state: &WindowState) -> TabStripMetrics {
|
||||
let viewport = tab_strip_width(window_state.size.width);
|
||||
fn tab_strip_metrics(window_state: &WindowState, show_new_session_button: bool) -> TabStripMetrics {
|
||||
let viewport = tab_strip_width(window_state.size.width, show_new_session_button);
|
||||
let count = window_state.tabs.len();
|
||||
let width = tab_width(viewport, count);
|
||||
let step = width + TAB_SPACING;
|
||||
@@ -5184,7 +5215,7 @@ fn tab_index_at(state: &Moorly, window: window::Id, point: Point) -> Option<usiz
|
||||
return None;
|
||||
}
|
||||
|
||||
let metrics = tab_strip_metrics(window_state);
|
||||
let metrics = tab_strip_metrics(window_state, state.show_new_session_button);
|
||||
if metrics.viewport <= 0.0 || point.x > TAB_STRIP_LEFT + metrics.viewport {
|
||||
return None;
|
||||
}
|
||||
@@ -5206,7 +5237,7 @@ fn tab_gap_index(state: &Moorly, window: window::Id, x: f32) -> Option<usize> {
|
||||
return Some(0);
|
||||
}
|
||||
|
||||
let metrics = tab_strip_metrics(window_state);
|
||||
let metrics = tab_strip_metrics(window_state, state.show_new_session_button);
|
||||
let relative = x - TAB_STRIP_LEFT + metrics.offset;
|
||||
let mut gap = window_state.tabs.len();
|
||||
|
||||
@@ -5282,7 +5313,7 @@ fn drag_scroll_delta(state: &Moorly) -> Option<f32> {
|
||||
}
|
||||
|
||||
let window_state = state.windows.get(&drag.window)?;
|
||||
let metrics = tab_strip_metrics(window_state);
|
||||
let metrics = tab_strip_metrics(window_state, state.show_new_session_button);
|
||||
if window_state.tabs.is_empty()
|
||||
|| metrics.viewport <= 0.0
|
||||
|| metrics.content <= metrics.viewport
|
||||
@@ -5587,7 +5618,7 @@ fn tab_reveal_delta(state: &Moorly, window: window::Id) -> Option<f32> {
|
||||
return None;
|
||||
}
|
||||
|
||||
let metrics = tab_strip_metrics(window_state);
|
||||
let metrics = tab_strip_metrics(window_state, state.show_new_session_button);
|
||||
if metrics.viewport <= 0.0 || metrics.content <= metrics.viewport {
|
||||
return None;
|
||||
}
|
||||
@@ -5944,7 +5975,7 @@ fn tab_drop_bar(
|
||||
return None;
|
||||
}
|
||||
|
||||
let metrics = tab_strip_metrics(window_state);
|
||||
let metrics = tab_strip_metrics(window_state, state.show_new_session_button);
|
||||
if metrics.viewport <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
@@ -6134,7 +6165,7 @@ fn theme_picker(state: &Moorly) -> Element<'_, Message> {
|
||||
.cloned();
|
||||
|
||||
row![
|
||||
text("Themes").size(16),
|
||||
text("Themes").size(SETTINGS_H3_SIZE),
|
||||
space::horizontal(),
|
||||
pick_list(options, selected, Message::SelectTheme).width(200),
|
||||
]
|
||||
@@ -6148,9 +6179,9 @@ fn advanced_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
let glyph = if state.advanced_open { "▴" } else { "▾" };
|
||||
let header = button(
|
||||
row![
|
||||
text("Advanced customization"),
|
||||
text("Advanced customization").size(SETTINGS_H2_SIZE),
|
||||
space::horizontal(),
|
||||
text(glyph),
|
||||
text(glyph).size(SETTINGS_H2_SIZE),
|
||||
]
|
||||
.width(Length::Fill)
|
||||
.align_y(Alignment::Center),
|
||||
@@ -6172,7 +6203,7 @@ fn advanced_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
rows = rows.push(rule::horizontal(1));
|
||||
rows = rows.push(
|
||||
row![
|
||||
text("Custom toaster colors"),
|
||||
text("Custom toaster colors").size(SETTINGS_H3_SIZE),
|
||||
space::horizontal(),
|
||||
toggler(state.custom_toasts).on_toggle(Message::SetCustomToasts),
|
||||
]
|
||||
@@ -6272,7 +6303,11 @@ fn color_swatch_row<'a>(
|
||||
|
||||
let picker = iced_aw::color_picker(open, color, button, Message::CancelColorPicker, on_submit);
|
||||
|
||||
row![text(label), space::horizontal(), picker]
|
||||
row![
|
||||
text(label).size(SETTINGS_H3_SIZE),
|
||||
space::horizontal(),
|
||||
picker
|
||||
]
|
||||
.align_y(Alignment::Center)
|
||||
.into()
|
||||
}
|
||||
@@ -6321,7 +6356,7 @@ fn shortcut_row(action: ShortcutAction, shortcut: Option<&Shortcut>) -> Element<
|
||||
let field = text_input("None", &value).width(180).padding(6);
|
||||
|
||||
row![
|
||||
container(text(action.label())).width(120),
|
||||
container(text(action.label()).size(SETTINGS_H3_SIZE)).width(120),
|
||||
field,
|
||||
button("Default")
|
||||
.on_press(Message::DefaultShortcut(action))
|
||||
@@ -7003,7 +7038,7 @@ fn trash_dialog_view(state: &Moorly) -> Element<'_, Message> {
|
||||
.style(theme::settings_frame);
|
||||
|
||||
container(
|
||||
column![text("Trash").size(16), header, listing]
|
||||
column![text("Trash").size(SETTINGS_H2_SIZE), header, listing]
|
||||
.spacing(10)
|
||||
.width(Length::Fill),
|
||||
)
|
||||
@@ -7642,7 +7677,7 @@ fn start_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
fn command_palette_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
let mut rows = column![
|
||||
row![
|
||||
text("Enable command palette").size(14),
|
||||
text("Enable command palette").size(SETTINGS_H3_SIZE),
|
||||
space::horizontal(),
|
||||
toggler(state.command_palette_enabled_draft)
|
||||
.on_toggle(Message::SetCommandPaletteEnabled),
|
||||
@@ -7651,7 +7686,7 @@ fn command_palette_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
rule::horizontal(1),
|
||||
row![
|
||||
container(text("Command").size(13)).width(180),
|
||||
text("Description").size(13),
|
||||
text("Description").size(SETTINGS_CAPTION_SIZE),
|
||||
]
|
||||
.spacing(12),
|
||||
rule::horizontal(1),
|
||||
@@ -7689,7 +7724,7 @@ fn command_palette_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
fn command_palette_row(command: String, description: String) -> Element<'static, Message> {
|
||||
row![
|
||||
container(text(command).size(13)).width(180),
|
||||
text(description).size(13),
|
||||
text(description).size(SETTINGS_CAPTION_SIZE),
|
||||
]
|
||||
.spacing(12)
|
||||
.into()
|
||||
@@ -7697,7 +7732,7 @@ fn command_palette_row(command: String, description: String) -> Element<'static,
|
||||
|
||||
fn general_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
row![
|
||||
text("Fade In/Fade out animation"),
|
||||
text("Fade In/Fade out animation").size(SETTINGS_H3_SIZE),
|
||||
space::horizontal(),
|
||||
toggler(state.fade_settings_draft).on_toggle(Message::SetFadeSettings),
|
||||
]
|
||||
@@ -7708,7 +7743,7 @@ fn general_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
/// Startup settings that are edited as a draft until saved.
|
||||
fn startup_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
row![
|
||||
text("Show Start tab at startup"),
|
||||
text("Show Start tab at startup").size(SETTINGS_H3_SIZE),
|
||||
space::horizontal(),
|
||||
toggler(state.show_start_tab_draft).on_toggle(Message::SetShowStartTab),
|
||||
]
|
||||
@@ -7721,8 +7756,16 @@ fn appearance_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
column![
|
||||
theme_picker(state),
|
||||
advanced_panel(state),
|
||||
text("Tab bar").size(SETTINGS_H2_SIZE),
|
||||
row![
|
||||
text("Hide tab close icon"),
|
||||
text("Show new Session Button").size(SETTINGS_H3_SIZE),
|
||||
space::horizontal(),
|
||||
toggler(state.show_new_session_button_draft)
|
||||
.on_toggle(Message::SetShowNewSessionButton),
|
||||
]
|
||||
.align_y(Alignment::Center),
|
||||
row![
|
||||
text("Hide tab close icon").size(SETTINGS_H3_SIZE),
|
||||
space::horizontal(),
|
||||
toggler(state.hide_tab_close_draft).on_toggle(Message::SetHideTabClose),
|
||||
]
|
||||
@@ -7823,7 +7866,7 @@ fn settings_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
.spacing(12)
|
||||
.width(Length::Fill)
|
||||
.padding(Padding::ZERO.right(if scrolls { 12.0 } else { 0.0 }));
|
||||
content = content.push(text(state.settings_section.label()).size(18));
|
||||
content = content.push(text(state.settings_section.label()).size(SETTINGS_H1_SIZE));
|
||||
if state.settings_section == SettingsSection::General {
|
||||
content = content.push(general_panel(state));
|
||||
}
|
||||
@@ -7889,6 +7932,7 @@ fn settings_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
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.command_palette_enabled_draft != state.command_palette_enabled
|
||||
|| state.theme_choice != state.saved_theme_choice
|
||||
|| state.shortcuts != state.saved_shortcuts;
|
||||
@@ -8085,7 +8129,7 @@ fn tab_scroll_limits(state: &Moorly, window: window::Id) -> (bool, bool) {
|
||||
return (false, false);
|
||||
}
|
||||
|
||||
let metrics = tab_strip_metrics(window_state);
|
||||
let metrics = tab_strip_metrics(window_state, state.show_new_session_button);
|
||||
let max_offset = (metrics.content - metrics.viewport).max(0.0);
|
||||
let offset = window_state.tab_offset.min(max_offset);
|
||||
(offset > 0.5, offset < max_offset - 0.5)
|
||||
@@ -8105,6 +8149,7 @@ fn main_view(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
let active_tab = window_state.active_tab;
|
||||
let menu_open = window_state.menu_open;
|
||||
let quick_menu_open = window_state.quick_menu_open;
|
||||
let show_new_session_button = state.show_new_session_button;
|
||||
let tabs_submenu_open = window_state.tabs_submenu_open;
|
||||
let scroll_id = window_state.scroll_id.clone();
|
||||
let hide_close = state.hide_tab_close;
|
||||
@@ -8163,14 +8208,28 @@ fn main_view(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
|
||||
let (can_scroll_left, can_scroll_right) = tab_scroll_limits(state, window);
|
||||
|
||||
let mut bar = row![
|
||||
quick_add_button(quick_menu_open, text_color, window),
|
||||
tab_strip,
|
||||
scroll_button("◀", -TAB_SCROLL_STEP, can_scroll_left, text_color, window),
|
||||
scroll_button("▶", TAB_SCROLL_STEP, can_scroll_right, text_color, window),
|
||||
]
|
||||
.spacing(2)
|
||||
.align_y(Alignment::Center);
|
||||
let mut bar = row![].spacing(2).align_y(Alignment::Center);
|
||||
|
||||
if show_new_session_button {
|
||||
bar = bar.push(quick_add_button(quick_menu_open, text_color, window));
|
||||
}
|
||||
|
||||
bar = bar
|
||||
.push(tab_strip)
|
||||
.push(scroll_button(
|
||||
"◀",
|
||||
-TAB_SCROLL_STEP,
|
||||
can_scroll_left,
|
||||
text_color,
|
||||
window,
|
||||
))
|
||||
.push(scroll_button(
|
||||
"▶",
|
||||
TAB_SCROLL_STEP,
|
||||
can_scroll_right,
|
||||
text_color,
|
||||
window,
|
||||
));
|
||||
|
||||
if menu_open {
|
||||
// The dropdown draws the close button over this spot.
|
||||
@@ -8541,6 +8600,8 @@ mod tests {
|
||||
fade_settings_draft: true,
|
||||
hide_tab_close: true,
|
||||
hide_tab_close_draft: true,
|
||||
show_new_session_button: true,
|
||||
show_new_session_button_draft: true,
|
||||
command_palette_enabled: true,
|
||||
command_palette_enabled_draft: true,
|
||||
advanced_open: false,
|
||||
@@ -8681,6 +8742,30 @@ mod tests {
|
||||
assert_eq!(state.hide_tab_close_draft, state.hide_tab_close);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hiding_the_new_session_button_waits_for_save_or_undo() {
|
||||
let mut state = state();
|
||||
|
||||
let _ = update(&mut state, Message::SetShowNewSessionButton(false));
|
||||
assert!(state.show_new_session_button);
|
||||
assert!(!state.show_new_session_button_draft);
|
||||
|
||||
let _ = update(&mut state, Message::UndoChanges);
|
||||
assert_eq!(
|
||||
state.show_new_session_button_draft,
|
||||
state.show_new_session_button
|
||||
);
|
||||
|
||||
let _ = update(&mut state, Message::SetShowNewSessionButton(false));
|
||||
super::apply_settings(&mut state);
|
||||
assert!(!state.show_new_session_button);
|
||||
assert_eq!(
|
||||
state.show_new_session_button_draft,
|
||||
state.show_new_session_button
|
||||
);
|
||||
assert!(super::tab_strip_width(1024.0, false) > super::tab_strip_width(1024.0, true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disabling_the_command_palette_waits_for_save_or_undo() {
|
||||
let mut state = state();
|
||||
@@ -8733,6 +8818,7 @@ mod tests {
|
||||
state.fade_settings = false;
|
||||
state.show_start_tab = false;
|
||||
state.hide_tab_close = false;
|
||||
state.show_new_session_button = false;
|
||||
state.command_palette_enabled = false;
|
||||
state.saved_theme = theme::Preference::Dark;
|
||||
state.saved_theme_choice = super::ThemeChoice::BuiltIn(theme::Preference::Dark);
|
||||
@@ -8746,6 +8832,7 @@ mod tests {
|
||||
assert!(text.contains("[general]\nfade_settings = false"));
|
||||
assert!(text.contains("[startup]\nshow_start_tab = false"));
|
||||
assert!(text.contains("[appearance]\ntheme = \"dark\""));
|
||||
assert!(text.contains("show_new_session_button = false"));
|
||||
assert!(text.contains("[appearance.toast]"));
|
||||
assert!(text.contains("[shortcuts]"));
|
||||
assert!(text.contains("[command_palette]\nenabled = false"));
|
||||
@@ -9217,7 +9304,7 @@ mod tests {
|
||||
let window = test_window();
|
||||
window_state_mut(&mut state).tabs = (1..=20).map(Tab::Blank).collect();
|
||||
|
||||
let viewport = super::tab_strip_width(1024.0);
|
||||
let viewport = super::tab_strip_width(1024.0, true);
|
||||
state.drag = Some(super::TabDrag {
|
||||
window,
|
||||
tab: Tab::Blank(1),
|
||||
|
||||
Reference in new issue
Block a user