fix(desktop): Keep Today visible in folded journal splits

Allow space for the split close button and keep the week controls visible.
Exercise the Today click after opening a split and resizing the window.
This commit is contained in:
DarkSky committed 2026-12-03 14:55:10 +09:00
1 parent 9687cbb676
commit 91e074a40a
2 files changed
+304 -141

No files matched your search

@@ -591,9 +591,25 @@ mod tests {
}
}
fn resize(&self, width: u32, height: u32) {
let mut window = self.window.clone();
ui::PlatformWindow::resize(&mut window, size(px(width as f32), px(height as f32)));
}
fn split_journal(&self) {
self.click("desktop.topbar.more");
self.click("desktop.header.menu.split");
self.state(|state| assert_eq!(state.split.panes.len(), 2));
}
fn frame(&self) -> FrameSnapshot {
self.window.request_frame();
self.platform.run_until_parked();
self.app.update(|cx| {
self.handle
.update(cx, |_, window, _| window.refresh())
.unwrap()
});
self.window.request_frame();
self.app.update(|cx| {
self.handle
.update(cx, |_, window, _| window.frame_snapshot().clone())
@@ -831,138 +847,252 @@ mod tests {
#[test]
fn journal_header_controls_fit_the_pane_and_keep_actions_available() {
for readonly in [false, true] {
for (width, sidebar_width) in [
(299, 0),
(300, 0),
(320, 0),
(359, 0),
(360, 0),
(390, 0),
(499, 0),
(500, 0),
(504, 0),
(524, 0),
(768, 240),
(768, 248),
(1280, 248),
] {
let case =
format!("window {width}px, sidebar {sidebar_width}px, readonly {readonly}");
let mut state = seeded(false);
if sidebar_width > 0 {
state.sidebar.width = sidebar_width as f32;
}
let yesterday = state.store.create_doc(
"Yesterday",
DocMode::Page,
Some(YESTERDAY.into()),
1_000,
);
if readonly {
mark_readonly(&mut state);
}
state.navigate_active_pane(DesktopRoute::Doc(yesterday));
let shell = TestShell::open(state, width);
let frame = shell.frame();
let elements = &frame.elements;
let pane = elements["desktop.workbench.topbar"].bounds;
assert_eq!(pane.x, sidebar_width as f32, "{case}");
assert_eq!(pane.width, (width - sidebar_width) as f32, "{case}");
for id in [
"desktop.topbar.journal_previous",
"desktop.topbar.journal_next",
"desktop.topbar.more",
"desktop.topbar.inspector_toggle",
for split_open in [false, true] {
for (width, sidebar_width) in [
(299, 0),
(300, 0),
(310, 0),
(320, 0),
(340, 0),
(359, 0),
(360, 0),
(390, 0),
(399, 0),
(400, 0),
(459, 0),
(460, 0),
(499, 0),
(500, 0),
(504, 0),
(524, 0),
(639, 0),
(640, 0),
(768, 0),
(768, 240),
(768, 248),
(1280, 0),
(1280, 248),
] {
assert!(
elements.get(id).is_some_and(|el| el.interactive),
"{id}: {case}"
let case = format!(
"window {width}px, sidebar {sidebar_width}px, readonly {readonly}, split {split_open}"
);
}
for (id, visible) in [
("desktop.topbar.today", width >= 300),
("desktop.topbar.sidebar_toggle", sidebar_width == 0),
("desktop.topbar.share", width - sidebar_width >= 500),
] {
assert_eq!(
elements.get(id).map(|el| el.interactive),
visible.then_some(true),
"{id}: {case}"
);
}
assert_eq!(
elements.contains_key("desktop.topbar.readonly_sqlite_badge"),
readonly,
"{case}"
);
for id in ["desktop.topbar.favorite", "desktop.topbar.doc_info"] {
assert!(!elements.contains_key(id), "{id}: {case}");
}
let fits = |outer: ui::SnapshotRect, inner: ui::SnapshotRect| {
inner.x >= outer.x - 0.5 && inner.right() <= outer.right() + 0.5
};
let week = elements["desktop.topbar.journal_week"].bounds;
let days: Vec<_> = elements
.values()
.filter(|el| el.id.starts_with("desktop.topbar.day."))
.collect();
assert!((1..=7).contains(&days.len()), "{case}");
for day in days {
assert!(
day.interactive && fits(week, day.bounds),
"{}: {case}",
day.id
);
}
let mut controls = Vec::new();
for el in elements
.values()
.filter(|el| el.id.starts_with("desktop.topbar."))
{
assert!(fits(pane, el.bounds), "{} {:?}: {case}", el.id, el.bounds);
assert!(
fits(el.content_mask, el.bounds),
"{} {:?} clipped by {:?}: {case}",
el.id,
el.bounds,
el.content_mask
);
if !matches!(
el.id.as_str(),
"desktop.topbar.mode_switch" | "desktop.topbar.journal_week"
) {
controls.push(el);
let mut state = seeded(false);
state.sidebar.open = sidebar_width > 0;
if sidebar_width > 0 {
state.sidebar.width = sidebar_width as f32;
}
}
controls.sort_by(|a, b| a.bounds.x.total_cmp(&b.bounds.x));
for pair in controls.windows(2) {
let yesterday = state.store.create_doc(
"Yesterday",
DocMode::Page,
Some(YESTERDAY.into()),
1_000,
);
if readonly {
mark_readonly(&mut state);
}
state.navigate_active_pane(DesktopRoute::Doc(yesterday.clone()));
let shell = TestShell::open(state, 1280);
if split_open {
shell.split_journal();
}
shell.resize(width, 800);
assert_doc(&shell, &yesterday);
let active = shell.state(|state| state.split.active_pane);
let frame = shell.frame();
assert_eq!(
frame.elements.contains_key("desktop.topbar.sidebar_toggle"),
sidebar_width == 0,
"{case}"
);
let visible: Vec<_> = (0..=usize::from(split_open))
.filter(|index| {
frame
.elements
.contains_key(&format!("desktop.pane.{index}"))
})
.collect();
let folded = width < 640;
assert_eq!(
visible.len(),
1 + usize::from(split_open && !folded),
"{case}"
);
for (position, &index) in visible.iter().enumerate() {
let prefix = if index == 0 {
"desktop.topbar".into()
} else {
format!("desktop.pane.{index}.topbar")
};
let pane = frame.elements[&format!("desktop.pane.{index}")].bounds;
let pane_width = (width - sidebar_width) as f32 / visible.len() as f32;
assert_eq!(
pane.x,
sidebar_width as f32 + position as f32 * pane_width,
"{case}"
);
assert_eq!(pane.width, pane_width, "{case}");
assert_journal_header(
&frame,
&prefix,
pane,
[
("today", pane.width >= 300.0),
("more", true),
("inspector_toggle", position + 1 == visible.len()),
("close_split", split_open),
("share", !split_open && pane.width >= 500.0),
],
position == 0 && sidebar_width == 0,
readonly,
&case,
);
if split_open && folded && pane.width < 400.0 {
let indicator =
frame.elements[&format!("{prefix}.split_indicator")].bounds;
let week = frame.elements[&format!("{prefix}.journal_week")].bounds;
assert!(
indicator.bottom() <= week.y,
"split indicator overlaps the week: {case}"
);
}
}
let prefix = if active == 0 {
"desktop.topbar".into()
} else {
format!("desktop.pane.{active}.topbar")
};
if frame.elements.contains_key(&format!("{prefix}.today")) {
shell.click(&format!("{prefix}.today"));
assert!(
!shell.frame().elements.contains_key("desktop.header.menu"),
"Today opened More: {case}"
);
shell.state(|state| {
assert_eq!(state.split.active_pane, active, "{case}");
assert_eq!(
state.split.active().active_route().doc_id(),
Some("doc-journal-today"),
"{case}"
);
});
}
shell.click(&format!("{prefix}.more"));
let menu = shell.frame();
assert!(
pair[0].bounds.x + pair[0].bounds.width <= pair[1].bounds.x + 0.5,
"{} overlaps {}: {case}",
pair[0].id,
pair[1].id,
menu.elements.contains_key("desktop.header.menu.favorite"),
"{case}"
);
assert!(
menu.elements.contains_key("desktop.header.menu.doc_info"),
"{case}"
);
}
if width >= 300 {
shell.click("desktop.topbar.today");
assert_doc(&shell, "doc-journal-today");
}
shell.click("desktop.topbar.more");
let menu = shell.frame();
assert!(
menu.elements.contains_key("desktop.header.menu.favorite"),
"{case}"
);
assert!(
menu.elements.contains_key("desktop.header.menu.doc_info"),
"{case}"
);
}
}
}
fn assert_journal_header(
frame: &FrameSnapshot,
prefix: &str,
pane: ui::SnapshotRect,
actions: [(&str, bool); 5],
sidebar_toggle: bool,
readonly: bool,
case: &str,
) {
let elements = &frame.elements;
for (name, visible) in actions.into_iter().chain([
("journal_previous", true),
("journal_next", true),
("mode.page", true),
("mode.edgeless", true),
]) {
let id = format!("{prefix}.{name}");
assert_eq!(
elements.get(&id).map(|el| el.interactive),
visible.then_some(true),
"{id}: {case}"
);
}
let sidebar = "desktop.topbar.sidebar_toggle";
if sidebar_toggle {
assert!(elements[sidebar].interactive, "{case}");
}
assert_eq!(
elements.contains_key(&format!("{prefix}.readonly_sqlite_badge")),
readonly,
"{case}"
);
for name in ["favorite", "doc_info"] {
assert!(
!elements.contains_key(&format!("{prefix}.{name}")),
"{name}: {case}"
);
}
let fits = |outer: ui::SnapshotRect, inner: ui::SnapshotRect| {
inner.x >= outer.x - 0.5
&& inner.right() <= outer.right() + 0.5
&& inner.y >= outer.y - 0.5
&& inner.bottom() <= outer.bottom() + 0.5
};
let week = elements[&format!("{prefix}.journal_week")].bounds;
let mode = elements[&format!("{prefix}.mode_switch")].bounds;
let mut controls = Vec::new();
let mut days = 0;
for el in elements.values() {
let name = if el.id == sidebar {
if !sidebar_toggle {
continue;
}
"sidebar_toggle"
} else if let Some(name) = el
.id
.strip_prefix(prefix)
.and_then(|id| id.strip_prefix('.'))
{
name
} else {
continue;
};
assert!(
fits(pane, el.bounds),
"{} {:?} outside {pane:?}: {case}",
el.id,
el.bounds
);
assert!(
fits(el.content_mask, el.bounds),
"{} {:?} clipped by {:?}: {case}",
el.id,
el.bounds,
el.content_mask
);
if name.starts_with("day.") {
days += 1;
assert!(el.interactive && fits(week, el.bounds), "{}: {case}", el.id);
}
if name.starts_with("mode.") {
assert!(fits(mode, el.bounds), "{}: {case}", el.id);
}
if !matches!(name, "mode_switch" | "journal_week" | "split_indicator") {
controls.push(el);
}
}
assert!((1..=7).contains(&days), "{case}");
controls.sort_by(|a, b| a.bounds.x.total_cmp(&b.bounds.x));
for pair in controls.windows(2) {
assert!(
pair[0].bounds.right() <= pair[1].bounds.x + 0.5,
"{} overlaps {}: {case}",
pair[0].id,
pair[1].id,
);
}
}
#[test]
fn today_opens_the_first_journal_from_another_document_on_the_same_date() {
for readonly in [false, true] {
@@ -23,6 +23,7 @@ use crate::{
pub(super) const HEADER_HEIGHT: f32 = 52.0;
pub(super) const APP_TABS_HEIGHT: f32 = 40.0;
pub(super) const SPLIT_BREAKPOINT: f32 = 640.0;
const TIGHT_SPLIT_JOURNAL_BADGE_WIDTH: f32 = 58.0;
#[derive(Clone, PartialEq, Eq)]
struct DocTarget {
@@ -119,12 +120,18 @@ fn render_readonly_sqlite_badge(
.flex_shrink(0.0)
.rounded(px(4.0))
.px(px(8.0))
.when_some(journal_width, |badge, width| {
badge.w(px(width)).px(px(5.0)).flex().justify_center()
})
.py(px(2.0))
.bg(palette.bg_pill)
.text_size(px(12.0))
.when_some(journal_width, |badge, width| {
let tight = width == TIGHT_SPLIT_JOURNAL_BADGE_WIDTH;
badge
.w(px(width))
.px(px(if tight { 4.0 } else { 5.0 }))
.text_size(px(if tight { 11.0 } else { 12.0 }))
.flex()
.justify_center()
})
.font_weight(FontWeight::MEDIUM)
.line_height(px(20.0))
.text_color(palette.text_secondary)
@@ -181,11 +188,15 @@ pub(super) fn render_detail_header(
doc_entry.is_some_and(|entry| entry.meta.journal_date.is_some() && !entry.meta.trashed);
let narrow = width < 500.0;
let hide_share = split_visible || width < 500.0;
let compact_journal = journal && width < 420.0;
let tight_journal = journal && width < 340.0;
// The split close button adds a fourth control. Leave 100px for the week and Today.
let compact_journal = journal && width < if split_visible { 460.0 } else { 420.0 };
let tight_journal = journal && width < if split_visible { 400.0 } else { 340.0 };
let tight_split_journal = tight_journal && split_visible;
let hide_doc_actions = width < 300.0;
let show_sidebar_switch = first && !shell.state.sidebar.open;
let inset = if compact_journal {
let inset = if tight_split_journal {
4.0
} else if compact_journal {
5.0
} else if width < 360.0 {
8.0
@@ -199,7 +210,13 @@ pub(super) fn render_detail_header(
} else {
8.0
};
let icon_width = if tight_journal { 24.0 } else { 32.0 };
let icon_width = if tight_split_journal {
20.0
} else if tight_journal {
24.0
} else {
32.0
};
let id = |name: &str| -> SharedString {
if index == 0 {
format!("desktop.topbar.{name}").into()
@@ -252,7 +269,11 @@ pub(super) fn render_detail_header(
}),
)
.w(px(36.0))
.h(px(12.0))
.h(px(if tight_split_journal && first && last {
6.0
} else {
12.0
}))
.gap(px(3.0))
.children((0..3).map(|_| {
div().w(px(3.0)).h(px(3.0)).rounded(px(1.5)).bg(if active {
@@ -319,10 +340,16 @@ pub(super) fn render_detail_header(
.w(px(icon_width))
});
let outer_controls = u8::from(show_sidebar_switch) + u8::from(split_visible) + u8::from(last);
let control_width = if narrow { 36.0 } else { 40.0 };
let control_width = icon_width + gap;
let remaining = width - 2.0 * inset - control_width * f32::from(outer_controls);
let readonly = shell.state.store.is_readonly_sqlite();
let journal_badge_width = if compact_journal { 64.0 } else { 76.0 };
let journal_badge_width = if tight_split_journal {
TIGHT_SPLIT_JOURNAL_BADGE_WIDTH
} else if compact_journal {
64.0
} else {
76.0
};
let readonly_badge = || {
render_readonly_sqlite_badge(
id("readonly_sqlite_badge"),
@@ -356,7 +383,13 @@ pub(super) fn render_detail_header(
.children(close_split);
};
let share_width = 72.0;
let mode_button_width = if tight_journal { 19.0 } else { 24.0 };
let mode_button_width = if tight_split_journal {
18.0
} else if tight_journal {
19.0
} else {
24.0
};
let mode_padding = if compact_journal { 2.0 } else { 4.0 };
let mode_gap = if compact_journal { 2.0 } else { 8.0 };
let show_doc_actions = !journal && !hide_doc_actions;
@@ -443,7 +476,7 @@ pub(super) fn render_detail_header(
}
header = header.children(readonly.then(readonly_badge));
if journal {
let icons_width = f32::from(outer_controls + 1) * (icon_width + gap);
let icons_width = f32::from(outer_controls + 1) * control_width;
let mode_width = 2.0 * (mode_button_width + mode_padding) + mode_gap + gap;
let badge_width = if readonly {
journal_badge_width + gap
@@ -494,12 +527,12 @@ pub(super) fn render_detail_header(
}
let menu_target = target.clone();
let controls_from_more = u8::from(show_doc_actions) + u8::from(last) + u8::from(split_visible);
let menu_offset = if journal {
f32::from(controls_from_more) * (icon_width + gap)
+ if hide_share { 0.0 } else { share_width + gap }
} else {
f32::from(controls_from_more) * control_width
};
let menu_offset = f32::from(controls_from_more) * control_width
+ if journal && !hide_share {
share_width + gap
} else {
0.0
};
let menu_right = right - inset - menu_offset;
header = header.child(
icon_button(