mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-12-05 11:15:01 +03:00
feat(desktop): add right-sidebar frame panel and live thumbnails
Align the Edgeless right-sidebar Frame slide panel with AFFiNE 0.27.5: - Add the Frame inspector tab with All frames count, Presentation stage trigger, empty-state guidance, ordered slide cards, live canvas selection sync, and click-to-center navigation. - Render live frame thumbnails directly from `PreparedEdgelessScene` in unified scene paint order across notes, surface elements, and text, and fit the active slide on the first fullscreen presentation frame.
This commit is contained in:
1 parent
c0de995075
commit
d18b6bbc2c
10 files changed
+1226
-31
No files matched your search
@@ -647,6 +647,83 @@ pub fn build_edgeless_layer_prepared(
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
impl PreparedEdgelessScene {
|
||||
/// Paint the frame contents in scene order under the caller's preview transform and clip.
|
||||
pub fn paint_frame_contents(
|
||||
&self,
|
||||
viewport: Bounds<ui::Pixels>,
|
||||
window: &mut Window,
|
||||
cx: &mut ui::App,
|
||||
) {
|
||||
let visible = world_rect(viewport);
|
||||
for item in self.order.iter().copied() {
|
||||
let (rect, scale, degrees, layout, padding) = match item {
|
||||
PaintItem::Note(i) => {
|
||||
let note = &self.notes[i];
|
||||
if !note.rect.intersects(visible) {
|
||||
continue;
|
||||
}
|
||||
let bounds = Bounds::new(
|
||||
point(px(note.rect.x), px(note.rect.y)),
|
||||
size(px(note.rect.w), px(note.rect.h)),
|
||||
);
|
||||
window.paint_quad(
|
||||
ui::fill(bounds, note.fill).corner_radii(px(note.border_radius)),
|
||||
);
|
||||
(note.rect, note.scale, 0.0, ¬e.layout, NOTE_CARD_PADDING)
|
||||
}
|
||||
PaintItem::Text(i) => {
|
||||
let text = &self.texts[i];
|
||||
if !text.world_aabb.intersects(visible) {
|
||||
continue;
|
||||
}
|
||||
(text.rect, text.scale, text.rotate_deg, &text.layout, 0.0)
|
||||
}
|
||||
PaintItem::Surface(layer, index) => {
|
||||
self.surfaces[layer].paint_item(index, viewport, None, window, cx);
|
||||
continue;
|
||||
}
|
||||
PaintItem::Frame(_) | PaintItem::SurfaceBlock(_) => continue,
|
||||
};
|
||||
let scale_from_origin = TransformationMatrix::unit()
|
||||
.translate(point(ScaledPixels(rect.x), ScaledPixels(rect.y)))
|
||||
.scale(size(scale, scale))
|
||||
.translate(point(ScaledPixels(-rect.x), ScaledPixels(-rect.y)));
|
||||
let (x, y) = rect.center();
|
||||
let transform = TransformationMatrix::unit()
|
||||
.translate(point(ScaledPixels(x), ScaledPixels(y)))
|
||||
.rotate(ui::radians(degrees.to_radians()))
|
||||
.translate(point(ScaledPixels(-x), ScaledPixels(-y)))
|
||||
.compose(scale_from_origin);
|
||||
let origin = point(px(rect.x + padding), px(rect.y + padding));
|
||||
window.with_paint_transformation(transform, |window| {
|
||||
let mut paint = |window: &mut Window| {
|
||||
for block in &layout.blocks {
|
||||
block.body.paint_content(
|
||||
origin + point(px(block.x), px(block.y)),
|
||||
BlockPaint::default(),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
};
|
||||
if padding > 0.0 {
|
||||
let bounds = Bounds::new(
|
||||
origin,
|
||||
size(
|
||||
px((rect.w / scale - 2.0 * padding).max(0.0)),
|
||||
px((rect.h / scale - 2.0 * padding).max(0.0)),
|
||||
),
|
||||
);
|
||||
window.with_local_paint_mask(ContentMask { bounds }, paint);
|
||||
} else {
|
||||
paint(window);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::ShapePreset;
|
||||
|
||||
@@ -382,13 +382,13 @@ impl PlaygroundView {
|
||||
|
||||
let vp_origin = point(px(0.0), px(self.topbar_height()));
|
||||
let vp_size = size(px(viewport_width.max(1.0)), px(viewport_height.max(1.0)));
|
||||
if viewport_width > 0.0 && viewport_height > 0.0 {
|
||||
self.edgeless.ensure_camera_initialized(&snapshot, vp_size);
|
||||
}
|
||||
let presenting = self.edgeless.authoring.tool == edgeless::EdgelessTool::Present;
|
||||
if presenting {
|
||||
self.update_presentation_camera(vp_size);
|
||||
}
|
||||
if viewport_width > 0.0 && viewport_height > 0.0 {
|
||||
self.edgeless.ensure_camera_initialized(&snapshot, vp_size);
|
||||
}
|
||||
let now_ms = self.now_ms(cx);
|
||||
self.edgeless.authoring.last_frame_now_ms = now_ms;
|
||||
self.step_edgeless_fling(now_ms, window);
|
||||
|
||||
@@ -64,6 +64,12 @@ use commands::{
|
||||
find_block, max_spatial_index, next_index_after, next_spatial_index, prev_index_before,
|
||||
};
|
||||
|
||||
impl crate::PlaygroundView {
|
||||
pub fn edgeless_selection(&self) -> &std::collections::BTreeSet<String> {
|
||||
&self.edgeless.authoring.selection
|
||||
}
|
||||
}
|
||||
|
||||
impl EdgelessToolbarHost for crate::PlaygroundView {
|
||||
fn edgeless_present_icon() -> &'static [u8] {
|
||||
PRESENTATION_ICON
|
||||
|
||||
@@ -192,7 +192,9 @@ impl PlaygroundView {
|
||||
|
||||
pub(crate) fn update_presentation_camera(&mut self, viewport: Size<Pixels>) {
|
||||
self.sync_presentation_frames();
|
||||
if self.edgeless_presentation.viewport != Some(viewport) {
|
||||
if !self.edgeless.camera_initialized
|
||||
|| self.edgeless_presentation.viewport != Some(viewport)
|
||||
{
|
||||
self.center_presentation_frame(viewport);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,6 +398,7 @@ impl DesktopEditorHost {
|
||||
let last_mode_obs = last_synced_mode.clone();
|
||||
let observed_workspace = workspace_id.clone();
|
||||
let was_presenting = Cell::new(false);
|
||||
let mut last_frame_selection = std::collections::BTreeSet::new();
|
||||
let subscription = cx.observe(&entity, move |this: &mut DesktopShellView, view, cx| {
|
||||
if pane_id.is_some() {
|
||||
use blocksuite_editor::edgeless::{EdgelessTool, EdgelessToolbarHost};
|
||||
@@ -407,6 +408,17 @@ impl DesktopEditorHost {
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
if pane_id.is_some() {
|
||||
let selection = view.read(cx).edgeless_selection();
|
||||
if &last_frame_selection != selection {
|
||||
last_frame_selection.clone_from(selection);
|
||||
if pane_id == Some(this.state.split.active().id)
|
||||
&& this.state.inspector_tab == Some(crate::DocInspectorTab::Frame)
|
||||
{
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
if fullscreen_changed.replace(false) {
|
||||
cx.notify();
|
||||
}
|
||||
@@ -2493,6 +2505,10 @@ pub(crate) mod tests {
|
||||
) {
|
||||
view.edit_document(cx, |doc| {
|
||||
let page = doc.workspace.page_mut("doc-board").unwrap();
|
||||
for id in ["frame-notes", "frame-workbench"] {
|
||||
page.delete_block_subtree("surface-board", id, 4_998)
|
||||
.unwrap();
|
||||
}
|
||||
page.add_surface_element(
|
||||
"surface-board",
|
||||
"shape-overview",
|
||||
@@ -2772,7 +2788,7 @@ pub(crate) mod tests {
|
||||
fn escape_stops_presentation_before_closing_center_peek() {
|
||||
let mut state = DesktopAppState::seed_showcase(ThemeMode::Light, "2026-12-02");
|
||||
state.open_doc_in_active_pane("doc-arch");
|
||||
state.open_peek_view("doc-board");
|
||||
state.open_peek_view_with_mode("doc-sync", Some(crate::DocViewMode::Edgeless));
|
||||
let (platform, app, handle, window) = open_test_shell(state, 1280, 800);
|
||||
window.request_frame();
|
||||
platform.run_until_parked();
|
||||
|
||||
@@ -471,6 +471,27 @@ impl DesktopDocStore {
|
||||
)?;
|
||||
s.add_block("p-board", BlockSpec::Paragraph { paragraph_type: ParagraphType::Text, text: "Edgeless whiteboard elements render alongside live Page notes on a shared GPU canvas.".into() }, Some("note-board"), None, 14)?;
|
||||
seed_surface_diagram(&mut s, "surface-board", 20);
|
||||
for (id, title, xywh, index) in [
|
||||
(
|
||||
"frame-workbench",
|
||||
"Workbench flow",
|
||||
"[580,55,300,335]",
|
||||
"a1",
|
||||
),
|
||||
("frame-notes", "Spatial notes", "[0,40,520,340]", "a0"),
|
||||
] {
|
||||
s.add_block(
|
||||
id,
|
||||
BlockSpec::Frame {
|
||||
title: title.into(),
|
||||
xywh: Some(xywh.into()),
|
||||
presentation_index: Some(index.into()),
|
||||
},
|
||||
Some("surface-board"),
|
||||
None,
|
||||
36,
|
||||
)?;
|
||||
}
|
||||
|
||||
self.register_seeded(
|
||||
DesktopDocMeta {
|
||||
|
||||
@@ -25,6 +25,7 @@ mod doc_width;
|
||||
pub enum DocInspectorTab {
|
||||
Outline,
|
||||
Info,
|
||||
Frame,
|
||||
Journal,
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,485 @@
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
use blocksuite_editor::{
|
||||
block_flow::FormFactor,
|
||||
edgeless::{
|
||||
EdgelessCamera, EdgelessCanvasState, EdgelessRenderInput, NavigatorMode,
|
||||
PreparedEdgelessScene, PresentationFrame, WorldRect, parse_xywh, prepare_edgeless_scene,
|
||||
presentation_frames,
|
||||
},
|
||||
scroll::{ScrollAxis, wheel_delta},
|
||||
};
|
||||
use blocksuite_playground_doc::read::{BlockContent, PageSnapshot};
|
||||
use playground::{PlaygroundMode, PlaygroundView, edgeless::PRESENTATION_ICON};
|
||||
use ui::{
|
||||
App, Bounds, ContentMask, Context, ElementId, Entity, FontWeight, InteractiveElement,
|
||||
IntoElement, ParentElement, RenderOnce, ScaledPixels, SharedString, StatefulInteractiveElement,
|
||||
Styled, TransformationMatrix, Window, canvas, div, point, px, size, svg,
|
||||
};
|
||||
use ui_kit::VirtualList;
|
||||
use ui_tokens::ThemeMode;
|
||||
|
||||
use crate::{
|
||||
DesktopFlexExt, DesktopPalette, DocViewMode, playground_theme_for, split_view::PaneId,
|
||||
workbench::DesktopShellView,
|
||||
};
|
||||
|
||||
const PRESENT_ID: &str = "desktop.inspector.frame.present";
|
||||
const EMPTY_ID: &str = "desktop.inspector.frame.empty";
|
||||
const LIST_ID: &str = "desktop.inspector.frame.list";
|
||||
const PREVIEW_HEIGHT: f32 = 170.0;
|
||||
const ROW_HEIGHT: f32 = 198.0;
|
||||
const ROW_STRIDE: f32 = ROW_HEIGHT + 16.0;
|
||||
const FIT_PADDING: f32 = 20.0;
|
||||
|
||||
#[derive(Default)]
|
||||
struct PanelState {
|
||||
revision: Option<(u64, ThemeMode)>,
|
||||
frames: Vec<PresentationFrame>,
|
||||
preview: Option<Rc<PreparedEdgelessScene>>,
|
||||
scroll: f32,
|
||||
viewport_height: Option<f32>,
|
||||
}
|
||||
|
||||
fn prepare_thumbnail(
|
||||
snapshot: &PageSnapshot,
|
||||
theme: ThemeMode,
|
||||
window: &Window,
|
||||
) -> Rc<PreparedEdgelessScene> {
|
||||
let theme = playground_theme_for(theme);
|
||||
Rc::new(prepare_edgeless_scene(
|
||||
&mut EdgelessCanvasState::new(),
|
||||
&EdgelessRenderInput {
|
||||
snapshot,
|
||||
doc_rev: 0,
|
||||
env_rev: 0,
|
||||
preview_rev: 0,
|
||||
preedit_nonce: 0,
|
||||
theme,
|
||||
palette: &theme.palette(),
|
||||
page_titles: &BTreeMap::new(),
|
||||
images: &HashMap::new(),
|
||||
pdf_previews: None,
|
||||
doc_directory: None,
|
||||
viewport_width: 0.0,
|
||||
viewport_height: 0.0,
|
||||
direction: window.layout_direction(),
|
||||
form_factor: FormFactor::Desktop,
|
||||
utc_offset_minutes: 0,
|
||||
utc_offset_at: None,
|
||||
editing_selection: None,
|
||||
local_collapsed: None,
|
||||
},
|
||||
window,
|
||||
))
|
||||
}
|
||||
|
||||
pub(super) struct FramePanel {
|
||||
pub(super) shell: Entity<DesktopShellView>,
|
||||
pub(super) doc: String,
|
||||
pub(super) workspace: String,
|
||||
pub(super) scroll_key: ElementId,
|
||||
pub(super) palette: DesktopPalette,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Target {
|
||||
workspace: String,
|
||||
doc: String,
|
||||
pane: PaneId,
|
||||
tab: u64,
|
||||
}
|
||||
|
||||
impl Target {
|
||||
fn active_editor(&self, shell: &DesktopShellView, app: &App) -> Option<Entity<PlaygroundView>> {
|
||||
let pane = shell.state.split.active();
|
||||
if shell.state.store.active_workspace().id != self.workspace
|
||||
|| pane.id != self.pane
|
||||
|| pane.active_tab().id != self.tab
|
||||
|| pane.active_route().doc_id() != Some(self.doc.as_str())
|
||||
|| !shell.state.is_openable_doc(&self.doc)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let editor = shell.editor_host().pane_entity(self.pane)?;
|
||||
(editor.read(app).active_doc_id() == Some(self.doc.as_str())).then_some(editor)
|
||||
}
|
||||
|
||||
fn switch_mode(
|
||||
shell: &mut DesktopShellView,
|
||||
editor: &Entity<PlaygroundView>,
|
||||
cx: &mut Context<DesktopShellView>,
|
||||
) {
|
||||
let pane = shell.state.split.active_mut();
|
||||
if pane.active_mode() != DocViewMode::Edgeless {
|
||||
pane.set_mode(DocViewMode::Edgeless);
|
||||
cx.notify();
|
||||
}
|
||||
editor.update(cx, |editor, cx| {
|
||||
editor.set_mode_immediate(PlaygroundMode::Edgeless, cx);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for FramePanel {
|
||||
fn render(self, window: &mut Window, app: &mut App) -> impl IntoElement {
|
||||
let shell = self.shell.read(app);
|
||||
let pane = shell.state.split.active();
|
||||
let target = Target {
|
||||
workspace: self.workspace,
|
||||
doc: self.doc,
|
||||
pane: pane.id,
|
||||
tab: pane.active_tab().id,
|
||||
};
|
||||
let theme = shell.state.theme;
|
||||
let state = window.use_keyed_state(self.scroll_key, app, |_, _| PanelState::default());
|
||||
state.update(app, |state, cx| {
|
||||
let shell = self.shell.read(cx);
|
||||
let entry = shell.state.store.get_doc(&target.doc);
|
||||
let revision = entry.map(|entry| (entry.revision, theme));
|
||||
if revision != state.revision {
|
||||
state.revision = revision;
|
||||
state.frames = entry
|
||||
.map(|entry| presentation_frames(&entry.snapshot))
|
||||
.unwrap_or_default();
|
||||
state.preview = entry
|
||||
.filter(|_| !state.frames.is_empty())
|
||||
.map(|entry| prepare_thumbnail(&entry.snapshot, theme, window));
|
||||
}
|
||||
});
|
||||
let palette = self.palette;
|
||||
let present_target = target.clone();
|
||||
let shell = self.shell.clone();
|
||||
let header = div()
|
||||
.h(px(36.0))
|
||||
.px(px(8.0))
|
||||
.flex()
|
||||
.flex_shrink(0.0)
|
||||
.items_center()
|
||||
.justify_between()
|
||||
.gap(px(4.0))
|
||||
.text_size(px(12.0))
|
||||
.text_color(palette.text_secondary)
|
||||
.child(
|
||||
div()
|
||||
.min_w_0()
|
||||
.text_ellipsis()
|
||||
.text_size(px(14.0))
|
||||
.font_weight(FontWeight::MEDIUM)
|
||||
.child("All frames"),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.id(PRESENT_ID)
|
||||
.snapshot(PRESENT_ID, Some("desktop.inspector"))
|
||||
.tab_stop(true)
|
||||
.cursor_pointer()
|
||||
.flex()
|
||||
.flex_shrink(0.0)
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.gap(px(4.0))
|
||||
.w(px(117.0))
|
||||
.h(px(28.0))
|
||||
.px(px(8.0))
|
||||
.rounded(px(8.0))
|
||||
.border_1()
|
||||
.border_color(palette.border)
|
||||
.hover(move |style| style.bg(palette.hover_color))
|
||||
.text_color(palette.text_primary)
|
||||
.font_weight(FontWeight::MEDIUM)
|
||||
.child(
|
||||
svg()
|
||||
.data(PRESENTATION_ICON)
|
||||
.size(px(16.0))
|
||||
.text_color(palette.text_secondary),
|
||||
)
|
||||
.child("Presentation")
|
||||
.on_click(move |_, window, app| {
|
||||
shell.update(app, |shell, cx| {
|
||||
if let Some(editor) = present_target.active_editor(shell, cx) {
|
||||
Target::switch_mode(shell, &editor, cx);
|
||||
shell.editor_host().toggle_pane_presentation(
|
||||
present_target.pane,
|
||||
&present_target.doc,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
});
|
||||
}),
|
||||
);
|
||||
let body = if state.read(app).frames.is_empty() {
|
||||
div()
|
||||
.id(EMPTY_ID)
|
||||
.snapshot(EMPTY_ID, Some("desktop.inspector"))
|
||||
.snapshot_text("No frames in this document.")
|
||||
.flex()
|
||||
.flex_col()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.gap(px(4.0))
|
||||
.px(px(8.0))
|
||||
.text_size(px(15.0))
|
||||
.text_color(palette.text_secondary)
|
||||
.child("Empty")
|
||||
.child("No frames in this document.")
|
||||
.into_any_element()
|
||||
} else {
|
||||
frame_list(&state, &target, &self.shell, palette, window, app).into_any_element()
|
||||
};
|
||||
div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
.child(header)
|
||||
.child(body)
|
||||
}
|
||||
}
|
||||
|
||||
fn frame_list(
|
||||
state: &Entity<PanelState>,
|
||||
target: &Target,
|
||||
shell: &Entity<DesktopShellView>,
|
||||
palette: DesktopPalette,
|
||||
window: &Window,
|
||||
app: &App,
|
||||
) -> impl IntoElement {
|
||||
let data = state.read(app);
|
||||
let editor = target.active_editor(shell.read(app), app);
|
||||
let selection = editor.as_ref().and_then(|editor| {
|
||||
let editor = editor.read(app);
|
||||
(editor.mode() == PlaygroundMode::Edgeless).then(|| editor.edgeless_selection())
|
||||
});
|
||||
let measured_height = data.viewport_height;
|
||||
let viewport = measured_height.unwrap_or_else(|| f32::from(window.viewport_size().height));
|
||||
let list = VirtualList::fixed(data.frames.len(), ROW_STRIDE);
|
||||
let offset = ScrollAxis::new(data.scroll, list.total_height() - viewport).offset;
|
||||
let slice = list.window(viewport, offset, ROW_STRIDE);
|
||||
let mut rows = div()
|
||||
.w_full()
|
||||
.relative()
|
||||
.top(px(slice.leading_spacer - offset))
|
||||
.flex_shrink(0.0)
|
||||
.px(px(8.0))
|
||||
.flex()
|
||||
.flex_col();
|
||||
for index in slice.visible_range {
|
||||
let frame = &data.frames[index];
|
||||
rows = rows.child(div().h(px(ROW_STRIDE)).flex_shrink(0.0).child(frame_card(
|
||||
frame,
|
||||
index,
|
||||
selection.is_some_and(|selection| selection.contains(&frame.id)),
|
||||
data.preview.clone(),
|
||||
palette,
|
||||
target.clone(),
|
||||
shell.clone(),
|
||||
)));
|
||||
}
|
||||
let measure_state = state.clone();
|
||||
let scroll_state = state.clone();
|
||||
let total_height = list.total_height();
|
||||
div()
|
||||
.id(LIST_ID)
|
||||
.snapshot(LIST_ID, Some("desktop.inspector"))
|
||||
.relative()
|
||||
.w_full()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
.overflow_hidden()
|
||||
.on_scroll(move |event, _, app| {
|
||||
scroll_state.update(app, |data, cx| {
|
||||
let (_, dy) = wheel_delta(event, 0.0);
|
||||
let mut axis = ScrollAxis::new(
|
||||
data.scroll,
|
||||
total_height - data.viewport_height.unwrap_or(viewport),
|
||||
);
|
||||
if axis.apply(dy) {
|
||||
data.scroll = axis.offset;
|
||||
cx.stop_propagation();
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
})
|
||||
.child(rows)
|
||||
.child(
|
||||
canvas(
|
||||
move |bounds, window, _| {
|
||||
let height = f32::from(bounds.size.height);
|
||||
if measured_height != Some(height) {
|
||||
window.on_next_frame(move |_, app| {
|
||||
measure_state.update(app, |data, cx| {
|
||||
data.viewport_height = Some(height);
|
||||
data.scroll =
|
||||
ScrollAxis::new(data.scroll, total_height - height).offset;
|
||||
cx.notify();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|_, (), _, _| {},
|
||||
)
|
||||
.absolute()
|
||||
.inset_0(),
|
||||
)
|
||||
}
|
||||
|
||||
fn frame_card(
|
||||
frame: &PresentationFrame,
|
||||
index: usize,
|
||||
selected: bool,
|
||||
preview: Option<Rc<PreparedEdgelessScene>>,
|
||||
palette: DesktopPalette,
|
||||
target: Target,
|
||||
shell: Entity<DesktopShellView>,
|
||||
) -> impl IntoElement {
|
||||
let id = frame.id.clone();
|
||||
let key = ui::snap_id!("desktop.inspector.frame.item.{id}");
|
||||
let title = if frame.title.is_empty() {
|
||||
SharedString::new_static("Frame")
|
||||
} else {
|
||||
SharedString::new(&frame.title)
|
||||
};
|
||||
super::max_width(div(), px(284.0))
|
||||
.id(SharedString::from(format!("frame-item-{id}")))
|
||||
.snapshot(key, Some(LIST_ID))
|
||||
.snapshot_text(title.clone())
|
||||
.tab_stop(true)
|
||||
.cursor_pointer()
|
||||
.w_full()
|
||||
.h(px(ROW_HEIGHT))
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap(px(8.0))
|
||||
.child(
|
||||
div()
|
||||
.h(px(20.0))
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(px(6.0))
|
||||
.text_size(px(14.0))
|
||||
.text_color(palette.text_primary)
|
||||
.child(
|
||||
div()
|
||||
.h(px(18.0))
|
||||
.min_w(px(18.0))
|
||||
.px(px(3.0))
|
||||
.flex()
|
||||
.flex_shrink(0.0)
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.rounded(px(2.0))
|
||||
.bg(palette.text_primary)
|
||||
.text_color(palette.bg_canvas)
|
||||
.font_weight(FontWeight::MEDIUM)
|
||||
.child((index + 1).to_string()),
|
||||
)
|
||||
.child(div().min_w_0().text_ellipsis().child(title)),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.h(px(PREVIEW_HEIGHT))
|
||||
.w_full()
|
||||
.flex_shrink(0.0)
|
||||
.relative()
|
||||
.overflow_hidden()
|
||||
.rounded(px(8.0))
|
||||
.bg(palette.bg_surface)
|
||||
.border(px(if selected { 2.0 } else { 1.0 }))
|
||||
.border_color(if selected {
|
||||
palette.accent
|
||||
} else {
|
||||
palette.border
|
||||
})
|
||||
.children(
|
||||
frame
|
||||
.bounds
|
||||
.zip(preview)
|
||||
.map(|(frame, scene)| thumbnail(frame, scene, palette)),
|
||||
),
|
||||
)
|
||||
.on_click(move |_, window, app| {
|
||||
shell.update(app, |shell, cx| {
|
||||
let Some(editor) = target.active_editor(shell, cx) else {
|
||||
return;
|
||||
};
|
||||
let Some(BlockContent::Frame { xywh, .. }) = editor
|
||||
.read(cx)
|
||||
.page_snapshot()
|
||||
.and_then(|snapshot| snapshot.block(&id))
|
||||
.map(|block| &block.content)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let bounds = parse_xywh(xywh);
|
||||
Target::switch_mode(shell, &editor, cx);
|
||||
editor.update(cx, |editor, cx| {
|
||||
editor.edgeless_commit_inline_edit(window, cx);
|
||||
editor.edgeless_set_selection([id.clone()], cx);
|
||||
if let Some(camera) =
|
||||
bounds.and_then(|frame| fit_frame(frame, editor.canvas_rect(window).1))
|
||||
{
|
||||
editor.set_edgeless_camera(camera.pan_x, camera.pan_y, camera.zoom, cx);
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
fn thumbnail(
|
||||
frame: WorldRect,
|
||||
scene: Rc<PreparedEdgelessScene>,
|
||||
palette: DesktopPalette,
|
||||
) -> impl IntoElement {
|
||||
canvas(
|
||||
|_, _, _| (),
|
||||
move |bounds, (), window, cx| {
|
||||
let zoom = (f32::from(bounds.size.width) / frame.w)
|
||||
.min(f32::from(bounds.size.height) / frame.h);
|
||||
if !zoom.is_finite() || zoom <= 0.0 {
|
||||
return;
|
||||
}
|
||||
let viewport = size(px(frame.w * zoom), px(frame.h * zoom));
|
||||
let origin = point(
|
||||
bounds.origin.x + (bounds.size.width - viewport.width) / 2.0,
|
||||
bounds.origin.y + (bounds.size.height - viewport.height) / 2.0,
|
||||
);
|
||||
let clip = Bounds::new(origin, viewport);
|
||||
let world = Bounds::new(
|
||||
point(px(frame.x), px(frame.y)),
|
||||
size(px(frame.w), px(frame.h)),
|
||||
);
|
||||
let transform = TransformationMatrix::unit()
|
||||
.translate(point(
|
||||
ScaledPixels(origin.x.into()),
|
||||
ScaledPixels(origin.y.into()),
|
||||
))
|
||||
.scale(size(zoom, zoom))
|
||||
.translate(point(ScaledPixels(-frame.x), ScaledPixels(-frame.y)));
|
||||
window.paint_quad(ui::fill(clip, palette.bg_canvas));
|
||||
window.with_content_mask(Some(ContentMask { bounds: clip }), |window| {
|
||||
window.with_paint_transformation(transform, |window| {
|
||||
scene.paint_frame_contents(world, window, cx);
|
||||
});
|
||||
});
|
||||
},
|
||||
)
|
||||
.absolute()
|
||||
.inset(px(2.0))
|
||||
}
|
||||
|
||||
fn fit_frame(frame: WorldRect, viewport: ui::Size<ui::Pixels>) -> Option<EdgelessCamera> {
|
||||
let padding = px(2.0 * FIT_PADDING);
|
||||
let padded = size(viewport.width - padding, viewport.height - padding);
|
||||
let mut camera = NavigatorMode::Fit.camera(frame, padded)?;
|
||||
let inset = FIT_PADDING / camera.zoom;
|
||||
camera.pan_x -= inset;
|
||||
camera.pan_y -= inset;
|
||||
Some(camera)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod frame_panel;
|
||||
mod outline;
|
||||
mod properties;
|
||||
#[cfg(test)]
|
||||
@@ -6,10 +7,13 @@ mod tests;
|
||||
pub(crate) use properties::render_doc_info_body;
|
||||
|
||||
use ui::{
|
||||
Context, Div, FontWeight, Hsla, InteractiveElement, IntoElement, ParentElement, Stateful,
|
||||
StatefulInteractiveElement, Styled, div, px, svg,
|
||||
AppContext as _, Context, Div, FontWeight, Hsla, InteractiveElement, IntoElement,
|
||||
ParentElement, Stateful, StatefulInteractiveElement, Styled, Window, div, px, svg,
|
||||
};
|
||||
use ui_tokens::{
|
||||
FONT_SANS, ThemeMode,
|
||||
icons::{BULLETED_LIST, FRAME},
|
||||
};
|
||||
use ui_tokens::{FONT_SANS, ThemeMode, icons::BULLETED_LIST};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(super) use super::FALLBACK_TAG_RGB;
|
||||
@@ -31,8 +35,6 @@ struct SwitcherStyle {
|
||||
track_bg: Hsla,
|
||||
active_bg: Hsla,
|
||||
hover_bg: Hsla,
|
||||
active_text: Hsla,
|
||||
inactive_text: Hsla,
|
||||
active_icon: Hsla,
|
||||
inactive_icon: Hsla,
|
||||
}
|
||||
@@ -62,16 +64,6 @@ impl SwitcherStyle {
|
||||
"--affine-v2-switch-buttonBackground-hover",
|
||||
tokens.hover,
|
||||
),
|
||||
active_text: crate::theme_color(
|
||||
tokens,
|
||||
"--affine-v2-switch-fontColor-primary",
|
||||
tokens.text_primary,
|
||||
),
|
||||
inactive_text: crate::theme_color(
|
||||
tokens,
|
||||
"--affine-v2-switch-fontColor-tertiary",
|
||||
tokens.text_secondary,
|
||||
),
|
||||
active_icon: crate::theme_color(
|
||||
tokens,
|
||||
"--affine-v2-switch-iconColor-active",
|
||||
@@ -115,6 +107,14 @@ pub(crate) fn render_doc_inspector(
|
||||
palette,
|
||||
})
|
||||
.into_any_element(),
|
||||
(DocInspectorTab::Frame, Some(id)) => ui::ViewElement::new(frame_panel::FramePanel {
|
||||
shell: cx.entity(),
|
||||
doc: id.to_owned(),
|
||||
workspace: store.active_workspace().id.clone(),
|
||||
scroll_key: key.into(),
|
||||
palette,
|
||||
})
|
||||
.into_any_element(),
|
||||
_ => {
|
||||
let mut body = div().flex().flex_col().gap(px(10.0)).w_full();
|
||||
if let (DocInspectorTab::Journal, _) = (tab, doc_id) {
|
||||
@@ -149,8 +149,8 @@ pub(crate) fn render_doc_inspector(
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(px(2.0))
|
||||
.p(px(2.0))
|
||||
.gap(px(8.0))
|
||||
.p(px(4.0))
|
||||
.rounded(px(8.0))
|
||||
.bg(switcher.track_bg)
|
||||
.child(inspector_tab_btn(
|
||||
@@ -171,6 +171,15 @@ pub(crate) fn render_doc_inspector(
|
||||
switcher,
|
||||
cx,
|
||||
))
|
||||
.child(inspector_tab_btn(
|
||||
"desktop.inspector.tab.frame",
|
||||
"Frame",
|
||||
FRAME.svg.as_bytes(),
|
||||
tab,
|
||||
DocInspectorTab::Frame,
|
||||
switcher,
|
||||
cx,
|
||||
))
|
||||
.child(inspector_tab_btn(
|
||||
"desktop.inspector.tab.journal",
|
||||
"Journal",
|
||||
@@ -215,36 +224,49 @@ fn inspector_tab_btn(
|
||||
.tab_stop(true)
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(px(5.0))
|
||||
.h(px(28.0))
|
||||
.px(px(6.0))
|
||||
.justify_center()
|
||||
.size(px(28.0))
|
||||
.rounded(px(6.0))
|
||||
.text_size(px(13.0))
|
||||
.cursor_pointer();
|
||||
if active {
|
||||
btn = btn
|
||||
.bg(style.active_bg)
|
||||
.shadow(crate::theme_shadow(style.mode, "--affine-button-shadow"))
|
||||
.text_color(style.active_text);
|
||||
.shadow(crate::theme_shadow(style.mode, "--affine-button-shadow"));
|
||||
} else {
|
||||
let hover_bg = style.hover_bg;
|
||||
btn = btn
|
||||
.bg(ui::transparent_black())
|
||||
.text_color(style.inactive_text)
|
||||
.hover(move |s| s.bg(hover_bg));
|
||||
}
|
||||
btn.child(svg().data(icon).size(px(16.0)).text_color(if active {
|
||||
btn.interactivity()
|
||||
.tooltip(move |_, app| app.new(|_| TabTooltip(label, style.mode)).into());
|
||||
btn.child(svg().data(icon).size(px(20.0)).text_color(if active {
|
||||
style.active_icon
|
||||
} else {
|
||||
style.inactive_icon
|
||||
}))
|
||||
.child(label)
|
||||
.on_click(cx.listener(move |this, _, _, cx| {
|
||||
this.state.inspector_tab = Some(target);
|
||||
cx.notify();
|
||||
}))
|
||||
}
|
||||
|
||||
struct TabTooltip(&'static str, ThemeMode);
|
||||
|
||||
impl ui::Render for TabTooltip {
|
||||
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
|
||||
let palette = crate::palette_for(self.1);
|
||||
div()
|
||||
.px(px(8.0))
|
||||
.py(px(4.0))
|
||||
.rounded(px(4.0))
|
||||
.bg(palette.bg_elevated)
|
||||
.text_color(palette.text_primary)
|
||||
.text_size(px(12.0))
|
||||
.child(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn section_title(label: &'static str, palette: DesktopPalette) -> Div {
|
||||
div()
|
||||
.text_size(px(14.0))
|
||||
|
||||
@@ -580,3 +580,568 @@ fn inspector_properties_virtualizes_1002_backlinks_and_updates_across_mutations(
|
||||
.expect("view")
|
||||
});
|
||||
}
|
||||
|
||||
const FRAME_TAB: &str = "desktop.inspector.tab.frame";
|
||||
const FRAME_NOTES: &str = "desktop.inspector.frame.item.frame-notes";
|
||||
const FRAME_WORKBENCH: &str = "desktop.inspector.frame.item.frame-workbench";
|
||||
|
||||
struct FramePanelTest {
|
||||
platform: Rc<HeadlessPlatform>,
|
||||
app: ui::ApplicationHandle,
|
||||
handle: ui::WindowHandle<DesktopShellView>,
|
||||
window: ui::HeadlessWindow,
|
||||
}
|
||||
|
||||
impl FramePanelTest {
|
||||
fn open(state: DesktopAppState, width: u32) -> Self {
|
||||
let (platform, app, handle, window) =
|
||||
crate::editor_host::tests::open_test_shell(state, width, 800);
|
||||
let test = Self {
|
||||
platform,
|
||||
app,
|
||||
handle,
|
||||
window,
|
||||
};
|
||||
test.frame();
|
||||
test
|
||||
}
|
||||
|
||||
fn frame(&self) {
|
||||
self.window.request_frame();
|
||||
self.platform.run_until_parked();
|
||||
}
|
||||
|
||||
fn inspect<T>(
|
||||
&self,
|
||||
f: impl FnOnce(&mut DesktopShellView, &mut ui::Window, &mut ui::Context<DesktopShellView>) -> T,
|
||||
) -> T {
|
||||
self.app.update(|cx| self.handle.update(cx, f).unwrap())
|
||||
}
|
||||
|
||||
fn center(&self, id: &str) -> ui::Point<ui::Pixels> {
|
||||
self.inspect(|_, window, _| {
|
||||
let b = window.frame_snapshot().elements[id].bounds;
|
||||
point(px(b.x + b.width / 2.0), px(b.y + b.height / 2.0))
|
||||
})
|
||||
}
|
||||
|
||||
fn click(&self, id: &str) {
|
||||
self.window.simulate_click(self.center(id));
|
||||
self.frame();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frame_panel_orders_frames_fits_the_canvas_and_tracks_selection() {
|
||||
use crate::DocViewMode;
|
||||
|
||||
let mut state = DesktopAppState::seed_showcase(ThemeMode::Light, "2026-12-02");
|
||||
state.open_doc_in_active_pane("doc-board");
|
||||
state.split.active_mut().set_mode(DocViewMode::Page);
|
||||
state.inspector_tab = Some(DocInspectorTab::Outline);
|
||||
let test = FramePanelTest::open(state, 1280);
|
||||
test.click(FRAME_TAB);
|
||||
assert!(test.center(FRAME_NOTES).y < test.center(FRAME_WORKBENCH).y);
|
||||
test.click(FRAME_WORKBENCH);
|
||||
test.inspect(|shell, window, cx| {
|
||||
let pane = shell.state.split.active();
|
||||
assert_eq!(pane.active_mode(), DocViewMode::Edgeless);
|
||||
let editor = shell.editor_host().pane_entity(pane.id).unwrap();
|
||||
let editor = editor.read(cx);
|
||||
assert_eq!(editor.mode(), playground::PlaygroundMode::Edgeless);
|
||||
assert_eq!(
|
||||
editor
|
||||
.edgeless_selection()
|
||||
.iter()
|
||||
.map(String::as_str)
|
||||
.collect::<Vec<_>>(),
|
||||
["frame-workbench"]
|
||||
);
|
||||
let (origin, viewport) = editor.canvas_rect(window);
|
||||
let camera = editor.edgeless_camera();
|
||||
let top_left = camera.world_to_screen(point(px(580.0), px(55.0)), origin);
|
||||
let bottom_right = camera.world_to_screen(point(px(880.0), px(390.0)), origin);
|
||||
let margins = [
|
||||
f32::from(top_left.x - origin.x),
|
||||
f32::from(top_left.y - origin.y),
|
||||
f32::from(origin.x + viewport.width - bottom_right.x),
|
||||
f32::from(origin.y + viewport.height - bottom_right.y),
|
||||
];
|
||||
assert!(margins.iter().all(|margin| *margin >= 19.99), "{margins:?}");
|
||||
assert!((margins[0] - margins[2]).abs() < 0.01, "{margins:?}");
|
||||
assert!((margins[1] - margins[3]).abs() < 0.01, "{margins:?}");
|
||||
assert!((margins.into_iter().reduce(f32::min).unwrap() - 20.0).abs() < 0.01);
|
||||
});
|
||||
|
||||
let card_edge = || {
|
||||
test.inspect(|_, window, _| {
|
||||
let card = window.frame_snapshot().elements[FRAME_WORKBENCH].bounds;
|
||||
window
|
||||
.render_to_image()
|
||||
.unwrap()
|
||||
.get_pixel((card.x + card.width / 2.0) as u32, (card.y + 29.0) as u32)
|
||||
.0
|
||||
})
|
||||
};
|
||||
let selected_color = card_edge();
|
||||
let blank = test.inspect(|_, window, _| {
|
||||
let viewport = window.frame_snapshot().elements["edgeless.viewport"].bounds;
|
||||
point(px(viewport.x + 10.0), px(viewport.y + 8.0))
|
||||
});
|
||||
test.window.simulate_click(blank);
|
||||
test.frame();
|
||||
assert_ne!(card_edge(), selected_color);
|
||||
test.inspect(|shell, _, cx| {
|
||||
let editor = shell
|
||||
.editor_host()
|
||||
.pane_entity(shell.state.split.active().id)
|
||||
.unwrap();
|
||||
assert!(editor.read(cx).edgeless_selection().is_empty());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frame_panel_presentation_switches_page_mode_and_reports_empty_docs() {
|
||||
use crate::DocViewMode;
|
||||
const EMPTY: &str = "desktop.inspector.frame.empty";
|
||||
|
||||
for (doc, progress) in [("doc-board", Some("1 / 2")), ("doc-sync", None)] {
|
||||
let mut state = DesktopAppState::seed_showcase(ThemeMode::Dark, "2026-12-02");
|
||||
state.open_doc_in_active_pane(doc);
|
||||
state.split.active_mut().set_mode(DocViewMode::Page);
|
||||
state.inspector_tab = Some(DocInspectorTab::Frame);
|
||||
let test = FramePanelTest::open(state, 1280);
|
||||
test.inspect(|_, window, _| {
|
||||
let snapshot = window.frame_snapshot();
|
||||
assert_eq!(
|
||||
snapshot
|
||||
.elements
|
||||
.get(EMPTY)
|
||||
.and_then(|node| node.text.as_deref()),
|
||||
progress.is_none().then_some("No frames in this document.")
|
||||
);
|
||||
});
|
||||
test.click("desktop.inspector.frame.present");
|
||||
test.inspect(|shell, window, cx| {
|
||||
let pane = shell.state.split.active();
|
||||
assert_eq!(pane.active_mode(), DocViewMode::Edgeless);
|
||||
let editor = shell.editor_host().pane_entity(pane.id).unwrap();
|
||||
assert!(editor.read(cx).is_presentation_fullscreen());
|
||||
let snapshot = window.frame_snapshot();
|
||||
if let Some(progress) = progress {
|
||||
assert_eq!(
|
||||
snapshot.elements["chrome.edgeless_toolbar.presentation.current"]
|
||||
.text
|
||||
.as_deref(),
|
||||
Some(progress)
|
||||
);
|
||||
} else {
|
||||
assert!(snapshot.elements.contains_key("overlay.context_menu.toast"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frame_panel_virtualizes_and_scrolls_to_the_last_card() {
|
||||
const COUNT: usize = 50;
|
||||
let mut state = DesktopAppState::seed_showcase(ThemeMode::Light, "2026-12-02");
|
||||
state.open_doc_in_active_pane("doc-board");
|
||||
state.inspector_tab = Some(DocInspectorTab::Frame);
|
||||
let entry = state.store.docs.get_mut("doc-board").unwrap();
|
||||
for i in 0..COUNT {
|
||||
entry
|
||||
.session
|
||||
.add_block(
|
||||
&format!("extra-{i}"),
|
||||
BlockSpec::Frame {
|
||||
title: String::new(),
|
||||
xywh: Some("[0,0,100,100]".into()),
|
||||
presentation_index: Some(format!("b{i:02}")),
|
||||
},
|
||||
Some("surface-board"),
|
||||
None,
|
||||
100 + i as u64,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
entry.snapshot = entry.session.read_page_snapshot().unwrap();
|
||||
|
||||
let test = FramePanelTest::open(state, 320);
|
||||
let last_id = format!("desktop.inspector.frame.item.extra-{}", COUNT - 1);
|
||||
test.inspect(|_, window, _| {
|
||||
let snapshot = window.frame_snapshot();
|
||||
let elements = &snapshot.elements;
|
||||
assert!(!elements.contains_key(&last_id));
|
||||
let pane = elements["desktop.inspector"].bounds;
|
||||
for id in ["outline", "info", "frame", "journal"] {
|
||||
let button = elements[&format!("desktop.inspector.tab.{id}")].bounds;
|
||||
assert!(button.x >= pane.x && button.x + button.width <= pane.x + pane.width);
|
||||
}
|
||||
});
|
||||
test.window
|
||||
.dispatch_input(PlatformInput::Scroll(ScrollEvent {
|
||||
position: test.center("desktop.inspector.frame.list"),
|
||||
delta: ScrollDelta::Pixels(point(px(0.0), px(-20_000.0))),
|
||||
..Default::default()
|
||||
}));
|
||||
test.frame();
|
||||
test.inspect(|_, window, _| {
|
||||
let snapshot = window.frame_snapshot();
|
||||
assert!(!snapshot.elements.contains_key(FRAME_NOTES));
|
||||
assert_eq!(snapshot.elements[&last_id].text.as_deref(), Some("Frame"));
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod frame_regressions {
|
||||
use super::*;
|
||||
use crate::DocViewMode;
|
||||
use blocksuite_editor::edgeless::{NavigatorMode, WorldRect};
|
||||
use image::{RgbaImage, imageops::crop_imm};
|
||||
|
||||
const PRESENT: &str = "desktop.inspector.frame.present";
|
||||
const TEXT_DOC: &str = "doc-sync";
|
||||
|
||||
#[test]
|
||||
fn frame_panel_thumbnails_paint_edgeless_text_and_refresh_after_edits() {
|
||||
let mut counts = Vec::new();
|
||||
for (theme, name) in [(ThemeMode::Light, "light"), (ThemeMode::Dark, "dark")] {
|
||||
let mut state = DesktopAppState::seed_showcase(theme, "2026-12-02");
|
||||
state.open_doc_in_active_pane(TEXT_DOC);
|
||||
state.split.active_mut().set_mode(DocViewMode::Edgeless);
|
||||
state.inspector_tab = Some(DocInspectorTab::Frame);
|
||||
let entry = state.store.docs.get_mut(TEXT_DOC).unwrap();
|
||||
for (id, title, xywh, order) in [
|
||||
("empty-preview", "Empty frame", "[700,300,320,180]", "a0"),
|
||||
("text-preview", "Text only", "[700,50,320,180]", "a1"),
|
||||
] {
|
||||
entry
|
||||
.session
|
||||
.add_block(
|
||||
id,
|
||||
BlockSpec::Frame {
|
||||
title: title.into(),
|
||||
xywh: Some(xywh.into()),
|
||||
presentation_index: Some(order.into()),
|
||||
},
|
||||
Some("surface-sync"),
|
||||
None,
|
||||
2_000,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
entry
|
||||
.session
|
||||
.add_edgeless_text(
|
||||
Some("surface-sync"),
|
||||
"preview-text",
|
||||
"preview-paragraph",
|
||||
"a2",
|
||||
[728.0, 116.0, 240.0, 40.0],
|
||||
"Frame preview heading",
|
||||
2_001,
|
||||
)
|
||||
.unwrap();
|
||||
entry
|
||||
.session
|
||||
.set_block_rotate("preview-text", -12.0, 2_002)
|
||||
.unwrap();
|
||||
entry
|
||||
.session
|
||||
.set_block_prop(
|
||||
"preview-text",
|
||||
"prop:scale",
|
||||
y_octo::SessionValue::Any(y_octo::Any::Float64(1.4.into())),
|
||||
2_003,
|
||||
)
|
||||
.unwrap();
|
||||
entry.snapshot = entry.session.read_page_snapshot().unwrap();
|
||||
entry.revision = entry.session.revision();
|
||||
|
||||
let test = FramePanelTest::open(state, 1280);
|
||||
let crop = |id: &str| {
|
||||
test.inspect(|_, window, _| {
|
||||
let key = format!("desktop.inspector.frame.item.{id}");
|
||||
let card = window.frame_snapshot().elements[&key].bounds;
|
||||
let shot = window.render_to_image().unwrap();
|
||||
if id == "text-preview"
|
||||
&& let Some(dir) = std::env::var_os("FRAME25C_R2_EVIDENCE")
|
||||
{
|
||||
let filename = format!("{name}-edgeless-text.png");
|
||||
let path = std::path::Path::new(&dir).join(filename);
|
||||
if !path.exists() {
|
||||
shot.save(path).unwrap();
|
||||
}
|
||||
}
|
||||
crop_imm(&shot, card.x as u32 + 4, card.y as u32 + 32, 276, 160).to_image()
|
||||
})
|
||||
};
|
||||
let empty = crop("empty-preview");
|
||||
let before = crop("text-preview");
|
||||
|
||||
let revision = test.inspect(|shell, _, cx| {
|
||||
let revision = shell.state.store.docs[TEXT_DOC].revision;
|
||||
let editor = shell
|
||||
.editor_host()
|
||||
.pane_entity(shell.state.split.active().id)
|
||||
.unwrap();
|
||||
editor.update(cx, |view, cx| {
|
||||
view.edit_document(cx, |doc| {
|
||||
doc.workspace
|
||||
.page_mut(TEXT_DOC)
|
||||
.unwrap()
|
||||
.insert_text("preview-paragraph", "prop:text", 0, "Updated: ", 2_004)
|
||||
.unwrap();
|
||||
});
|
||||
});
|
||||
revision
|
||||
});
|
||||
test.frame();
|
||||
test.inspect(|shell, _, _| {
|
||||
assert_ne!(shell.state.store.docs[TEXT_DOC].revision, revision);
|
||||
});
|
||||
let edited = crop("text-preview");
|
||||
let changed_pixels = |a: &RgbaImage, b: &RgbaImage| {
|
||||
a.pixels().zip(b.pixels()).filter(|(a, b)| a != b).count()
|
||||
};
|
||||
counts.push((
|
||||
theme,
|
||||
changed_pixels(&empty, &before),
|
||||
changed_pixels(&before, &edited),
|
||||
));
|
||||
}
|
||||
for (theme, initial, edited) in counts {
|
||||
assert!(
|
||||
initial > 100,
|
||||
"{theme:?}: {initial} pixels differ from an empty frame"
|
||||
);
|
||||
assert!(
|
||||
edited > 100,
|
||||
"{theme:?}: {edited} pixels changed after editing"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frame_panel_thumbnails_match_canvas_order_for_overlapping_note_text_and_shape() {
|
||||
use blocksuite_playground_doc::schema::SurfaceElementSpec;
|
||||
use y_octo::{Any, SessionValue};
|
||||
|
||||
const CARD: &str = "desktop.inspector.frame.item.layer-frame";
|
||||
let [note_front, items_front] =
|
||||
[("note-front", "a0"), ("text-front", "a2")].map(|(name, index)| {
|
||||
let mut state = DesktopAppState::seed_showcase(ThemeMode::Light, "2026-12-02");
|
||||
state.open_doc_in_active_pane("doc-board");
|
||||
state.split.active_mut().set_mode(DocViewMode::Page);
|
||||
state.inspector_tab = Some(DocInspectorTab::Frame);
|
||||
let entry = state.store.docs.get_mut("doc-board").unwrap();
|
||||
let root = entry.snapshot.root.as_ref().unwrap().id.clone();
|
||||
let page = &mut entry.session;
|
||||
page.add_block(
|
||||
"layer-frame",
|
||||
BlockSpec::Frame {
|
||||
title: "Layer order".into(),
|
||||
xywh: Some("[3000,3000,420,230]".into()),
|
||||
presentation_index: Some("Zz".into()),
|
||||
},
|
||||
Some("surface-board"),
|
||||
None,
|
||||
400,
|
||||
)
|
||||
.unwrap();
|
||||
page.add_edgeless_note(
|
||||
&root,
|
||||
"layer-note",
|
||||
"layer-note-body",
|
||||
"a1",
|
||||
[3020.0, 3020.0, 380.0, 175.0],
|
||||
"",
|
||||
401,
|
||||
)
|
||||
.unwrap();
|
||||
page.add_surface_element(
|
||||
"surface-board",
|
||||
"layer-shape",
|
||||
index,
|
||||
SurfaceElementSpec::Shape {
|
||||
shape_type: "rect".into(),
|
||||
xywh: "[3060,3050,180,40]".into(),
|
||||
filled: true,
|
||||
seed: 42,
|
||||
text: None,
|
||||
},
|
||||
402,
|
||||
)
|
||||
.unwrap();
|
||||
page.set_surface_element_field(
|
||||
"surface-board",
|
||||
"layer-shape",
|
||||
"fillColor",
|
||||
SessionValue::Any(Any::String("#38bdf8".into())),
|
||||
403,
|
||||
)
|
||||
.unwrap();
|
||||
page.add_edgeless_text(
|
||||
Some("surface-board"),
|
||||
"layer-text",
|
||||
"layer-text-body",
|
||||
index,
|
||||
[3050.0, 3110.0, 280.0, 50.0],
|
||||
"Frame preview heading",
|
||||
404,
|
||||
)
|
||||
.unwrap();
|
||||
entry.revision = page.revision();
|
||||
entry.snapshot = page.read_page_snapshot().unwrap();
|
||||
|
||||
let test = FramePanelTest::open(state, 1280);
|
||||
test.click(CARD);
|
||||
test.inspect(|shell, window, cx| {
|
||||
let editor = shell
|
||||
.editor_host()
|
||||
.pane_entity(shell.state.split.active().id)
|
||||
.unwrap();
|
||||
let editor = editor.read(cx);
|
||||
assert!(editor.edgeless_selection().contains("layer-frame"));
|
||||
let (origin, _) = editor.canvas_rect(window);
|
||||
let camera = editor.edgeless_camera();
|
||||
let card = window.frame_snapshot().elements[CARD].bounds;
|
||||
let shot = window.render_to_image().unwrap();
|
||||
if let Some(dir) = std::env::var_os("FRAME25C_R3_EVIDENCE") {
|
||||
shot.save(std::path::Path::new(&dir).join(format!("{name}.png")))
|
||||
.unwrap();
|
||||
}
|
||||
[(3045.0, 65), (3100.0, 102)].map(|(y, row)| {
|
||||
let a = camera.world_to_screen(point(px(3045.0), px(y)), origin);
|
||||
let b = camera.world_to_screen(point(px(3340.0), px(y + 55.0)), origin);
|
||||
let canvas = crop_imm(
|
||||
&shot,
|
||||
f32::from(a.x) as u32,
|
||||
f32::from(a.y) as u32,
|
||||
f32::from(b.x - a.x) as u32,
|
||||
f32::from(b.y - a.y) as u32,
|
||||
)
|
||||
.to_image();
|
||||
let thumbnail =
|
||||
crop_imm(&shot, card.x as u32 + 20, card.y as u32 + row, 225, 37)
|
||||
.to_image();
|
||||
(canvas, thumbnail)
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
for (name, ((canvas_before, thumb_before), (canvas_after, thumb_after))) in
|
||||
["shape", "text"]
|
||||
.into_iter()
|
||||
.zip(note_front.into_iter().zip(items_front))
|
||||
{
|
||||
for (view, before, after) in [
|
||||
("canvas", canvas_before, canvas_after),
|
||||
("thumbnail", thumb_before, thumb_after),
|
||||
] {
|
||||
let changed = before
|
||||
.pixels()
|
||||
.zip(after.pixels())
|
||||
.filter(|(a, b)| a != b)
|
||||
.count();
|
||||
assert!(
|
||||
changed > 100,
|
||||
"{name}: only {changed} pixels changed in {view}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frame_panel_presentation_fits_the_current_slide_on_first_fullscreen_frame() {
|
||||
let slides = [
|
||||
("1 / 2", WorldRect::new(0.0, 40.0, 520.0, 340.0)),
|
||||
("2 / 2", WorldRect::new(580.0, 55.0, 300.0, 335.0)),
|
||||
];
|
||||
for index in [1, 0] {
|
||||
let mut state = DesktopAppState::seed_showcase(ThemeMode::Light, "2026-12-02");
|
||||
state.open_doc_in_active_pane("doc-board");
|
||||
state.split.active_mut().set_mode(DocViewMode::Page);
|
||||
state.inspector_tab = Some(DocInspectorTab::Frame);
|
||||
let test = FramePanelTest::open(state, 1280);
|
||||
if index == 1 {
|
||||
test.click(FRAME_WORKBENCH);
|
||||
}
|
||||
test.click(PRESENT);
|
||||
test.frame();
|
||||
if index == 1
|
||||
&& let Some(dir) = std::env::var_os("FRAME25C_R2_EVIDENCE")
|
||||
{
|
||||
test.inspect(|_, window, _| {
|
||||
window
|
||||
.render_to_image()
|
||||
.unwrap()
|
||||
.save(std::path::Path::new(&dir).join("first-fullscreen.png"))
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
let stage = |(progress, frame)| {
|
||||
test.inspect(|shell, window, cx| {
|
||||
let snapshot = window.frame_snapshot();
|
||||
assert_eq!(
|
||||
snapshot.elements["chrome.edgeless_toolbar.presentation.current"]
|
||||
.text
|
||||
.as_deref(),
|
||||
Some(progress)
|
||||
);
|
||||
let editor = shell
|
||||
.editor_host()
|
||||
.pane_entity(shell.state.split.active().id)
|
||||
.unwrap();
|
||||
let editor = editor.read(cx);
|
||||
let (origin, viewport) = editor.canvas_rect(window);
|
||||
assert_eq!(origin, point(px(0.0), px(0.0)));
|
||||
assert_eq!(viewport, size(px(1280.0), px(800.0)));
|
||||
let actual = editor.edgeless_camera();
|
||||
let expected = NavigatorMode::Fit.camera(frame, viewport).unwrap();
|
||||
for (a, b) in [
|
||||
(actual.pan_x, expected.pan_x),
|
||||
(actual.pan_y, expected.pan_y),
|
||||
(actual.zoom, expected.zoom),
|
||||
] {
|
||||
assert!(
|
||||
(a - b).abs() < 0.01,
|
||||
"{progress}: {actual:?} != {expected:?}"
|
||||
);
|
||||
}
|
||||
let image = window.render_to_image().unwrap();
|
||||
(actual, crop_imm(&image, 180, 100, 920, 540).to_image())
|
||||
})
|
||||
};
|
||||
let initial = stage(slides[index]);
|
||||
let step = |key| {
|
||||
test.app.update(|cx| {
|
||||
ui::AnyWindowHandle::from(test.handle)
|
||||
.update(cx, |_, window, cx| {
|
||||
window.dispatch_keystroke(ui::Keystroke::parse(key).unwrap(), cx);
|
||||
})
|
||||
.unwrap();
|
||||
});
|
||||
test.frame();
|
||||
};
|
||||
let (away, back) = if index == 1 {
|
||||
("left", "right")
|
||||
} else {
|
||||
("right", "left")
|
||||
};
|
||||
step(away);
|
||||
stage(slides[1 - index]);
|
||||
step(back);
|
||||
let returned = stage(slides[index]);
|
||||
for (a, b) in [
|
||||
(initial.0.pan_x, returned.0.pan_x),
|
||||
(initial.0.pan_y, returned.0.pan_y),
|
||||
(initial.0.zoom, returned.0.zoom),
|
||||
] {
|
||||
assert!((a - b).abs() < 0.01);
|
||||
}
|
||||
assert_eq!(initial.1.as_raw(), returned.1.as_raw());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user