mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-12-05 11:15:01 +03:00
fix(edgeless): correct the selection toolbar and color picker
Hide the toolbar during canvas pans. Keep More visible on narrow viewports and add Lock to its menu. Show shared actions for mixed selections. Use the text color glyph for EdgelessText and show the standard color grid.
This commit is contained in:
1 parent
38b9e02f9e
commit
7515eebd76
12 files changed
+1312
-1218
No files matched your search
@@ -1,15 +1,15 @@
|
||||
//! Per-type button group builders for `chrome.edgeless_element_toolbar`.
|
||||
|
||||
use blocksuite_playground_doc::read::{ConnectorMode, StrokeStyle};
|
||||
use ui::{BorderStyle, Bounds, Context, Corners, Edges, Hsla, point, prelude::*, px, size};
|
||||
use ui::{BorderStyle, Bounds, Context, Corners, Edges, Hsla, point, px, size};
|
||||
|
||||
use crate::{block_flow::FlowRect, theme::Palette};
|
||||
use crate::theme::Palette;
|
||||
|
||||
use super::{
|
||||
EdgelessElementAction, EdgelessElementToolbarHost, ElementColorSlot, ElementSubMenu,
|
||||
ElementToolbarSummary, ShapePreset,
|
||||
media_toolbar::append_media_toolbar_items,
|
||||
render::ToolbarFlowCursor,
|
||||
render::ToolbarRow,
|
||||
typography::font_trigger_widths,
|
||||
widgets::{
|
||||
BTN_SIZE, align_action_btn, icon_action_btn, stroke_style_btn, swatch_btn, text_action_btn,
|
||||
@@ -45,7 +45,7 @@ fn connector_mode_icon(mode: ConnectorMode) -> &'static str {
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) fn append_per_type_items<V: EdgelessElementToolbarHost>(
|
||||
mut bar: ui::Div,
|
||||
row: &mut ToolbarRow,
|
||||
summary: &ElementToolbarSummary,
|
||||
open_color_picker: Option<ElementColorSlot>,
|
||||
open_sub: Option<ElementSubMenu>,
|
||||
@@ -53,18 +53,13 @@ pub(super) fn append_per_type_items<V: EdgelessElementToolbarHost>(
|
||||
palette: &Palette,
|
||||
panel_bg: Hsla,
|
||||
border_col: Hsla,
|
||||
cursor: &mut ToolbarFlowCursor,
|
||||
sub_triggers: &mut Vec<(ElementSubMenu, FlowRect)>,
|
||||
color_triggers: &mut Vec<(ElementColorSlot, FlowRect)>,
|
||||
cx: &mut Context<V>,
|
||||
) -> ui::Div {
|
||||
) {
|
||||
let show_tooltips = open_sub.is_none() && open_color_picker.is_none();
|
||||
if summary.has_frame_actions {
|
||||
cursor.place(54.0);
|
||||
cursor.place(64.0);
|
||||
cursor.place(58.0);
|
||||
bar = bar
|
||||
.child(text_action_btn(
|
||||
row.push(
|
||||
54.0,
|
||||
text_action_btn(
|
||||
"el-tb-rename",
|
||||
"chrome.edgeless_element_toolbar.rename",
|
||||
"Rename",
|
||||
@@ -75,8 +70,11 @@ pub(super) fn append_per_type_items<V: EdgelessElementToolbarHost>(
|
||||
palette,
|
||||
EdgelessElementAction::Rename,
|
||||
cx,
|
||||
))
|
||||
.child(text_action_btn(
|
||||
),
|
||||
);
|
||||
row.push(
|
||||
64.0,
|
||||
text_action_btn(
|
||||
"el-tb-insert-page",
|
||||
"chrome.edgeless_element_toolbar.insert_page",
|
||||
"To Page",
|
||||
@@ -87,25 +85,27 @@ pub(super) fn append_per_type_items<V: EdgelessElementToolbarHost>(
|
||||
palette,
|
||||
EdgelessElementAction::InsertFrameIntoPage,
|
||||
cx,
|
||||
))
|
||||
.child(text_action_btn(
|
||||
),
|
||||
);
|
||||
row.push(
|
||||
76.0,
|
||||
text_action_btn(
|
||||
"el-tb-ungroup",
|
||||
"chrome.edgeless_element_toolbar.ungroup",
|
||||
"Ungroup",
|
||||
58.0,
|
||||
76.0,
|
||||
false,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::Ungroup,
|
||||
cx,
|
||||
));
|
||||
),
|
||||
);
|
||||
} else if summary.has_group_actions {
|
||||
cursor.place(64.0);
|
||||
cursor.place(54.0);
|
||||
cursor.place(58.0);
|
||||
bar = bar
|
||||
.child(text_action_btn(
|
||||
row.push(
|
||||
64.0,
|
||||
text_action_btn(
|
||||
"el-tb-insert-group-page",
|
||||
"chrome.edgeless_element_toolbar.insert_page",
|
||||
"To Page",
|
||||
@@ -116,8 +116,11 @@ pub(super) fn append_per_type_items<V: EdgelessElementToolbarHost>(
|
||||
palette,
|
||||
EdgelessElementAction::InsertGroupIntoPage,
|
||||
cx,
|
||||
))
|
||||
.child(text_action_btn(
|
||||
),
|
||||
);
|
||||
row.push(
|
||||
54.0,
|
||||
text_action_btn(
|
||||
"el-tb-rename",
|
||||
"chrome.edgeless_element_toolbar.rename",
|
||||
"Rename",
|
||||
@@ -128,258 +131,297 @@ pub(super) fn append_per_type_items<V: EdgelessElementToolbarHost>(
|
||||
palette,
|
||||
EdgelessElementAction::Rename,
|
||||
cx,
|
||||
))
|
||||
.child(text_action_btn(
|
||||
),
|
||||
);
|
||||
row.push(
|
||||
76.0,
|
||||
text_action_btn(
|
||||
"el-tb-ungroup",
|
||||
"chrome.edgeless_element_toolbar.ungroup",
|
||||
"Ungroup",
|
||||
58.0,
|
||||
76.0,
|
||||
false,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::Ungroup,
|
||||
cx,
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(mm) = &summary.mindmap {
|
||||
sub_triggers.push((ElementSubMenu::MindmapStyle, cursor.place(62.0)));
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-mm-style",
|
||||
"chrome.edgeless_element_toolbar.mindmap_style",
|
||||
format!("Style {}", mm.style as u8),
|
||||
row.submenu(
|
||||
ElementSubMenu::MindmapStyle,
|
||||
62.0,
|
||||
open_sub == Some(ElementSubMenu::MindmapStyle),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::MindmapStyle),
|
||||
cx,
|
||||
));
|
||||
sub_triggers.push((ElementSubMenu::MindmapLayout, cursor.place(62.0)));
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-mm-layout",
|
||||
"chrome.edgeless_element_toolbar.mindmap_layout",
|
||||
"Layout",
|
||||
62.0,
|
||||
open_sub == Some(ElementSubMenu::MindmapLayout),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::MindmapLayout),
|
||||
cx,
|
||||
));
|
||||
if mm.has_children {
|
||||
cursor.place(54.0);
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-mm-fold",
|
||||
"chrome.edgeless_element_toolbar.mindmap_collapse",
|
||||
if mm.collapsed { "Expand" } else { "Fold" },
|
||||
54.0,
|
||||
mm.collapsed,
|
||||
false,
|
||||
text_action_btn(
|
||||
"el-tb-mm-style",
|
||||
"chrome.edgeless_element_toolbar.mindmap_style",
|
||||
format!("Style {}", mm.style as u8),
|
||||
62.0,
|
||||
open_sub == Some(ElementSubMenu::MindmapStyle),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleMindmapCollapse,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::MindmapStyle),
|
||||
cx,
|
||||
));
|
||||
),
|
||||
);
|
||||
row.submenu(
|
||||
ElementSubMenu::MindmapLayout,
|
||||
62.0,
|
||||
text_action_btn(
|
||||
"el-tb-mm-layout",
|
||||
"chrome.edgeless_element_toolbar.mindmap_layout",
|
||||
"Layout",
|
||||
62.0,
|
||||
open_sub == Some(ElementSubMenu::MindmapLayout),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::MindmapLayout),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
if mm.has_children {
|
||||
row.push(
|
||||
54.0,
|
||||
text_action_btn(
|
||||
"el-tb-mm-fold",
|
||||
"chrome.edgeless_element_toolbar.mindmap_collapse",
|
||||
if mm.collapsed { "Expand" } else { "Fold" },
|
||||
54.0,
|
||||
mm.collapsed,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleMindmapCollapse,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(sb) = &summary.surface_block {
|
||||
bar = append_media_toolbar_items(
|
||||
bar,
|
||||
sb,
|
||||
open_sub,
|
||||
show_tooltips,
|
||||
palette,
|
||||
cursor,
|
||||
sub_triggers,
|
||||
cx,
|
||||
);
|
||||
append_media_toolbar_items(row, sb, open_sub, show_tooltips, palette, cx);
|
||||
}
|
||||
|
||||
if summary.has_shape_type {
|
||||
sub_triggers.push((ElementSubMenu::ShapeType, cursor.place(BTN_SIZE)));
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-shape-type",
|
||||
"chrome.edgeless_element_toolbar.shape_type",
|
||||
"Switch shape",
|
||||
shape_preset_icon(summary.shape_preset),
|
||||
open_sub == Some(ElementSubMenu::ShapeType),
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::ShapeType),
|
||||
cx,
|
||||
));
|
||||
row.submenu(
|
||||
ElementSubMenu::ShapeType,
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-shape-type",
|
||||
"chrome.edgeless_element_toolbar.shape_type",
|
||||
"Switch shape",
|
||||
shape_preset_icon(summary.shape_preset),
|
||||
open_sub == Some(ElementSubMenu::ShapeType),
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::ShapeType),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if summary.has_fill {
|
||||
color_triggers.push((ElementColorSlot::Fill, cursor.place(BTN_SIZE)));
|
||||
let active = open_color_picker == Some(ElementColorSlot::Fill);
|
||||
let fill = summary.fill_color;
|
||||
bar = bar.child(swatch_btn(
|
||||
"el-tb-fill",
|
||||
"chrome.edgeless_element_toolbar.fill",
|
||||
"Fill color",
|
||||
active,
|
||||
show_tooltips,
|
||||
palette,
|
||||
row.color(
|
||||
ElementColorSlot::Fill,
|
||||
move |bounds, window| {
|
||||
let inset = 3.0;
|
||||
let side = (f32::from(bounds.size.width) - 2.0 * inset).max(10.0);
|
||||
window.paint_quad(ui::quad(
|
||||
Bounds::new(
|
||||
point(bounds.origin.x + px(inset), bounds.origin.y + px(inset)),
|
||||
size(px(side), px(side)),
|
||||
),
|
||||
Corners::all(px(side * 0.5)),
|
||||
fill,
|
||||
Edges::all(px(0.5)),
|
||||
border_col,
|
||||
BorderStyle::Solid,
|
||||
));
|
||||
},
|
||||
cx,
|
||||
));
|
||||
BTN_SIZE,
|
||||
swatch_btn(
|
||||
"el-tb-fill",
|
||||
"chrome.edgeless_element_toolbar.fill",
|
||||
"Fill color",
|
||||
active,
|
||||
show_tooltips,
|
||||
palette,
|
||||
ElementColorSlot::Fill,
|
||||
move |bounds, window| {
|
||||
let inset = 3.0;
|
||||
let side = (f32::from(bounds.size.width) - 2.0 * inset).max(10.0);
|
||||
window.paint_quad(ui::quad(
|
||||
Bounds::new(
|
||||
point(bounds.origin.x + px(inset), bounds.origin.y + px(inset)),
|
||||
size(px(side), px(side)),
|
||||
),
|
||||
Corners::all(px(side * 0.5)),
|
||||
fill,
|
||||
Edges::all(px(0.5)),
|
||||
border_col,
|
||||
BorderStyle::Solid,
|
||||
));
|
||||
},
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if summary.has_stroke {
|
||||
color_triggers.push((ElementColorSlot::Stroke, cursor.place(BTN_SIZE)));
|
||||
let active = open_color_picker == Some(ElementColorSlot::Stroke);
|
||||
let stroke = summary.stroke_color;
|
||||
bar = bar.child(swatch_btn(
|
||||
"el-tb-stroke",
|
||||
"chrome.edgeless_element_toolbar.stroke",
|
||||
"Border color",
|
||||
active,
|
||||
show_tooltips,
|
||||
palette,
|
||||
ElementColorSlot::Stroke,
|
||||
move |bounds, window| {
|
||||
let inset = 3.0;
|
||||
let side = (f32::from(bounds.size.width) - 2.0 * inset).max(10.0);
|
||||
window.paint_quad(ui::quad(
|
||||
Bounds::new(
|
||||
point(bounds.origin.x + px(inset), bounds.origin.y + px(inset)),
|
||||
size(px(side), px(side)),
|
||||
),
|
||||
Corners::all(px(side * 0.5)),
|
||||
panel_bg,
|
||||
Edges::all(px(2.5)),
|
||||
stroke,
|
||||
BorderStyle::Solid,
|
||||
));
|
||||
},
|
||||
cx,
|
||||
));
|
||||
let button = if summary.stroke_is_text {
|
||||
text_color_btn(
|
||||
ElementColorSlot::Stroke,
|
||||
active,
|
||||
stroke,
|
||||
show_tooltips,
|
||||
palette,
|
||||
cx,
|
||||
)
|
||||
} else {
|
||||
swatch_btn(
|
||||
"el-tb-stroke",
|
||||
"chrome.edgeless_element_toolbar.stroke",
|
||||
"Border color",
|
||||
active,
|
||||
show_tooltips,
|
||||
palette,
|
||||
ElementColorSlot::Stroke,
|
||||
move |bounds, window| {
|
||||
let inset = 3.0;
|
||||
let side = (f32::from(bounds.size.width) - 2.0 * inset).max(10.0);
|
||||
window.paint_quad(ui::quad(
|
||||
Bounds::new(
|
||||
point(bounds.origin.x + px(inset), bounds.origin.y + px(inset)),
|
||||
size(px(side), px(side)),
|
||||
),
|
||||
Corners::all(px(side * 0.5)),
|
||||
panel_bg,
|
||||
Edges::all(px(2.5)),
|
||||
stroke,
|
||||
BorderStyle::Solid,
|
||||
));
|
||||
},
|
||||
cx,
|
||||
)
|
||||
};
|
||||
row.color(ElementColorSlot::Stroke, BTN_SIZE, button);
|
||||
}
|
||||
|
||||
if summary.has_stroke_style {
|
||||
cursor.place(BTN_SIZE);
|
||||
bar = bar.child(stroke_style_btn(
|
||||
summary.stroke_style,
|
||||
next_stroke_style(summary.stroke_style),
|
||||
show_tooltips,
|
||||
palette,
|
||||
cx,
|
||||
));
|
||||
row.push(
|
||||
BTN_SIZE,
|
||||
stroke_style_btn(
|
||||
summary.stroke_style,
|
||||
next_stroke_style(summary.stroke_style),
|
||||
show_tooltips,
|
||||
palette,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if summary.has_stroke_width {
|
||||
sub_triggers.push((ElementSubMenu::LineWidth, cursor.place(44.0)));
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-stroke-width",
|
||||
"chrome.edgeless_element_toolbar.stroke_width",
|
||||
format!("{}px", summary.stroke_width.round() as i32),
|
||||
row.submenu(
|
||||
ElementSubMenu::LineWidth,
|
||||
44.0,
|
||||
open_sub == Some(ElementSubMenu::LineWidth),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::LineWidth),
|
||||
cx,
|
||||
));
|
||||
text_action_btn(
|
||||
"el-tb-stroke-width",
|
||||
"chrome.edgeless_element_toolbar.stroke_width",
|
||||
format!("{}px", summary.stroke_width.round() as i32),
|
||||
44.0,
|
||||
open_sub == Some(ElementSubMenu::LineWidth),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::LineWidth),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if summary.has_rough_style {
|
||||
cursor.place(BTN_SIZE);
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-rough",
|
||||
"chrome.edgeless_element_toolbar.rough_style",
|
||||
if summary.scribbled {
|
||||
"Scribbled"
|
||||
} else {
|
||||
"General"
|
||||
},
|
||||
if summary.scribbled {
|
||||
"PenIcon"
|
||||
} else {
|
||||
"SquareIcon"
|
||||
},
|
||||
summary.scribbled,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleRoughStyle,
|
||||
cx,
|
||||
));
|
||||
row.push(
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-rough",
|
||||
"chrome.edgeless_element_toolbar.rough_style",
|
||||
if summary.scribbled {
|
||||
"Scribbled"
|
||||
} else {
|
||||
"General"
|
||||
},
|
||||
if summary.scribbled {
|
||||
"PenIcon"
|
||||
} else {
|
||||
"SquareIcon"
|
||||
},
|
||||
summary.scribbled,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleRoughStyle,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if summary.has_connector_props {
|
||||
sub_triggers.push((ElementSubMenu::ConnectorMode, cursor.place(BTN_SIZE)));
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-conn-mode",
|
||||
"chrome.edgeless_element_toolbar.connector_mode",
|
||||
"Connector shape",
|
||||
connector_mode_icon(summary.connector_mode),
|
||||
open_sub == Some(ElementSubMenu::ConnectorMode),
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::ConnectorMode),
|
||||
cx,
|
||||
));
|
||||
row.submenu(
|
||||
ElementSubMenu::ConnectorMode,
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-conn-mode",
|
||||
"chrome.edgeless_element_toolbar.connector_mode",
|
||||
"Connector shape",
|
||||
connector_mode_icon(summary.connector_mode),
|
||||
open_sub == Some(ElementSubMenu::ConnectorMode),
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::ConnectorMode),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
sub_triggers.push((ElementSubMenu::ConnectorCaps, cursor.place(48.0)));
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-conn-caps",
|
||||
"chrome.edgeless_element_toolbar.connector_caps",
|
||||
"Caps",
|
||||
row.submenu(
|
||||
ElementSubMenu::ConnectorCaps,
|
||||
48.0,
|
||||
open_sub == Some(ElementSubMenu::ConnectorCaps),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::ConnectorCaps),
|
||||
cx,
|
||||
));
|
||||
text_action_btn(
|
||||
"el-tb-conn-caps",
|
||||
"chrome.edgeless_element_toolbar.connector_caps",
|
||||
"Caps",
|
||||
48.0,
|
||||
open_sub == Some(ElementSubMenu::ConnectorCaps),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::ConnectorCaps),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if summary.can_add_text {
|
||||
cursor.place(BTN_SIZE);
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-add-text",
|
||||
"chrome.edgeless_element_toolbar.add_text",
|
||||
"Add text",
|
||||
"AddTextIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::AddText,
|
||||
cx,
|
||||
));
|
||||
row.push(
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-add-text",
|
||||
"chrome.edgeless_element_toolbar.add_text",
|
||||
"Add text",
|
||||
"AddTextIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::AddText,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if summary.has_text_color {
|
||||
color_triggers.push((ElementColorSlot::Text, cursor.place(BTN_SIZE)));
|
||||
bar = bar.child(text_color_btn(
|
||||
open_color_picker == Some(ElementColorSlot::Text),
|
||||
summary.text_color,
|
||||
show_tooltips,
|
||||
palette,
|
||||
cx,
|
||||
));
|
||||
row.color(
|
||||
ElementColorSlot::Text,
|
||||
BTN_SIZE,
|
||||
text_color_btn(
|
||||
ElementColorSlot::Text,
|
||||
open_color_picker == Some(ElementColorSlot::Text),
|
||||
summary.text_color,
|
||||
show_tooltips,
|
||||
palette,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(style) = &summary.typography {
|
||||
@@ -404,95 +446,106 @@ pub(super) fn append_per_type_items<V: EdgelessElementToolbarHost>(
|
||||
] {
|
||||
let action = EdgelessElementAction::ToggleSubMenu(menu);
|
||||
let active = open_sub == Some(menu);
|
||||
sub_triggers.push((menu, cursor.place(width)));
|
||||
bar = bar.child(match (compact, menu) {
|
||||
(true, ElementSubMenu::FontFamily) => icon_action_btn(
|
||||
id,
|
||||
"chrome.edgeless_element_toolbar.font_family",
|
||||
tooltip,
|
||||
icon,
|
||||
active,
|
||||
show_tooltips,
|
||||
palette,
|
||||
action,
|
||||
cx,
|
||||
),
|
||||
(true, _) => icon_action_btn(
|
||||
id,
|
||||
"chrome.edgeless_element_toolbar.font_weight",
|
||||
tooltip,
|
||||
icon,
|
||||
active,
|
||||
show_tooltips,
|
||||
palette,
|
||||
action,
|
||||
cx,
|
||||
),
|
||||
(false, ElementSubMenu::FontFamily) => text_action_btn(
|
||||
id,
|
||||
"chrome.edgeless_element_toolbar.font_family",
|
||||
label,
|
||||
width,
|
||||
active,
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
action,
|
||||
cx,
|
||||
),
|
||||
(false, _) => text_action_btn(
|
||||
id,
|
||||
"chrome.edgeless_element_toolbar.font_weight",
|
||||
label,
|
||||
width,
|
||||
active,
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
action,
|
||||
cx,
|
||||
),
|
||||
});
|
||||
row.submenu(
|
||||
menu,
|
||||
width,
|
||||
match (compact, menu) {
|
||||
(true, ElementSubMenu::FontFamily) => icon_action_btn(
|
||||
id,
|
||||
"chrome.edgeless_element_toolbar.font_family",
|
||||
tooltip,
|
||||
icon,
|
||||
active,
|
||||
show_tooltips,
|
||||
palette,
|
||||
action,
|
||||
cx,
|
||||
),
|
||||
(true, _) => icon_action_btn(
|
||||
id,
|
||||
"chrome.edgeless_element_toolbar.font_weight",
|
||||
tooltip,
|
||||
icon,
|
||||
active,
|
||||
show_tooltips,
|
||||
palette,
|
||||
action,
|
||||
cx,
|
||||
),
|
||||
(false, ElementSubMenu::FontFamily) => text_action_btn(
|
||||
id,
|
||||
"chrome.edgeless_element_toolbar.font_family",
|
||||
label,
|
||||
width,
|
||||
active,
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
action,
|
||||
cx,
|
||||
),
|
||||
(false, _) => text_action_btn(
|
||||
id,
|
||||
"chrome.edgeless_element_toolbar.font_weight",
|
||||
label,
|
||||
width,
|
||||
active,
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
action,
|
||||
cx,
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
cursor.place(BTN_SIZE);
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-italic",
|
||||
"chrome.edgeless_element_toolbar.italic",
|
||||
"Italic",
|
||||
"ItalicIcon",
|
||||
style.italic,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::SetItalic(!style.italic),
|
||||
cx,
|
||||
));
|
||||
row.push(
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-italic",
|
||||
"chrome.edgeless_element_toolbar.italic",
|
||||
"Italic",
|
||||
"ItalicIcon",
|
||||
style.italic,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::SetItalic(!style.italic),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if summary.has_font_size {
|
||||
sub_triggers.push((ElementSubMenu::FontSize, cursor.place(44.0)));
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-font-size",
|
||||
"chrome.edgeless_element_toolbar.font_size",
|
||||
format!("{}px", summary.font_size.round() as i32),
|
||||
row.submenu(
|
||||
ElementSubMenu::FontSize,
|
||||
44.0,
|
||||
open_sub == Some(ElementSubMenu::FontSize),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::FontSize),
|
||||
cx,
|
||||
));
|
||||
text_action_btn(
|
||||
"el-tb-font-size",
|
||||
"chrome.edgeless_element_toolbar.font_size",
|
||||
format!("{}px", summary.font_size.round() as i32),
|
||||
44.0,
|
||||
open_sub == Some(ElementSubMenu::FontSize),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::FontSize),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if summary.has_text_align {
|
||||
sub_triggers.push((ElementSubMenu::TextAlign, cursor.place(BTN_SIZE)));
|
||||
bar = bar.child(align_action_btn(
|
||||
summary.text_align,
|
||||
open_sub == Some(ElementSubMenu::TextAlign),
|
||||
show_tooltips,
|
||||
palette,
|
||||
cx,
|
||||
));
|
||||
row.submenu(
|
||||
ElementSubMenu::TextAlign,
|
||||
BTN_SIZE,
|
||||
align_action_btn(
|
||||
summary.text_align,
|
||||
open_sub == Some(ElementSubMenu::TextAlign),
|
||||
show_tooltips,
|
||||
palette,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if summary.has_note_shadow {
|
||||
@@ -500,57 +553,61 @@ pub(super) fn append_per_type_items<V: EdgelessElementToolbarHost>(
|
||||
open_sub,
|
||||
Some(ElementSubMenu::NoteStyle | ElementSubMenu::NoteShadow)
|
||||
);
|
||||
let note_style_rect = cursor.place(56.0);
|
||||
sub_triggers.push((ElementSubMenu::NoteStyle, note_style_rect));
|
||||
sub_triggers.push((ElementSubMenu::NoteShadow, note_style_rect));
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-note-style",
|
||||
"chrome.edgeless_element_toolbar.note_style",
|
||||
"Style",
|
||||
row.submenu(
|
||||
ElementSubMenu::NoteStyle,
|
||||
56.0,
|
||||
style_open,
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::NoteStyle),
|
||||
cx,
|
||||
));
|
||||
text_action_btn(
|
||||
"el-tb-note-style",
|
||||
"chrome.edgeless_element_toolbar.note_style",
|
||||
"Style",
|
||||
56.0,
|
||||
style_open,
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::NoteStyle),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
sub_triggers.push((ElementSubMenu::NoteScale, cursor.place(54.0)));
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-note-scale",
|
||||
"chrome.edgeless_element_toolbar.note_scale",
|
||||
format!("{}%", (summary.note_scale * 100.0).round() as i32),
|
||||
row.submenu(
|
||||
ElementSubMenu::NoteScale,
|
||||
54.0,
|
||||
open_sub == Some(ElementSubMenu::NoteScale),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::NoteScale),
|
||||
cx,
|
||||
));
|
||||
text_action_btn(
|
||||
"el-tb-note-scale",
|
||||
"chrome.edgeless_element_toolbar.note_scale",
|
||||
format!("{}%", (summary.note_scale * 100.0).round() as i32),
|
||||
54.0,
|
||||
open_sub == Some(ElementSubMenu::NoteScale),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::NoteScale),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if summary.has_note_display {
|
||||
cursor.place(96.0);
|
||||
let label = if summary.note_in_page {
|
||||
"Displayed in Page"
|
||||
} else {
|
||||
"Display in Page"
|
||||
};
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-note-display",
|
||||
"chrome.edgeless_element_toolbar.note_display",
|
||||
label,
|
||||
row.push(
|
||||
96.0,
|
||||
summary.note_in_page,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleNoteDisplayMode,
|
||||
cx,
|
||||
));
|
||||
text_action_btn(
|
||||
"el-tb-note-display",
|
||||
"chrome.edgeless_element_toolbar.note_display",
|
||||
label,
|
||||
96.0,
|
||||
summary.note_in_page,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleNoteDisplayMode,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bar
|
||||
}
|
||||
@@ -15,9 +15,7 @@ use crate::{
|
||||
use super::{
|
||||
EDGELESS_VIEWPORT_ID, EdgelessAuthoringState, EdgelessElementAction,
|
||||
EdgelessElementToolbarHost, ElementColorSlot, ElementToolbarSummary,
|
||||
color_value_matches_swatch, palette_for_slot,
|
||||
palettes::SHAPE_COLOR_ROWS,
|
||||
parse_custom_hex_color,
|
||||
color_value_matches_swatch, palette_for_slot, parse_custom_hex_color,
|
||||
widgets::{isolate_floating_chrome, toolbar_chrome_tokens},
|
||||
};
|
||||
|
||||
@@ -35,31 +33,19 @@ pub(super) fn build_color_picker_pill<V: EdgelessElementToolbarHost>(
|
||||
) -> (AnyElement, FlowRect) {
|
||||
let (panel_bg, border_col, shadows) = toolbar_chrome_tokens(palette, theme);
|
||||
let (swatches, cols) = palette_for_slot(slot, summary.is_note_fill, summary.is_shape_text);
|
||||
let show_shape_strip = summary.has_shape_type
|
||||
&& !summary.is_note_fill
|
||||
&& matches!(slot, ElementColorSlot::Fill | ElementColorSlot::Stroke);
|
||||
let current_val = match slot {
|
||||
ElementColorSlot::Fill => &summary.fill_color_value,
|
||||
ElementColorSlot::Stroke => &summary.stroke_color_value,
|
||||
ElementColorSlot::Text => &summary.text_color_value,
|
||||
};
|
||||
|
||||
let (cell, gap) = if show_shape_strip {
|
||||
(24.0, 2.0)
|
||||
} else {
|
||||
(26.0, 4.0)
|
||||
};
|
||||
let (cell, gap) = (24.0, 4.0);
|
||||
const PAD: f32 = 8.0;
|
||||
const CUSTOM_ROW_H: f32 = 26.0;
|
||||
const CUSTOM_ROW_GAP: f32 = 8.0;
|
||||
|
||||
let color_rows: Vec<&[super::PaletteSwatch]> = if show_shape_strip {
|
||||
SHAPE_COLOR_ROWS.to_vec()
|
||||
} else {
|
||||
swatches.chunks(cols).collect()
|
||||
};
|
||||
let rows = color_rows.len();
|
||||
let cols = color_rows.iter().map(|row| row.len()).max().unwrap_or(0);
|
||||
let rows = swatches.len().div_ceil(cols);
|
||||
let cols = cols.min(swatches.len());
|
||||
let grid_w = cols as f32 * cell + cols.saturating_sub(1) as f32 * gap;
|
||||
let grid_h = rows as f32 * cell + rows.saturating_sub(1) as f32 * gap;
|
||||
let sub_w = (grid_w + 2.0 * PAD + 2.0).max(176.0);
|
||||
@@ -107,7 +93,7 @@ pub(super) fn build_color_picker_pill<V: EdgelessElementToolbarHost>(
|
||||
);
|
||||
|
||||
let mut grid = div().flex().flex_col().gap(px(gap));
|
||||
for row_chunk in color_rows {
|
||||
for row_chunk in swatches.chunks(cols) {
|
||||
let mut row = div().flex().items_center().gap(px(gap));
|
||||
for &swatch in row_chunk {
|
||||
let color = swatch.resolve_hsla(theme);
|
||||
@@ -116,16 +102,12 @@ pub(super) fn build_color_picker_pill<V: EdgelessElementToolbarHost>(
|
||||
let selected = color_value_matches_swatch(current_val, swatch, theme, ignore_alpha);
|
||||
let wire_val = swatch.to_color_value();
|
||||
let el_id = SharedString::from(format!("el-tb-swatch-{slot_tag}-{}", swatch.key));
|
||||
let swatch_bg = if is_transparent {
|
||||
ui::Rgba {
|
||||
r: 1.0,
|
||||
g: 1.0,
|
||||
b: 1.0,
|
||||
a: 1.0,
|
||||
}
|
||||
.into()
|
||||
let swatch_bg = if is_transparent { panel_bg } else { color };
|
||||
let dark_swatch = theme == PlaygroundTheme::Dark && color.l < 0.3;
|
||||
let stroke = if dark_swatch {
|
||||
palette.text_secondary
|
||||
} else {
|
||||
color
|
||||
border_col
|
||||
};
|
||||
row = row.child(
|
||||
div()
|
||||
@@ -187,21 +169,16 @@ pub(super) fn build_color_picker_pill<V: EdgelessElementToolbarHost>(
|
||||
),
|
||||
Corners::all(px(dot * 0.5)),
|
||||
swatch_bg,
|
||||
Edges::all(px(0.5)),
|
||||
border_col,
|
||||
Edges::all(px(if dark_swatch { 1.0 } else { 0.5 })),
|
||||
stroke,
|
||||
BorderStyle::Solid,
|
||||
));
|
||||
if is_transparent {
|
||||
// Diagonal red slash across the transparent swatch circle.
|
||||
for step in -4..=4 {
|
||||
let off = step as f32 * 1.1;
|
||||
window.paint_quad(ui::fill(
|
||||
Bounds::new(
|
||||
point(px(cx_b + off - 0.75), px(cy_b - off - 0.75)),
|
||||
size(px(1.5), px(1.5)),
|
||||
),
|
||||
slash_col,
|
||||
));
|
||||
let mut slash = ui::PathBuilder::stroke(px(1.25));
|
||||
slash.move_to(point(px(cx_b - 5.0), px(cy_b + 5.0)));
|
||||
slash.line_to(point(px(cx_b + 5.0), px(cy_b - 5.0)));
|
||||
if let Ok(path) = slash.build() {
|
||||
window.paint_path(path, slash_col);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::{
|
||||
use super::{
|
||||
EDGELESS_VIEWPORT_ID, EdgelessElementAction, EdgelessElementToolbarHost, ElementSubMenu,
|
||||
SurfaceBlockKind, SurfaceBlockToolbarSummary, prop_f32,
|
||||
render::ToolbarFlowCursor,
|
||||
render::ToolbarRow,
|
||||
widgets::{
|
||||
BTN_SIZE, icon_action_btn, isolate_floating_chrome, text_action_btn, toolbar_chrome_tokens,
|
||||
},
|
||||
@@ -114,206 +114,89 @@ pub(super) fn summarize_surface_block(
|
||||
})
|
||||
}
|
||||
|
||||
/// Estimated widths for each button pushed by `append_media_toolbar_items`.
|
||||
pub(super) fn media_toolbar_item_widths(sb: &SurfaceBlockToolbarSummary) -> Vec<f32> {
|
||||
match sb.kind {
|
||||
SurfaceBlockKind::Image => {
|
||||
let mut w = vec![56.0, BTN_SIZE, 54.0];
|
||||
if sb.can_download {
|
||||
w.push(BTN_SIZE);
|
||||
}
|
||||
w
|
||||
}
|
||||
SurfaceBlockKind::Attachment => {
|
||||
let mut w = vec![68.0, 62.0, 56.0];
|
||||
if sb.can_download {
|
||||
w.push(BTN_SIZE);
|
||||
}
|
||||
w
|
||||
}
|
||||
SurfaceBlockKind::Bookmark => {
|
||||
let mut w = vec![64.0, BTN_SIZE];
|
||||
if sb.can_toggle_view {
|
||||
w.push(68.0);
|
||||
}
|
||||
w.extend([62.0, 56.0]);
|
||||
w
|
||||
}
|
||||
SurfaceBlockKind::EmbedLinkedDoc
|
||||
| SurfaceBlockKind::EmbedSyncedDoc
|
||||
| SurfaceBlockKind::ExternalEmbed => vec![58.0, BTN_SIZE, 68.0, 56.0],
|
||||
}
|
||||
}
|
||||
|
||||
/// Append dedicated media/embed controls to the Edgeless element toolbar, recording trigger rects
|
||||
/// for any dropdowns (`MediaStyle`, `MediaScale`).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) fn append_media_toolbar_items<V: EdgelessElementToolbarHost>(
|
||||
mut bar: ui::Div,
|
||||
row: &mut ToolbarRow,
|
||||
sb: &SurfaceBlockToolbarSummary,
|
||||
open_sub: Option<ElementSubMenu>,
|
||||
show_tooltips: bool,
|
||||
palette: &Palette,
|
||||
cursor: &mut ToolbarFlowCursor,
|
||||
trigger_rects: &mut Vec<(ElementSubMenu, FlowRect)>,
|
||||
cx: &mut Context<V>,
|
||||
) -> ui::Div {
|
||||
let mut advance = |w: f32, menu: Option<ElementSubMenu>| {
|
||||
let rect = cursor.place(w);
|
||||
if let Some(m) = menu {
|
||||
trigger_rects.push((m, rect));
|
||||
}
|
||||
};
|
||||
|
||||
) {
|
||||
match sb.kind {
|
||||
SurfaceBlockKind::Image => {
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-media-caption",
|
||||
"chrome.edgeless_element_toolbar.media_caption",
|
||||
"Caption",
|
||||
row.push(
|
||||
56.0,
|
||||
!sb.caption.is_empty(),
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaCaption,
|
||||
cx,
|
||||
));
|
||||
advance(56.0, None);
|
||||
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-media-rotate",
|
||||
"chrome.edgeless_element_toolbar.media_rotate",
|
||||
"Rotate 90°",
|
||||
"RedoIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaRotateCw,
|
||||
cx,
|
||||
));
|
||||
advance(BTN_SIZE, None);
|
||||
|
||||
let pct = (sb.scale * 100.0).round() as i32;
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-media-scale",
|
||||
"chrome.edgeless_element_toolbar.media_scale",
|
||||
format!("{pct}%"),
|
||||
54.0,
|
||||
open_sub == Some(ElementSubMenu::MediaScale),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::MediaScale),
|
||||
cx,
|
||||
));
|
||||
advance(54.0, Some(ElementSubMenu::MediaScale));
|
||||
|
||||
if sb.can_download {
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-media-download",
|
||||
"chrome.edgeless_element_toolbar.media_download",
|
||||
"Download",
|
||||
"AttachmentIcon",
|
||||
text_action_btn(
|
||||
"el-tb-media-caption",
|
||||
"chrome.edgeless_element_toolbar.media_caption",
|
||||
"Caption",
|
||||
56.0,
|
||||
!sb.caption.is_empty(),
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaDownload,
|
||||
EdgelessElementAction::MediaCaption,
|
||||
cx,
|
||||
));
|
||||
advance(BTN_SIZE, None);
|
||||
),
|
||||
);
|
||||
|
||||
row.push(
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-media-rotate",
|
||||
"chrome.edgeless_element_toolbar.media_rotate",
|
||||
"Rotate 90°",
|
||||
"RedoIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaRotateCw,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
let pct = (sb.scale * 100.0).round() as i32;
|
||||
row.submenu(
|
||||
ElementSubMenu::MediaScale,
|
||||
54.0,
|
||||
text_action_btn(
|
||||
"el-tb-media-scale",
|
||||
"chrome.edgeless_element_toolbar.media_scale",
|
||||
format!("{pct}%"),
|
||||
54.0,
|
||||
open_sub == Some(ElementSubMenu::MediaScale),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::MediaScale),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
if sb.can_download {
|
||||
row.push(
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-media-download",
|
||||
"chrome.edgeless_element_toolbar.media_download",
|
||||
"Download",
|
||||
"AttachmentIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaDownload,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
SurfaceBlockKind::Attachment => {
|
||||
let view_label = if sb.is_embed_view { "Embed" } else { "Card" };
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-media-view",
|
||||
"chrome.edgeless_element_toolbar.media_view",
|
||||
view_label,
|
||||
row.push(
|
||||
68.0,
|
||||
sb.is_embed_view,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaToggleView,
|
||||
cx,
|
||||
));
|
||||
advance(68.0, None);
|
||||
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-media-style",
|
||||
"chrome.edgeless_element_toolbar.media_style",
|
||||
"Style",
|
||||
62.0,
|
||||
open_sub == Some(ElementSubMenu::MediaStyle),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::MediaStyle),
|
||||
cx,
|
||||
));
|
||||
advance(62.0, Some(ElementSubMenu::MediaStyle));
|
||||
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-media-caption",
|
||||
"chrome.edgeless_element_toolbar.media_caption",
|
||||
"Caption",
|
||||
56.0,
|
||||
!sb.caption.is_empty(),
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaCaption,
|
||||
cx,
|
||||
));
|
||||
advance(56.0, None);
|
||||
|
||||
if sb.can_download {
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-media-download",
|
||||
"chrome.edgeless_element_toolbar.media_download",
|
||||
"Download",
|
||||
"AttachmentIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaDownload,
|
||||
cx,
|
||||
));
|
||||
advance(BTN_SIZE, None);
|
||||
}
|
||||
}
|
||||
SurfaceBlockKind::Bookmark => {
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-media-open",
|
||||
"chrome.edgeless_element_toolbar.media_open",
|
||||
"Open",
|
||||
64.0,
|
||||
false,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaOpenLink,
|
||||
cx,
|
||||
));
|
||||
advance(64.0, None);
|
||||
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-media-copy-link",
|
||||
"chrome.edgeless_element_toolbar.media_copy_link",
|
||||
"Copy link",
|
||||
"LinkIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaCopyLink,
|
||||
cx,
|
||||
));
|
||||
advance(BTN_SIZE, None);
|
||||
|
||||
if sb.can_toggle_view {
|
||||
let view_label = if sb.is_embed_view { "Embed" } else { "Card" };
|
||||
bar = bar.child(text_action_btn(
|
||||
text_action_btn(
|
||||
"el-tb-media-view",
|
||||
"chrome.edgeless_element_toolbar.media_view",
|
||||
view_label,
|
||||
@@ -324,99 +207,211 @@ pub(super) fn append_media_toolbar_items<V: EdgelessElementToolbarHost>(
|
||||
palette,
|
||||
EdgelessElementAction::MediaToggleView,
|
||||
cx,
|
||||
));
|
||||
advance(68.0, None);
|
||||
),
|
||||
);
|
||||
|
||||
row.submenu(
|
||||
ElementSubMenu::MediaStyle,
|
||||
62.0,
|
||||
text_action_btn(
|
||||
"el-tb-media-style",
|
||||
"chrome.edgeless_element_toolbar.media_style",
|
||||
"Style",
|
||||
62.0,
|
||||
open_sub == Some(ElementSubMenu::MediaStyle),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::MediaStyle),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
row.push(
|
||||
56.0,
|
||||
text_action_btn(
|
||||
"el-tb-media-caption",
|
||||
"chrome.edgeless_element_toolbar.media_caption",
|
||||
"Caption",
|
||||
56.0,
|
||||
!sb.caption.is_empty(),
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaCaption,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
if sb.can_download {
|
||||
row.push(
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-media-download",
|
||||
"chrome.edgeless_element_toolbar.media_download",
|
||||
"Download",
|
||||
"AttachmentIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaDownload,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
SurfaceBlockKind::Bookmark => {
|
||||
row.push(
|
||||
64.0,
|
||||
text_action_btn(
|
||||
"el-tb-media-open",
|
||||
"chrome.edgeless_element_toolbar.media_open",
|
||||
"Open",
|
||||
64.0,
|
||||
false,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaOpenLink,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
row.push(
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-media-copy-link",
|
||||
"chrome.edgeless_element_toolbar.media_copy_link",
|
||||
"Copy link",
|
||||
"LinkIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaCopyLink,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
if sb.can_toggle_view {
|
||||
let view_label = if sb.is_embed_view { "Embed" } else { "Card" };
|
||||
row.push(
|
||||
68.0,
|
||||
text_action_btn(
|
||||
"el-tb-media-view",
|
||||
"chrome.edgeless_element_toolbar.media_view",
|
||||
view_label,
|
||||
68.0,
|
||||
sb.is_embed_view,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaToggleView,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-media-style",
|
||||
"chrome.edgeless_element_toolbar.media_style",
|
||||
"Style",
|
||||
row.submenu(
|
||||
ElementSubMenu::MediaStyle,
|
||||
62.0,
|
||||
open_sub == Some(ElementSubMenu::MediaStyle),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::MediaStyle),
|
||||
cx,
|
||||
));
|
||||
advance(62.0, Some(ElementSubMenu::MediaStyle));
|
||||
text_action_btn(
|
||||
"el-tb-media-style",
|
||||
"chrome.edgeless_element_toolbar.media_style",
|
||||
"Style",
|
||||
62.0,
|
||||
open_sub == Some(ElementSubMenu::MediaStyle),
|
||||
true,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::MediaStyle),
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-media-caption",
|
||||
"chrome.edgeless_element_toolbar.media_caption",
|
||||
"Caption",
|
||||
row.push(
|
||||
56.0,
|
||||
!sb.caption.is_empty(),
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaCaption,
|
||||
cx,
|
||||
));
|
||||
advance(56.0, None);
|
||||
text_action_btn(
|
||||
"el-tb-media-caption",
|
||||
"chrome.edgeless_element_toolbar.media_caption",
|
||||
"Caption",
|
||||
56.0,
|
||||
!sb.caption.is_empty(),
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaCaption,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
SurfaceBlockKind::EmbedLinkedDoc
|
||||
| SurfaceBlockKind::EmbedSyncedDoc
|
||||
| SurfaceBlockKind::ExternalEmbed => {
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-media-open",
|
||||
"chrome.edgeless_element_toolbar.media_open",
|
||||
"Open",
|
||||
row.push(
|
||||
58.0,
|
||||
false,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaOpenLink,
|
||||
cx,
|
||||
));
|
||||
advance(58.0, None);
|
||||
text_action_btn(
|
||||
"el-tb-media-open",
|
||||
"chrome.edgeless_element_toolbar.media_open",
|
||||
"Open",
|
||||
58.0,
|
||||
false,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaOpenLink,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-media-copy-link",
|
||||
"chrome.edgeless_element_toolbar.media_copy_link",
|
||||
"Copy link",
|
||||
"LinkIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaCopyLink,
|
||||
cx,
|
||||
));
|
||||
advance(BTN_SIZE, None);
|
||||
row.push(
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-media-copy-link",
|
||||
"chrome.edgeless_element_toolbar.media_copy_link",
|
||||
"Copy link",
|
||||
"LinkIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaCopyLink,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
let view_label = if sb.is_embed_view { "Embed" } else { "Card" };
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-media-view",
|
||||
"chrome.edgeless_element_toolbar.media_view",
|
||||
view_label,
|
||||
row.push(
|
||||
68.0,
|
||||
sb.is_embed_view,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaToggleView,
|
||||
cx,
|
||||
));
|
||||
advance(68.0, None);
|
||||
text_action_btn(
|
||||
"el-tb-media-view",
|
||||
"chrome.edgeless_element_toolbar.media_view",
|
||||
view_label,
|
||||
68.0,
|
||||
sb.is_embed_view,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaToggleView,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
|
||||
bar = bar.child(text_action_btn(
|
||||
"el-tb-media-caption",
|
||||
"chrome.edgeless_element_toolbar.media_caption",
|
||||
"Caption",
|
||||
row.push(
|
||||
56.0,
|
||||
!sb.caption.is_empty(),
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaCaption,
|
||||
cx,
|
||||
));
|
||||
advance(56.0, None);
|
||||
text_action_btn(
|
||||
"el-tb-media-caption",
|
||||
"chrome.edgeless_element_toolbar.media_caption",
|
||||
"Caption",
|
||||
56.0,
|
||||
!sb.caption.is_empty(),
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::MediaCaption,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
bar
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
||||
@@ -217,13 +217,6 @@ pub trait EdgelessElementToolbarHost: 'static + Sized {
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
);
|
||||
|
||||
fn begin_element_toolbar_drag(
|
||||
&mut self,
|
||||
event: &ui::MouseDownEvent,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
);
|
||||
}
|
||||
|
||||
/// Summary of a selected Mindmap node (or root) for Mindmap toolbar controls.
|
||||
@@ -248,12 +241,12 @@ pub struct ElementToolbarSummary {
|
||||
pub can_frame_section: bool,
|
||||
pub can_group_section: bool,
|
||||
pub can_copy_markdown: bool,
|
||||
pub has_shape_grip: bool,
|
||||
pub can_align: bool,
|
||||
pub can_distribute: bool,
|
||||
pub can_draw_connector: bool,
|
||||
pub has_fill: bool,
|
||||
pub has_stroke: bool,
|
||||
pub stroke_is_text: bool,
|
||||
pub has_text_color: bool,
|
||||
pub has_text_align: bool,
|
||||
pub has_stroke_style: bool,
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::{
|
||||
use super::{
|
||||
EDGELESS_VIEWPORT_ID, EdgelessElementAction, EdgelessElementToolbarHost, ElementToolbarSummary,
|
||||
SurfaceBlockKind,
|
||||
widgets::{isolate_floating_chrome, toolbar_chrome_tokens},
|
||||
widgets::{isolate_floating_chrome, paint_group_action_icon, toolbar_chrome_tokens},
|
||||
};
|
||||
|
||||
const MENU_MIN_W: f32 = 220.0;
|
||||
@@ -94,16 +94,32 @@ pub(super) fn build_more_menu<V: EdgelessElementToolbarHost>(
|
||||
if summary.can_group_section {
|
||||
selection_section.push(MoreMenuItem {
|
||||
id: "group_section",
|
||||
label: "Create group",
|
||||
icon: "SelectIcon",
|
||||
label: "Group section",
|
||||
icon: "",
|
||||
shortcut: None,
|
||||
action: EdgelessElementAction::GroupSection,
|
||||
destructive: false,
|
||||
});
|
||||
}
|
||||
if !selection_section.is_empty() {
|
||||
sections.push(selection_section);
|
||||
if summary.has_group_actions || summary.has_frame_actions {
|
||||
selection_section.push(MoreMenuItem {
|
||||
id: "ungroup",
|
||||
label: "Ungroup",
|
||||
icon: "",
|
||||
shortcut: None,
|
||||
action: EdgelessElementAction::Ungroup,
|
||||
destructive: false,
|
||||
});
|
||||
}
|
||||
selection_section.push(MoreMenuItem {
|
||||
id: "lock",
|
||||
label: "Lock",
|
||||
icon: "LockIcon",
|
||||
shortcut: None,
|
||||
action: EdgelessElementAction::ToggleLock,
|
||||
destructive: false,
|
||||
});
|
||||
sections.push(selection_section);
|
||||
|
||||
if summary.has_frame_actions {
|
||||
sections.push(vec![MoreMenuItem {
|
||||
@@ -318,7 +334,9 @@ pub(super) fn build_more_menu<V: EdgelessElementToolbarHost>(
|
||||
canvas(
|
||||
|_, _, _| (),
|
||||
move |bounds, _, window, cx| {
|
||||
IconPaint::named(icon_name).paint(bounds, icon_col, window, cx);
|
||||
if !paint_group_action_icon(&item.action, bounds, icon_col, window) {
|
||||
IconPaint::named(icon_name).paint(bounds, icon_col, window, cx);
|
||||
}
|
||||
},
|
||||
)
|
||||
.w(px(18.0))
|
||||
|
||||
@@ -112,27 +112,6 @@ pub const DEFAULT_PALETTES: [PaletteSwatch; 26] = [
|
||||
PaletteSwatch::themed("Black", "#000000", "#ffffff"),
|
||||
];
|
||||
|
||||
/// BlockSuite's short Fill palette: medium colors, adaptive black and white, and transparent.
|
||||
const SHAPE_COLOR_STRIP: [PaletteSwatch; 11] = [
|
||||
DEFAULT_PALETTES[9],
|
||||
DEFAULT_PALETTES[10],
|
||||
DEFAULT_PALETTES[11],
|
||||
DEFAULT_PALETTES[12],
|
||||
DEFAULT_PALETTES[13],
|
||||
DEFAULT_PALETTES[14],
|
||||
DEFAULT_PALETTES[15],
|
||||
DEFAULT_PALETTES[16],
|
||||
DEFAULT_PALETTES[25],
|
||||
DEFAULT_PALETTES[17],
|
||||
DEFAULT_PALETTES[8],
|
||||
];
|
||||
|
||||
const SHAPE_LIGHT_COLORS: &[PaletteSwatch] = DEFAULT_PALETTES.split_at(8).0;
|
||||
const SHAPE_HEAVY_COLORS: &[PaletteSwatch] = DEFAULT_PALETTES.split_at(18).1.split_at(7).0;
|
||||
|
||||
pub(super) const SHAPE_COLOR_ROWS: [&[PaletteSwatch]; 3] =
|
||||
[&SHAPE_COLOR_STRIP, SHAPE_LIGHT_COLORS, SHAPE_HEAVY_COLORS];
|
||||
|
||||
/// BlockSuite `NoteBackgroundColorPalettes` (9 dual-theme note backgrounds including Transparent).
|
||||
pub const NOTE_BACKGROUND_PALETTES: [PaletteSwatch; 9] = [
|
||||
PaletteSwatch::themed("Red", "#fbb7b7", "#460606"),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! (flipping below while clearing south quick-connect arrows, or centered `top` when locked).
|
||||
|
||||
use blocksuite_playground_doc::read::PageSnapshot;
|
||||
use ui::{AnyElement, Context, div, point, prelude::*, px};
|
||||
use ui::{AnyElement, Context, Window, div, point, prelude::*, px};
|
||||
|
||||
use crate::{
|
||||
block_flow::FlowRect,
|
||||
@@ -14,81 +14,58 @@ use super::{
|
||||
EdgelessElementToolbarHost, ElementColorSlot, ElementSubMenu, SpatialItemKind,
|
||||
bar_items::append_per_type_items,
|
||||
color_popover::build_color_picker_pill,
|
||||
media_toolbar::media_toolbar_item_widths,
|
||||
popovers::{build_sub_menu_pill, place_toolbar_rect},
|
||||
summarize_element_toolbar,
|
||||
typography::font_trigger_widths,
|
||||
widgets::{
|
||||
BAR_GAP, BAR_HEIGHT, BAR_PAD_X, BAR_RADIUS, BTN_SIZE, SEP_W, custom_icon_btn,
|
||||
icon_action_btn, isolate_floating_chrome, more_vertical_glyph, shape_drag_handle,
|
||||
text_action_btn, toolbar_chrome_tokens, toolbar_separator,
|
||||
icon_action_btn, isolate_floating_chrome, more_vertical_glyph, text_action_btn,
|
||||
toolbar_chrome_tokens, toolbar_separator,
|
||||
},
|
||||
};
|
||||
|
||||
/// Deterministic flex-wrap cursor mirroring Taffy's row breaks inside `chrome.edgeless_element_toolbar`,
|
||||
/// so trigger anchor rects (including wrapped `More`) align with laid-out button coordinates on Frame 1.
|
||||
pub(super) struct ToolbarFlowCursor {
|
||||
origin_x: f32,
|
||||
bar_top: f32,
|
||||
bar_h: f32,
|
||||
inner_max: f32,
|
||||
wraps: bool,
|
||||
row_x: f32,
|
||||
row_idx: usize,
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum ToolbarTrigger {
|
||||
SubMenu(ElementSubMenu),
|
||||
Color(ElementColorSlot),
|
||||
}
|
||||
|
||||
impl ToolbarFlowCursor {
|
||||
pub(super) fn new(
|
||||
origin_x: f32,
|
||||
bar_top: f32,
|
||||
bar_h: f32,
|
||||
inner_max: f32,
|
||||
wraps: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
origin_x,
|
||||
bar_top,
|
||||
bar_h,
|
||||
inner_max,
|
||||
wraps,
|
||||
row_x: 0.0,
|
||||
row_idx: 0,
|
||||
}
|
||||
}
|
||||
struct ToolbarItem {
|
||||
rect: FlowRect,
|
||||
trigger: Option<ToolbarTrigger>,
|
||||
element: AnyElement,
|
||||
}
|
||||
|
||||
pub(super) fn place(&mut self, w: f32) -> FlowRect {
|
||||
let needed = if self.row_x == 0.0 { w } else { BAR_GAP + w };
|
||||
if self.wraps && self.row_x > 0.0 && self.row_x + needed > self.inner_max + 0.01 {
|
||||
self.row_idx += 1;
|
||||
self.row_x = 0.0;
|
||||
}
|
||||
let x = self.origin_x
|
||||
+ if self.row_x == 0.0 {
|
||||
0.0
|
||||
} else {
|
||||
self.row_x + BAR_GAP
|
||||
};
|
||||
self.row_x = if self.row_x == 0.0 {
|
||||
w
|
||||
pub(super) struct ToolbarRow {
|
||||
width: f32,
|
||||
gap: f32,
|
||||
items: Vec<ToolbarItem>,
|
||||
}
|
||||
|
||||
impl ToolbarRow {
|
||||
fn add(&mut self, width: f32, trigger: Option<ToolbarTrigger>, element: impl IntoElement) {
|
||||
let left = if self.items.is_empty() {
|
||||
0.0
|
||||
} else {
|
||||
self.row_x + BAR_GAP + w
|
||||
self.width + self.gap
|
||||
};
|
||||
FlowRect::new(x, self.bar_top, w, self.bar_h)
|
||||
self.width = left + width;
|
||||
self.items.push(ToolbarItem {
|
||||
rect: FlowRect::new(left, 0.0, width, BAR_HEIGHT),
|
||||
trigger,
|
||||
element: element.into_any_element(),
|
||||
});
|
||||
}
|
||||
|
||||
fn place_separator(&mut self, next_width: f32) -> bool {
|
||||
if self.wraps
|
||||
&& (self.row_x == 0.0
|
||||
|| self.row_x + 2.0 * BAR_GAP + SEP_W + next_width > self.inner_max + 0.01)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
self.place(SEP_W);
|
||||
true
|
||||
pub(super) fn push(&mut self, width: f32, element: impl IntoElement) {
|
||||
self.add(width, None, element);
|
||||
}
|
||||
|
||||
fn row_count(&self) -> usize {
|
||||
self.row_idx + 1
|
||||
pub(super) fn submenu(&mut self, menu: ElementSubMenu, width: f32, element: impl IntoElement) {
|
||||
self.add(width, Some(ToolbarTrigger::SubMenu(menu)), element);
|
||||
}
|
||||
|
||||
pub(super) fn color(&mut self, slot: ElementColorSlot, width: f32, element: impl IntoElement) {
|
||||
self.add(width, Some(ToolbarTrigger::Color(slot)), element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +82,7 @@ pub fn build_edgeless_element_toolbar<V: EdgelessElementToolbarHost>(
|
||||
palette: &Palette,
|
||||
theme: PlaygroundTheme,
|
||||
can_download_blob: impl Fn(&str) -> bool,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<V>,
|
||||
) -> Option<(AnyElement, Vec<FlowRect>)> {
|
||||
if authoring.inline_edit.is_some() || authoring.gesture.is_some() {
|
||||
@@ -200,200 +178,18 @@ pub fn build_edgeless_element_toolbar<V: EdgelessElementToolbarHost>(
|
||||
));
|
||||
}
|
||||
|
||||
let mut start_widths = Vec::new();
|
||||
if summary.has_shape_grip {
|
||||
start_widths.push(BTN_SIZE);
|
||||
}
|
||||
let compact = viewport_width <= 560.0;
|
||||
let gap = if compact { 6.0 } else { BAR_GAP };
|
||||
let mut row = ToolbarRow {
|
||||
width: 0.0,
|
||||
gap,
|
||||
items: Vec::new(),
|
||||
};
|
||||
|
||||
if summary.can_release_from_group {
|
||||
start_widths.push(64.0_f32);
|
||||
}
|
||||
if summary.can_wrap_frame {
|
||||
start_widths.push(52.0);
|
||||
}
|
||||
if summary.can_group {
|
||||
start_widths.push(52.0);
|
||||
}
|
||||
if summary.can_align {
|
||||
start_widths.push(58.0);
|
||||
}
|
||||
|
||||
let compact = viewport_width < 460.0;
|
||||
let mut type_widths = Vec::new();
|
||||
if summary.has_frame_actions {
|
||||
type_widths.extend_from_slice(&[54.0, 64.0, 58.0]);
|
||||
} else if summary.has_group_actions {
|
||||
type_widths.extend_from_slice(&[64.0, 54.0, 58.0]);
|
||||
}
|
||||
if let Some(mm) = &summary.mindmap {
|
||||
type_widths.extend_from_slice(&[62.0, 62.0]);
|
||||
if mm.has_children {
|
||||
type_widths.push(54.0);
|
||||
}
|
||||
}
|
||||
if let Some(sb) = &summary.surface_block {
|
||||
type_widths.extend(media_toolbar_item_widths(sb));
|
||||
}
|
||||
if summary.has_shape_type {
|
||||
type_widths.push(BTN_SIZE);
|
||||
}
|
||||
if summary.has_fill {
|
||||
type_widths.push(BTN_SIZE);
|
||||
}
|
||||
if summary.has_stroke {
|
||||
type_widths.push(BTN_SIZE);
|
||||
}
|
||||
if summary.has_stroke_style {
|
||||
type_widths.push(BTN_SIZE);
|
||||
}
|
||||
if summary.has_stroke_width {
|
||||
type_widths.push(44.0);
|
||||
}
|
||||
if summary.has_rough_style {
|
||||
type_widths.push(BTN_SIZE);
|
||||
}
|
||||
if summary.has_connector_props {
|
||||
type_widths.extend_from_slice(&[BTN_SIZE, 48.0]);
|
||||
}
|
||||
if summary.can_add_text {
|
||||
type_widths.push(BTN_SIZE);
|
||||
}
|
||||
if summary.has_text_color {
|
||||
type_widths.push(BTN_SIZE);
|
||||
}
|
||||
if summary.typography.is_some() {
|
||||
type_widths.extend(font_trigger_widths(compact));
|
||||
type_widths.push(BTN_SIZE);
|
||||
}
|
||||
if summary.has_font_size {
|
||||
type_widths.push(44.0);
|
||||
}
|
||||
if summary.has_text_align {
|
||||
type_widths.push(BTN_SIZE);
|
||||
}
|
||||
if summary.has_note_shadow {
|
||||
type_widths.extend_from_slice(&[56.0, 54.0]);
|
||||
}
|
||||
if summary.has_note_display {
|
||||
type_widths.push(96.0);
|
||||
}
|
||||
|
||||
let mut end_widths = Vec::new();
|
||||
if summary.can_draw_connector {
|
||||
end_widths.push(BTN_SIZE);
|
||||
}
|
||||
end_widths.push(BTN_SIZE);
|
||||
|
||||
let mut item_widths: Vec<f32> = Vec::with_capacity(24);
|
||||
let mut push_group = |widths: &[f32]| {
|
||||
if widths.is_empty() {
|
||||
return;
|
||||
}
|
||||
if !item_widths.is_empty() {
|
||||
item_widths.push(SEP_W);
|
||||
}
|
||||
item_widths.extend_from_slice(widths);
|
||||
};
|
||||
push_group(&start_widths);
|
||||
push_group(&type_widths);
|
||||
push_group(&end_widths);
|
||||
push_group(&[BTN_SIZE]);
|
||||
|
||||
let content_w = 2.0 * BAR_PAD_X
|
||||
+ 1.0
|
||||
+ item_widths.iter().sum::<f32>()
|
||||
+ BAR_GAP * (item_widths.len().saturating_sub(1) as f32);
|
||||
let max_bar_w = (viewport_width - 20.0).max(96.0);
|
||||
let wraps = content_w > max_bar_w;
|
||||
let bar_w = if wraps {
|
||||
max_bar_w.ceil()
|
||||
} else {
|
||||
content_w.ceil()
|
||||
};
|
||||
let inner_max = (bar_w - 2.0 * BAR_PAD_X - 1.0).max(BTN_SIZE);
|
||||
let rows = if wraps {
|
||||
let mut probe = ToolbarFlowCursor::new(0.0, 0.0, BAR_HEIGHT, inner_max, true);
|
||||
for (index, &w) in item_widths.iter().enumerate() {
|
||||
if w == SEP_W {
|
||||
probe.place_separator(item_widths.get(index + 1).copied().unwrap_or(0.0));
|
||||
} else {
|
||||
probe.place(w);
|
||||
}
|
||||
}
|
||||
probe.row_count() as f32
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
let bar_h = if wraps {
|
||||
rows * BTN_SIZE + (rows - 1.0) * BAR_GAP + 12.0 + 1.0
|
||||
} else {
|
||||
BAR_HEIGHT
|
||||
};
|
||||
let placed = place_toolbar_rect(
|
||||
authoring,
|
||||
camera,
|
||||
vp_origin,
|
||||
anchor,
|
||||
(bar_w, bar_h),
|
||||
vp_rect,
|
||||
false,
|
||||
);
|
||||
|
||||
let mut bar = isolate_floating_chrome(
|
||||
div()
|
||||
.absolute()
|
||||
.left(px(placed.rect.x))
|
||||
.top(px(placed.rect.y))
|
||||
.px(px(BAR_PAD_X))
|
||||
.rounded(px(BAR_RADIUS))
|
||||
.bg(panel_bg)
|
||||
.border(px(0.5))
|
||||
.border_color(border_col)
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(px(BAR_GAP)),
|
||||
);
|
||||
if wraps {
|
||||
bar = bar.w(px(bar_w)).py(px(6.0)).flex_wrap();
|
||||
} else {
|
||||
bar = bar.h(px(BAR_HEIGHT));
|
||||
}
|
||||
bar = bar.snapshot(
|
||||
"chrome.edgeless_element_toolbar",
|
||||
Some(EDGELESS_VIEWPORT_ID),
|
||||
);
|
||||
|
||||
let mut cursor = ToolbarFlowCursor::new(
|
||||
placed.rect.x + 0.5 + BAR_PAD_X,
|
||||
placed.rect.y,
|
||||
bar_h,
|
||||
inner_max,
|
||||
wraps,
|
||||
);
|
||||
let mut sub_triggers: Vec<(ElementSubMenu, FlowRect)> = Vec::new();
|
||||
let mut color_triggers: Vec<(ElementColorSlot, FlowRect)> = Vec::new();
|
||||
let mut has_any_prior = false;
|
||||
|
||||
let maybe_sep =
|
||||
|b: ui::Div, cur: &mut ToolbarFlowCursor, had: &mut bool, next_width| -> ui::Div {
|
||||
if *had {
|
||||
b.when(cur.place_separator(next_width), |bar| {
|
||||
bar.child(toolbar_separator(border_col, wraps))
|
||||
})
|
||||
} else {
|
||||
*had = true;
|
||||
b
|
||||
}
|
||||
};
|
||||
|
||||
if !start_widths.is_empty() {
|
||||
has_any_prior = true;
|
||||
if summary.has_shape_grip {
|
||||
cursor.place(BTN_SIZE);
|
||||
bar = bar.child(shape_drag_handle(palette, cx));
|
||||
}
|
||||
if summary.can_release_from_group {
|
||||
cursor.place(64.0);
|
||||
bar = bar.child(text_action_btn(
|
||||
row.push(
|
||||
64.0,
|
||||
text_action_btn(
|
||||
"el-tb-release-group",
|
||||
"chrome.edgeless_element_toolbar.release_from_group",
|
||||
"Release",
|
||||
@@ -404,11 +200,13 @@ pub fn build_edgeless_element_toolbar<V: EdgelessElementToolbarHost>(
|
||||
palette,
|
||||
EdgelessElementAction::ReleaseFromGroup,
|
||||
cx,
|
||||
));
|
||||
}
|
||||
if summary.can_wrap_frame {
|
||||
cursor.place(52.0);
|
||||
bar = bar.child(text_action_btn(
|
||||
),
|
||||
);
|
||||
}
|
||||
if summary.can_wrap_frame {
|
||||
row.push(
|
||||
52.0,
|
||||
text_action_btn(
|
||||
"el-tb-wrap-frame",
|
||||
"chrome.edgeless_element_toolbar.frame",
|
||||
"Frame",
|
||||
@@ -419,26 +217,31 @@ pub fn build_edgeless_element_toolbar<V: EdgelessElementToolbarHost>(
|
||||
palette,
|
||||
EdgelessElementAction::WrapInFrame,
|
||||
cx,
|
||||
));
|
||||
}
|
||||
if summary.can_group {
|
||||
cursor.place(52.0);
|
||||
bar = bar.child(text_action_btn(
|
||||
),
|
||||
);
|
||||
}
|
||||
if summary.can_group {
|
||||
row.push(
|
||||
66.0,
|
||||
text_action_btn(
|
||||
"el-tb-group",
|
||||
"chrome.edgeless_element_toolbar.group",
|
||||
"Group",
|
||||
52.0,
|
||||
66.0,
|
||||
false,
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::Group,
|
||||
cx,
|
||||
));
|
||||
}
|
||||
if summary.can_align {
|
||||
sub_triggers.push((ElementSubMenu::Align, cursor.place(58.0)));
|
||||
bar = bar.child(text_action_btn(
|
||||
),
|
||||
);
|
||||
}
|
||||
if summary.can_align {
|
||||
row.submenu(
|
||||
ElementSubMenu::Align,
|
||||
58.0,
|
||||
text_action_btn(
|
||||
"el-tb-align",
|
||||
"chrome.edgeless_element_toolbar.align",
|
||||
"Align",
|
||||
@@ -449,58 +252,180 @@ pub fn build_edgeless_element_toolbar<V: EdgelessElementToolbarHost>(
|
||||
palette,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::Align),
|
||||
cx,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if !type_widths.is_empty() {
|
||||
bar = maybe_sep(bar, &mut cursor, &mut has_any_prior, type_widths[0]);
|
||||
bar = append_per_type_items(
|
||||
bar,
|
||||
&summary,
|
||||
open_color_picker,
|
||||
open_sub,
|
||||
compact,
|
||||
palette,
|
||||
panel_bg,
|
||||
border_col,
|
||||
&mut cursor,
|
||||
&mut sub_triggers,
|
||||
&mut color_triggers,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bar = maybe_sep(bar, &mut cursor, &mut has_any_prior, end_widths[0]);
|
||||
let start_width = row.width;
|
||||
let start_len = row.items.len();
|
||||
if start_len > 0 {
|
||||
row.push(SEP_W, toolbar_separator(border_col));
|
||||
}
|
||||
let type_start = row.items.len();
|
||||
append_per_type_items(
|
||||
&mut row,
|
||||
&summary,
|
||||
open_color_picker,
|
||||
open_sub,
|
||||
compact,
|
||||
palette,
|
||||
panel_bg,
|
||||
border_col,
|
||||
cx,
|
||||
);
|
||||
if row.items.len() == type_start {
|
||||
row.items.truncate(start_len);
|
||||
row.width = start_width;
|
||||
}
|
||||
if !row.items.is_empty() {
|
||||
row.push(SEP_W, toolbar_separator(border_col));
|
||||
}
|
||||
if summary.can_draw_connector {
|
||||
cursor.place(BTN_SIZE);
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-draw-connector",
|
||||
"chrome.edgeless_element_toolbar.draw_connector",
|
||||
"Draw connector",
|
||||
"ConnectorCIcon",
|
||||
row.push(
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-draw-connector",
|
||||
"chrome.edgeless_element_toolbar.draw_connector",
|
||||
"Draw connector",
|
||||
"ConnectorCIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::DrawConnector,
|
||||
cx,
|
||||
),
|
||||
);
|
||||
}
|
||||
row.push(
|
||||
BTN_SIZE,
|
||||
icon_action_btn(
|
||||
"el-tb-lock",
|
||||
"chrome.edgeless_element_toolbar.lock",
|
||||
"Lock",
|
||||
"LockIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::DrawConnector,
|
||||
EdgelessElementAction::ToggleLock,
|
||||
cx,
|
||||
));
|
||||
}
|
||||
cursor.place(BTN_SIZE);
|
||||
bar = bar.child(icon_action_btn(
|
||||
"el-tb-lock",
|
||||
"chrome.edgeless_element_toolbar.lock",
|
||||
"Lock",
|
||||
"LockIcon",
|
||||
false,
|
||||
show_tooltips,
|
||||
palette,
|
||||
EdgelessElementAction::ToggleLock,
|
||||
cx,
|
||||
));
|
||||
),
|
||||
);
|
||||
|
||||
bar = maybe_sep(bar, &mut cursor, &mut has_any_prior, BTN_SIZE);
|
||||
sub_triggers.push((ElementSubMenu::More, cursor.place(BTN_SIZE)));
|
||||
let more_width = gap * 2.0 + SEP_W + BTN_SIZE;
|
||||
let chrome_width = 2.0 * BAR_PAD_X + 1.0;
|
||||
let strip_width = row
|
||||
.width
|
||||
.min((viewport_width - 20.0 - chrome_width - more_width).max(0.0));
|
||||
let bar_width = strip_width + more_width + chrome_width;
|
||||
let placed = place_toolbar_rect(
|
||||
authoring,
|
||||
camera,
|
||||
vp_origin,
|
||||
anchor,
|
||||
(bar_width, BAR_HEIGHT),
|
||||
vp_rect,
|
||||
false,
|
||||
);
|
||||
let strip_x = placed.rect.x + 0.5 + BAR_PAD_X;
|
||||
let strip_y = placed.rect.y;
|
||||
let max_scroll = row.width - strip_width;
|
||||
let scroll = (max_scroll > 0.0).then(|| window.use_state(cx, |_, _| 0.0_f32));
|
||||
let scroll_offset = scroll
|
||||
.as_ref()
|
||||
.map_or(0.0, |position| position.read(cx).clamp(0.0, max_scroll));
|
||||
let visible =
|
||||
|rect: FlowRect| rect.x >= scroll_offset && rect.right() <= scroll_offset + strip_width;
|
||||
let active_trigger = open_color_picker.map(ToolbarTrigger::Color).or_else(|| {
|
||||
open_sub.map(|menu| {
|
||||
ToolbarTrigger::SubMenu(match menu {
|
||||
ElementSubMenu::NoteShadow => ElementSubMenu::NoteStyle,
|
||||
other => other,
|
||||
})
|
||||
})
|
||||
});
|
||||
let trigger_rect = row.items.iter().find_map(|item| {
|
||||
(active_trigger.is_some() && item.trigger == active_trigger && visible(item.rect)).then(
|
||||
|| {
|
||||
FlowRect::new(
|
||||
strip_x + item.rect.x - scroll_offset,
|
||||
strip_y,
|
||||
item.rect.w,
|
||||
BAR_HEIGHT,
|
||||
)
|
||||
},
|
||||
)
|
||||
});
|
||||
|
||||
let strip = div().w(px(strip_width)).flex_none();
|
||||
let strip = if let Some(scroll) = scroll {
|
||||
strip
|
||||
.h(px(BAR_HEIGHT - 1.0))
|
||||
.relative()
|
||||
.on_scroll(move |event, _, cx| {
|
||||
let delta = event.delta.pixel_delta(px(BTN_SIZE));
|
||||
let dx = if delta.x == px(0.0) && event.source == ui::ScrollSource::Pointer {
|
||||
delta.y
|
||||
} else {
|
||||
delta.x
|
||||
};
|
||||
scroll.update(cx, |offset, cx| {
|
||||
let next = (*offset - f32::from(dx)).clamp(0.0, max_scroll);
|
||||
if next != *offset {
|
||||
*offset = next;
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
cx.stop_propagation();
|
||||
})
|
||||
.children(
|
||||
row.items
|
||||
.into_iter()
|
||||
.filter(|item| visible(item.rect))
|
||||
.map(|item| {
|
||||
div()
|
||||
.absolute()
|
||||
.left(px(item.rect.x - scroll_offset))
|
||||
.top(px(0.0))
|
||||
.h(px(BAR_HEIGHT - 1.0))
|
||||
.flex()
|
||||
.items_center()
|
||||
.child(item.element)
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
strip
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(px(gap))
|
||||
.children(row.items.into_iter().map(|item| item.element))
|
||||
};
|
||||
let more_trigger = FlowRect::new(
|
||||
strip_x + strip_width + gap * 2.0 + SEP_W,
|
||||
strip_y,
|
||||
BTN_SIZE,
|
||||
BAR_HEIGHT,
|
||||
);
|
||||
let mut bar = isolate_floating_chrome(
|
||||
div()
|
||||
.absolute()
|
||||
.left(px(placed.rect.x))
|
||||
.top(px(placed.rect.y))
|
||||
.w(px(bar_width))
|
||||
.h(px(BAR_HEIGHT))
|
||||
.px(px(BAR_PAD_X))
|
||||
.rounded(px(BAR_RADIUS))
|
||||
.bg(panel_bg)
|
||||
.border(px(0.5))
|
||||
.border_color(border_col)
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(px(gap)),
|
||||
)
|
||||
.snapshot(
|
||||
"chrome.edgeless_element_toolbar",
|
||||
Some(EDGELESS_VIEWPORT_ID),
|
||||
)
|
||||
.child(strip)
|
||||
.child(toolbar_separator(border_col));
|
||||
let more_icon_col = if open_sub == Some(ElementSubMenu::More) {
|
||||
palette.brand
|
||||
} else {
|
||||
@@ -525,15 +450,8 @@ pub fn build_edgeless_element_toolbar<V: EdgelessElementToolbarHost>(
|
||||
let mut hitboxes = vec![placed.rect];
|
||||
let mut wrapper = div().size_full().child(bar);
|
||||
if let Some(slot) = open_color_picker
|
||||
&& ((slot == ElementColorSlot::Fill && summary.has_fill)
|
||||
|| (slot == ElementColorSlot::Stroke && summary.has_stroke)
|
||||
|| (slot == ElementColorSlot::Text && summary.has_text_color))
|
||||
&& let Some(trigger) = trigger_rect
|
||||
{
|
||||
let trigger = color_triggers
|
||||
.iter()
|
||||
.find(|(s, _)| *s == slot)
|
||||
.map(|(_, r)| *r)
|
||||
.unwrap_or(placed.rect);
|
||||
let (sub_el, sub_rect) = build_color_picker_pill(
|
||||
slot,
|
||||
&summary,
|
||||
@@ -547,13 +465,13 @@ pub fn build_edgeless_element_toolbar<V: EdgelessElementToolbarHost>(
|
||||
);
|
||||
hitboxes.push(sub_rect);
|
||||
wrapper = wrapper.child(sub_el);
|
||||
} else if let Some(menu) = open_sub {
|
||||
let trigger = sub_triggers
|
||||
.iter()
|
||||
.find(|(m, _)| *m == menu)
|
||||
.map(|(_, r)| *r)
|
||||
.unwrap_or(placed.rect);
|
||||
if let Some((sub_el, sub_rect)) = build_sub_menu_pill(
|
||||
} else if let Some(menu) = open_sub
|
||||
&& let Some(trigger) = if menu == ElementSubMenu::More {
|
||||
Some(more_trigger)
|
||||
} else {
|
||||
trigger_rect
|
||||
}
|
||||
&& let Some((sub_el, sub_rect)) = build_sub_menu_pill(
|
||||
menu,
|
||||
&summary,
|
||||
trigger,
|
||||
@@ -562,10 +480,10 @@ pub fn build_edgeless_element_toolbar<V: EdgelessElementToolbarHost>(
|
||||
palette,
|
||||
theme,
|
||||
cx,
|
||||
) {
|
||||
hitboxes.push(sub_rect);
|
||||
wrapper = wrapper.child(sub_el);
|
||||
}
|
||||
)
|
||||
{
|
||||
hitboxes.push(sub_rect);
|
||||
wrapper = wrapper.child(sub_el);
|
||||
}
|
||||
Some((wrapper.into_any_element(), hitboxes))
|
||||
}
|
||||
@@ -256,6 +256,10 @@ pub fn summarize_element_toolbar(
|
||||
};
|
||||
|
||||
let selected_count = selected_items.len();
|
||||
let selection_kind = selected_items[0].kind;
|
||||
let mixed_kinds = selected_items
|
||||
.iter()
|
||||
.any(|item| item.kind != selection_kind);
|
||||
let mut is_locked = false;
|
||||
let non_frame_count = selected_items
|
||||
.iter()
|
||||
@@ -267,9 +271,23 @@ pub fn summarize_element_toolbar(
|
||||
!item.in_mindmap && item.parent_group_id == selected_items[0].parent_group_id
|
||||
});
|
||||
let can_wrap_frame = selected_count >= 2;
|
||||
let can_group = non_frame_count >= 2;
|
||||
let can_align = selected_count >= 2;
|
||||
let can_distribute = selected_count >= 3;
|
||||
let alignable_count = selected_items
|
||||
.iter()
|
||||
.filter(|item| {
|
||||
!matches!(
|
||||
item.kind,
|
||||
SpatialItemKind::Connector | SpatialItemKind::Group
|
||||
)
|
||||
})
|
||||
.count();
|
||||
let can_align = alignable_count >= 2 && selected_items.iter().all(|item| !item.in_mindmap);
|
||||
let can_group = selected_count >= 2
|
||||
&& can_group_section
|
||||
&& selection_kind != SpatialItemKind::Group
|
||||
&& selected_items
|
||||
.iter()
|
||||
.any(|item| item.kind != SpatialItemKind::Connector);
|
||||
let can_distribute = can_align && alignable_count >= 3;
|
||||
let single = (selected_count == 1).then_some(selected_items[0]);
|
||||
let can_release_from_group = single.is_some_and(|i| i.parent_group_id.is_some());
|
||||
let can_draw_connector = single.is_some_and(|i| {
|
||||
@@ -281,7 +299,6 @@ pub fn summarize_element_toolbar(
|
||||
| SpatialItemKind::Group
|
||||
)
|
||||
});
|
||||
let has_shape_grip = single.is_some_and(|i| i.kind == SpatialItemKind::Shape);
|
||||
let has_frame_actions = single.is_some_and(|i| i.kind == SpatialItemKind::Frame);
|
||||
let has_group_actions = single.is_some_and(|i| i.kind == SpatialItemKind::Group);
|
||||
let mindmap = single
|
||||
@@ -353,8 +370,14 @@ pub fn summarize_element_toolbar(
|
||||
(selected_count > 1).then(|| resolve_multi_targets(snapshot, selected_items));
|
||||
|
||||
for (idx, item) in selected_items.iter().enumerate() {
|
||||
if item.locked {
|
||||
is_locked = true;
|
||||
is_locked |= item.locked;
|
||||
if mixed_kinds {
|
||||
if let Some((blocks, elements)) = &multi_targets {
|
||||
is_locked |= blocks[idx]
|
||||
.is_some_and(|node| prop_bool(node, "prop:lockedBySelf", false))
|
||||
|| elements[idx].is_some_and(|el| el.locked_by_self);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
match item.kind {
|
||||
SpatialItemKind::Shape => {
|
||||
@@ -697,12 +720,12 @@ pub fn summarize_element_toolbar(
|
||||
can_frame_section,
|
||||
can_group_section: can_group_section && mindmap.is_none(),
|
||||
can_copy_markdown,
|
||||
has_shape_grip,
|
||||
can_align,
|
||||
can_distribute,
|
||||
can_draw_connector,
|
||||
has_fill,
|
||||
has_stroke,
|
||||
stroke_is_text: selection_kind == SpatialItemKind::EdgelessText,
|
||||
has_text_color,
|
||||
has_text_align,
|
||||
has_stroke_style,
|
||||
@@ -792,7 +815,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summarize_multi_selection_resolves_blocks_and_surface_elements() {
|
||||
fn mixed_selection_resolves_targets_and_exposes_shared_actions() {
|
||||
let shape = SurfaceElement {
|
||||
id: "s1".into(),
|
||||
index: "a0".into(),
|
||||
@@ -874,12 +897,21 @@ mod tests {
|
||||
let palette = Palette::new(theme);
|
||||
let summary = summarize_element_toolbar(&snapshot, &authoring, theme, &palette, |_| false)
|
||||
.expect("summary");
|
||||
assert!(summary.has_fill && summary.has_stroke && summary.note_in_page);
|
||||
assert!(summary.can_align && summary.can_group);
|
||||
assert!(!summary.has_fill && !summary.has_stroke && !summary.has_note_shadow);
|
||||
let items: Vec<_> = authoring.painted_items.iter().collect();
|
||||
let (blocks, surface_elements) = resolve_multi_targets(&snapshot, &items);
|
||||
assert_eq!(blocks[1].map(|note| note.id.as_str()), Some("n1"));
|
||||
assert_eq!(
|
||||
summary.fill_color_value,
|
||||
ColorValue::Single("#ff0000".into())
|
||||
surface_elements[0].map(|shape| shape.id.as_str()),
|
||||
Some("s1")
|
||||
);
|
||||
assert_eq!(summary.stroke_width, 3.0);
|
||||
assert_eq!(summary.shape_preset, ShapePreset::RoundedRect);
|
||||
|
||||
authoring.selection.retain(|id| id == "s1");
|
||||
let shape = summarize_element_toolbar(&snapshot, &authoring, theme, &palette, |_| false)
|
||||
.expect("shape summary");
|
||||
assert_eq!(shape.fill_color_value, ColorValue::Single("#ff0000".into()));
|
||||
assert_eq!(shape.stroke_width, 3.0);
|
||||
assert_eq!(shape.shape_preset, ShapePreset::RoundedRect);
|
||||
}
|
||||
}
|
||||
@@ -96,8 +96,8 @@ pub(super) fn isolate_floating_chrome(el: ui::Div) -> ui::Div {
|
||||
}
|
||||
|
||||
/// Full-height `0.5px` vertical separator inside a `4px` slot between action groups.
|
||||
pub(super) fn toolbar_separator(border_col: Hsla, wrapped: bool) -> ui::Div {
|
||||
let h = if wrapped { BTN_SIZE } else { BAR_HEIGHT - 1.0 };
|
||||
pub(super) fn toolbar_separator(border_col: Hsla) -> ui::Div {
|
||||
let h = BAR_HEIGHT - 1.0;
|
||||
div()
|
||||
.flex_none()
|
||||
.w(px(SEP_W))
|
||||
@@ -108,55 +108,54 @@ pub(super) fn toolbar_separator(border_col: Hsla, wrapped: bool) -> ui::Div {
|
||||
.child(div().w(px(0.5)).h(px(h)).bg(border_col))
|
||||
}
|
||||
|
||||
pub(super) fn shape_drag_handle<V: EdgelessElementToolbarHost>(
|
||||
palette: &Palette,
|
||||
cx: &mut Context<V>,
|
||||
) -> ui::Stateful<ui::Div> {
|
||||
let dots = palette.icon;
|
||||
let hover = palette.hover;
|
||||
div()
|
||||
.id("el-tb-shape-grip")
|
||||
.flex_none()
|
||||
.w(px(BTN_SIZE))
|
||||
.h(px(BTN_SIZE))
|
||||
.rounded(px(BTN_RADIUS))
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.cursor_grab()
|
||||
.hover(move |style| style.bg(hover))
|
||||
.on_mouse_down(
|
||||
MouseButton::Left,
|
||||
cx.listener(|this, event: &ui::MouseDownEvent, window, cx| {
|
||||
cx.stop_propagation();
|
||||
this.begin_element_toolbar_drag(event, window, cx);
|
||||
}),
|
||||
)
|
||||
.snapshot(
|
||||
"chrome.edgeless_element_toolbar.shape_grip",
|
||||
Some("chrome.edgeless_element_toolbar"),
|
||||
)
|
||||
.child(
|
||||
canvas(
|
||||
|_, _, _| (),
|
||||
move |bounds, _, window, _| {
|
||||
for row in 0..3 {
|
||||
for col in 0..2 {
|
||||
let dot = Bounds::new(
|
||||
point(
|
||||
bounds.origin.x + px(col as f32 * 5.0),
|
||||
bounds.origin.y + px(row as f32 * 5.0),
|
||||
),
|
||||
size(px(3.0), px(3.0)),
|
||||
);
|
||||
window.paint_quad(ui::fill(dot, dots).corner_radii(px(1.5)));
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.w(px(8.0))
|
||||
.h(px(13.0)),
|
||||
)
|
||||
pub(super) fn paint_group_action_icon(
|
||||
action: &EdgelessElementAction,
|
||||
bounds: Bounds<ui::Pixels>,
|
||||
color: Hsla,
|
||||
window: &mut ui::Window,
|
||||
) -> bool {
|
||||
let rectangles: &[(f32, f32, f32, f32)] = match action {
|
||||
EdgelessElementAction::Group => &[(3.5, 4.0, 17.0, 16.0)],
|
||||
EdgelessElementAction::GroupSection => &[(8.0, 8.0, 6.0, 4.0), (10.0, 12.0, 6.0, 4.0)],
|
||||
EdgelessElementAction::Ungroup => &[(4.0, 4.0, 9.0, 6.0), (11.0, 14.0, 9.0, 6.0)],
|
||||
_ => return false,
|
||||
};
|
||||
let scale = bounds.size.width / 24.0;
|
||||
let origin = bounds.origin;
|
||||
let at = |x, y| point(origin.x + scale * x, origin.y + scale * y);
|
||||
for &(x, y, w, h) in rectangles {
|
||||
window.paint_quad(ui::quad(
|
||||
Bounds::new(at(x, y), size(scale * w, scale * h)),
|
||||
ui::Corners::all(scale * 1.5),
|
||||
ui::transparent_black(),
|
||||
ui::Edges::all(scale * 1.5),
|
||||
color,
|
||||
ui::BorderStyle::Solid,
|
||||
));
|
||||
}
|
||||
let mut lines = ui::PathBuilder::stroke(scale * 1.5);
|
||||
match action {
|
||||
EdgelessElementAction::Group => {
|
||||
for x in [9.0, 15.0] {
|
||||
lines.move_to(at(x, 4.0));
|
||||
lines.line_to(at(x, 20.0));
|
||||
}
|
||||
}
|
||||
EdgelessElementAction::GroupSection => {
|
||||
for (x, dx) in [(4.0, 4.0), (20.0, -4.0)] {
|
||||
for (y, dy) in [(4.0, 4.0), (20.0, -4.0)] {
|
||||
lines.move_to(at(x + dx, y));
|
||||
lines.line_to(at(x, y));
|
||||
lines.line_to(at(x, y + dy));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => return true,
|
||||
}
|
||||
if let Ok(path) = lines.build() {
|
||||
window.paint_path(path, color);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Small downward chevron drawn inside dropdown trigger buttons (`EditorChevronDown`).
|
||||
@@ -377,7 +376,13 @@ pub(super) fn text_action_btn<V: EdgelessElementToolbarHost>(
|
||||
};
|
||||
let chevron_col = if active { palette.brand } else { palette.icon };
|
||||
let tip = label.clone();
|
||||
let unlock = action == EdgelessElementAction::ToggleLock;
|
||||
let icon_action = action.clone();
|
||||
let has_icon = matches!(
|
||||
action,
|
||||
EdgelessElementAction::ToggleLock
|
||||
| EdgelessElementAction::Group
|
||||
| EdgelessElementAction::Ungroup
|
||||
);
|
||||
let icon_color = palette.icon;
|
||||
let mut btn = div()
|
||||
.id(id)
|
||||
@@ -402,12 +407,14 @@ pub(super) fn text_action_btn<V: EdgelessElementToolbarHost>(
|
||||
}))
|
||||
.snapshot(snap_id, Some("chrome.edgeless_element_toolbar"))
|
||||
.snapshot_text(&label)
|
||||
.when(unlock, |btn| {
|
||||
.when(has_icon, |btn| {
|
||||
btn.child(
|
||||
canvas(
|
||||
|_, _, _| (),
|
||||
move |bounds, _, window, cx| {
|
||||
IconPaint::named("UnlockIcon").paint(bounds, icon_color, window, cx);
|
||||
if !paint_group_action_icon(&icon_action, bounds, icon_color, window) {
|
||||
IconPaint::named("UnlockIcon").paint(bounds, icon_color, window, cx);
|
||||
}
|
||||
},
|
||||
)
|
||||
.w(px(ICON_SIZE))
|
||||
@@ -511,6 +518,7 @@ pub(super) fn align_action_btn<V: EdgelessElementToolbarHost>(
|
||||
}
|
||||
|
||||
pub(super) fn text_color_btn<V: EdgelessElementToolbarHost>(
|
||||
slot: ElementColorSlot,
|
||||
active: bool,
|
||||
text_color: Hsla,
|
||||
show_tooltips: bool,
|
||||
@@ -523,8 +531,16 @@ pub(super) fn text_color_btn<V: EdgelessElementToolbarHost>(
|
||||
} else {
|
||||
palette.text_primary
|
||||
};
|
||||
let (id, snapshot_id) = if slot == ElementColorSlot::Stroke {
|
||||
("el-tb-stroke", "chrome.edgeless_element_toolbar.stroke")
|
||||
} else {
|
||||
(
|
||||
"el-tb-text-color",
|
||||
"chrome.edgeless_element_toolbar.text_color",
|
||||
)
|
||||
};
|
||||
let btn = div()
|
||||
.id("el-tb-text-color")
|
||||
.id(id)
|
||||
.flex_none()
|
||||
.w(px(BTN_SIZE))
|
||||
.h(px(BTN_SIZE))
|
||||
@@ -541,18 +557,15 @@ pub(super) fn text_color_btn<V: EdgelessElementToolbarHost>(
|
||||
.cursor_pointer()
|
||||
.hover(move |s| s.bg(hover_bg))
|
||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
||||
.on_click(cx.listener(|this, _: &ClickEvent, window, cx| {
|
||||
.on_click(cx.listener(move |this, _: &ClickEvent, window, cx| {
|
||||
cx.stop_propagation();
|
||||
this.edgeless_element_action(
|
||||
EdgelessElementAction::ToggleColorPicker(ElementColorSlot::Text),
|
||||
EdgelessElementAction::ToggleColorPicker(slot),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}))
|
||||
.snapshot(
|
||||
"chrome.edgeless_element_toolbar.text_color",
|
||||
Some("chrome.edgeless_element_toolbar"),
|
||||
)
|
||||
.snapshot(snapshot_id, Some("chrome.edgeless_element_toolbar"))
|
||||
.snapshot_text("A")
|
||||
.child("A")
|
||||
.child(div().w(px(13.0)).h(px(2.5)).rounded(px(1.0)).bg(text_color));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Focused tests for Edgeless Element Toolbar first-frame appearance after quick-connect / note
|
||||
//! slice / MindMap branch creation, viewport-clamped & wrapped toolbar geometry, and dark-mode
|
||||
//! slice / MindMap branch creation, viewport-clamped single-row toolbar geometry, and dark-mode
|
||||
//! default brush `{dark, light}` CRDT color serialization.
|
||||
|
||||
use std::path::PathBuf;
|
||||
@@ -409,7 +409,7 @@ fn dark_mode_default_brush_color_writes_theme_object_and_renders_bright_ink() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn narrow_390px_wrapped_element_toolbar_more_menu_anchors_to_more_button() {
|
||||
fn narrow_element_toolbar_keeps_more_on_the_same_row_and_anchors_its_menu() {
|
||||
use blocksuite_playground_doc::schema::{BlockSpec, ParagraphType, SurfaceElementSpec};
|
||||
use ui::{point, px};
|
||||
|
||||
@@ -507,10 +507,10 @@ fn narrow_390px_wrapped_element_toolbar_more_menu_anchors_to_more_button() {
|
||||
let hw = platform.windows().into_iter().next().unwrap();
|
||||
hw.request_frame();
|
||||
|
||||
for (label, target_id, expect_wrapped) in [
|
||||
("Bookmark", "bm-narrow", true),
|
||||
("Shape", "shape-a", true),
|
||||
("Note", "note-main", false),
|
||||
for (label, target_id) in [
|
||||
("Bookmark", "bm-narrow"),
|
||||
("Shape", "shape-a"),
|
||||
("Note", "note-main"),
|
||||
] {
|
||||
app.update(|cx| {
|
||||
win.update(cx, |v, _, cx| {
|
||||
@@ -557,12 +557,13 @@ fn narrow_390px_wrapped_element_toolbar_more_menu_anchors_to_more_button() {
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
if expect_wrapped {
|
||||
assert!(
|
||||
more_btn.y > tb.y + 30.0,
|
||||
"{label}: expected More button to wrap onto row 2 at 390px (tb={tb:?}, more_btn={more_btn:?})"
|
||||
);
|
||||
}
|
||||
assert!((tb.height - 36.0).abs() <= 0.5, "{label}: {tb:?}");
|
||||
assert!(
|
||||
more_btn.y >= tb.y
|
||||
&& more_btn.y + more_btn.height <= tb.y + tb.height
|
||||
&& more_btn.x + more_btn.width <= tb.x + tb.width,
|
||||
"{label}: More must stay in the toolbar row (toolbar={tb:?}, more={more_btn:?})"
|
||||
);
|
||||
let expected_x = more_btn.x.clamp(10.0, 380.0 - more_menu.width);
|
||||
assert!(
|
||||
(more_menu.x - expected_x).abs() <= 1.5,
|
||||
@@ -570,7 +571,7 @@ fn narrow_390px_wrapped_element_toolbar_more_menu_anchors_to_more_button() {
|
||||
);
|
||||
assert!(
|
||||
more_menu.y >= tb.y + tb.height - 0.5 || more_menu.y + more_menu.height <= tb.y + 0.5,
|
||||
"{label}: More menu must not overlap wrapped toolbar rows (tb={tb:?}, more_menu={more_menu:?})"
|
||||
"{label}: More menu must clear the toolbar row (tb={tb:?}, more_menu={more_menu:?})"
|
||||
);
|
||||
assert!(
|
||||
menu_in_hitbox,
|
||||
@@ -662,75 +663,205 @@ fn element_toolbar_tracks_visible_selection_and_closes_panels_when_the_context_c
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shape_toolbar_grip_moves_the_selection_in_one_undo_step() {
|
||||
use ui::{
|
||||
Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PlatformInput, point,
|
||||
px,
|
||||
#[cfg(test)]
|
||||
mod toolbar_regressions {
|
||||
use super::start_edgeless_toolbar_view;
|
||||
use crate::edgeless::{
|
||||
EdgelessElementAction, ElementColorSlot, ElementSubMenu, find_surface_element,
|
||||
};
|
||||
|
||||
let (platform, app, win, hw) = start_edgeless_toolbar_view();
|
||||
app.update(|cx| {
|
||||
win.update(cx, |v, _, cx| {
|
||||
v.edgeless_set_selection(["shape-a".into()], cx)
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
hw.request_frame();
|
||||
let read_bounds = |v: &crate::PlaygroundView| {
|
||||
let (_, element) =
|
||||
super::find_surface_element(v.page_snapshot().unwrap(), "shape-a").unwrap();
|
||||
let blocksuite_playground_doc::read::SurfaceElementKind::Shape(shape) = &element.kind
|
||||
else {
|
||||
panic!("selected element must be a shape");
|
||||
};
|
||||
shape.xywh
|
||||
};
|
||||
let (start, before) = app
|
||||
.update(|cx| {
|
||||
win.update(cx, |v, w, _| {
|
||||
let bounds =
|
||||
w.frame_snapshot().elements["chrome.edgeless_element_toolbar.shape_grip"]
|
||||
.bounds;
|
||||
(
|
||||
point(
|
||||
px(bounds.x + bounds.width / 2.0),
|
||||
px(bounds.y + bounds.height / 2.0),
|
||||
),
|
||||
read_bounds(v),
|
||||
)
|
||||
#[test]
|
||||
fn shape_toolbar_starts_with_the_shape_action() {
|
||||
let (_platform, app, win, hw) = start_edgeless_toolbar_view();
|
||||
app.update(|cx| {
|
||||
win.update(cx, |v, _, cx| {
|
||||
v.edgeless_set_selection(["shape-a".into()], cx)
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
hw.dispatch_input(PlatformInput::MouseDown(MouseDownEvent {
|
||||
button: MouseButton::Left,
|
||||
position: start,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
first_mouse: false,
|
||||
}));
|
||||
let end = point(start.x + px(57.0), start.y + px(36.0));
|
||||
hw.dispatch_input(PlatformInput::MouseMove(MouseMoveEvent {
|
||||
position: end,
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
}));
|
||||
hw.dispatch_input(PlatformInput::MouseUp(MouseUpEvent {
|
||||
button: MouseButton::Left,
|
||||
position: end,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
}));
|
||||
platform.run_until_parked();
|
||||
app.update(|cx| {
|
||||
win.update(cx, |v, _, cx| {
|
||||
let after = read_bounds(v);
|
||||
assert!(after[0] > before[0] && after[1] > before[1]);
|
||||
assert_eq!(after[2..], before[2..]);
|
||||
let undo = v.page_mut().unwrap().undo().unwrap().unwrap();
|
||||
v.did_edgeless_doc_commit(undo, cx);
|
||||
assert_eq!(read_bounds(v), before);
|
||||
hw.request_frame();
|
||||
app.update(|cx| {
|
||||
win.update(cx, |_, w, _| {
|
||||
let snap = w.frame_snapshot();
|
||||
let bar = snap.elements["chrome.edgeless_element_toolbar"].bounds;
|
||||
let shape = snap.elements["chrome.edgeless_element_toolbar.shape_type"].bounds;
|
||||
assert!(
|
||||
!snap
|
||||
.elements
|
||||
.contains_key("chrome.edgeless_element_toolbar.shape_grip")
|
||||
);
|
||||
assert!((shape.x - bar.x - 6.5).abs() <= 1.0, "{shape:?} {bar:?}");
|
||||
})
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mixed_selection_keeps_shared_actions_and_more_lock_undoes_once() {
|
||||
use ui::{Modifiers, MouseButton, MouseDownEvent, MouseUpEvent, PlatformInput, point, px};
|
||||
|
||||
let (platform, app, win, hw) = start_edgeless_toolbar_view();
|
||||
app.update(|cx| {
|
||||
win.update(cx, |v, _, cx| {
|
||||
v.edgeless_set_selection(["shape-a", "note-main"].map(str::to_owned), cx);
|
||||
v.apply_edgeless_element_action(
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::More),
|
||||
cx,
|
||||
);
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
hw.request_frame();
|
||||
let click_at = app
|
||||
.update(|cx| {
|
||||
win.update(cx, |_, window, _| {
|
||||
let snap = window.frame_snapshot();
|
||||
let key = |suffix| format!("chrome.edgeless_element_toolbar.{suffix}");
|
||||
for action in [
|
||||
"group",
|
||||
"align",
|
||||
"lock",
|
||||
"more.lock",
|
||||
"more.copy",
|
||||
"more.duplicate",
|
||||
"more.delete",
|
||||
"more.bring_to_front",
|
||||
] {
|
||||
assert!(snap.elements.contains_key(&key(action)), "missing {action}");
|
||||
}
|
||||
for action in ["shape_type", "fill", "note_style", "font_family"] {
|
||||
assert!(
|
||||
!snap.elements.contains_key(&key(action)),
|
||||
"unexpected {action}"
|
||||
);
|
||||
}
|
||||
let row = snap.elements[&key("more.lock")].bounds;
|
||||
point(px(row.x + 15.0), px(row.y + row.height * 0.5))
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
hw.dispatch_input(PlatformInput::MouseDown(MouseDownEvent {
|
||||
button: MouseButton::Left,
|
||||
position: click_at,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
first_mouse: false,
|
||||
}));
|
||||
hw.dispatch_input(PlatformInput::MouseUp(MouseUpEvent {
|
||||
button: MouseButton::Left,
|
||||
position: click_at,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
}));
|
||||
platform.run_until_parked();
|
||||
hw.request_frame();
|
||||
app.update(|cx| {
|
||||
win.update(cx, |v, w, cx| {
|
||||
let selected = v.edgeless.authoring.single_selected().unwrap().id.clone();
|
||||
let (_, group) =
|
||||
find_surface_element(v.snapshot.as_ref().unwrap(), &selected).unwrap();
|
||||
assert!(group.locked_by_self);
|
||||
assert!(
|
||||
w.frame_snapshot()
|
||||
.elements
|
||||
.contains_key("chrome.edgeless_element_toolbar.unlock")
|
||||
);
|
||||
let undo = v.page_mut().unwrap().undo().unwrap().unwrap();
|
||||
v.did_edgeless_doc_commit(undo, cx);
|
||||
let snapshot = v.snapshot.as_ref().unwrap();
|
||||
assert!(find_surface_element(snapshot, &selected).is_none());
|
||||
assert!(
|
||||
!find_surface_element(snapshot, "shape-a")
|
||||
.unwrap()
|
||||
.1
|
||||
.locked_by_self
|
||||
);
|
||||
assert!(snapshot.block("note-main").is_some());
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn canvas_pan_hides_toolbar_and_dismisses_panels_without_clearing_selection() {
|
||||
use ui::{
|
||||
KeyDownEvent, KeyUpEvent, Keystroke, Modifiers, MouseButton, MouseDownEvent,
|
||||
MouseMoveEvent, MouseUpEvent, PlatformInput, point, px,
|
||||
};
|
||||
|
||||
let (platform, app, win, hw) = start_edgeless_toolbar_view();
|
||||
let toolbar = "chrome.edgeless_element_toolbar";
|
||||
let frame = || {
|
||||
platform.run_until_parked();
|
||||
hw.request_frame();
|
||||
app.update(|cx| win.update(cx, |_, w, _| w.frame_snapshot().clone()))
|
||||
.unwrap()
|
||||
};
|
||||
let space = || Keystroke {
|
||||
modifiers: Modifiers::default(),
|
||||
key: "space".into(),
|
||||
key_char: None,
|
||||
};
|
||||
for (button, action, panel) in [
|
||||
(
|
||||
MouseButton::Middle,
|
||||
EdgelessElementAction::ToggleColorPicker(ElementColorSlot::Fill),
|
||||
"color_picker",
|
||||
),
|
||||
(
|
||||
MouseButton::Left,
|
||||
EdgelessElementAction::ToggleSubMenu(ElementSubMenu::More),
|
||||
"more_menu",
|
||||
),
|
||||
] {
|
||||
app.update(|cx| {
|
||||
win.update(cx, |v, w, cx| {
|
||||
v.editor_focus.focus(w, cx);
|
||||
v.edgeless_set_selection(["shape-a".into()], cx);
|
||||
v.apply_edgeless_element_action(action, cx);
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
let panel = format!("{toolbar}.{panel}");
|
||||
assert!(frame().elements.contains_key(&panel));
|
||||
|
||||
if button == MouseButton::Left {
|
||||
hw.dispatch_input(PlatformInput::KeyDown(KeyDownEvent {
|
||||
keystroke: space(),
|
||||
is_held: false,
|
||||
prefer_character_input: false,
|
||||
}));
|
||||
}
|
||||
let start = point(px(90.0), px(490.0));
|
||||
let end = point(px(120.0), px(502.0));
|
||||
hw.dispatch_input(PlatformInput::MouseDown(MouseDownEvent {
|
||||
button,
|
||||
position: start,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
first_mouse: false,
|
||||
}));
|
||||
assert!(!frame().elements.contains_key(toolbar), "{button:?} down");
|
||||
hw.dispatch_input(PlatformInput::MouseMove(MouseMoveEvent {
|
||||
position: end,
|
||||
pressed_button: Some(button),
|
||||
modifiers: Modifiers::default(),
|
||||
}));
|
||||
let during = frame();
|
||||
assert!(!during.elements.contains_key(toolbar), "{button:?} drag");
|
||||
assert!(!during.elements.contains_key(&panel));
|
||||
hw.dispatch_input(PlatformInput::MouseUp(MouseUpEvent {
|
||||
button,
|
||||
position: end,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
}));
|
||||
if button == MouseButton::Left {
|
||||
hw.dispatch_input(PlatformInput::KeyUp(KeyUpEvent { keystroke: space() }));
|
||||
}
|
||||
let after = frame();
|
||||
assert!(after.elements.contains_key(toolbar), "{button:?} up");
|
||||
assert!(!after.elements.contains_key(&panel));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,18 @@
|
||||
//! Connector / Text / Frame items.
|
||||
|
||||
use blocksuite_playground_doc::read::{ColorValue, EndpointStyle, NoteDisplayMode, StrokeStyle};
|
||||
use ui::{Context, MouseDownEvent, Window};
|
||||
use ui::{AnyElement, Context, Pixels, Size, Window};
|
||||
use y_octo::{AHashMap, Any, SessionValue};
|
||||
|
||||
use crate::{PlaygroundView, theme::PlaygroundTheme};
|
||||
use crate::{
|
||||
PlaygroundView,
|
||||
block_flow::{FlowRect, FormFactor},
|
||||
theme::{Palette, PlaygroundTheme},
|
||||
};
|
||||
|
||||
use super::{
|
||||
DragItemInitial, EdgelessElementAction, EdgelessElementToolbarHost, EdgelessGesture,
|
||||
ElementColorSlot, ShapePreset, SpatialItemKind, element_toolbar_color::apply_color_to_element,
|
||||
DragItemInitial, EdgelessElementAction, EdgelessElementToolbarHost, ElementColorSlot,
|
||||
ShapePreset, SpatialItemKind, element_toolbar_color::apply_color_to_element,
|
||||
parse_custom_hex_color,
|
||||
};
|
||||
|
||||
@@ -114,39 +118,6 @@ impl EdgelessElementToolbarHost for PlaygroundView {
|
||||
}
|
||||
self.apply_edgeless_element_action(action, cx);
|
||||
}
|
||||
fn begin_element_toolbar_drag(
|
||||
&mut self,
|
||||
event: &MouseDownEvent,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if self.is_edgeless_write_readonly()
|
||||
|| !self
|
||||
.edgeless
|
||||
.authoring
|
||||
.single_selected()
|
||||
.is_some_and(|item| item.kind == SpatialItemKind::Shape && !item.locked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
self.editor_focus.focus(window, cx);
|
||||
self.dismiss_edgeless_element_popovers();
|
||||
let (origin, _) = self.canvas_rect(window);
|
||||
let world = self.edgeless.camera.screen_to_world(event.position, origin);
|
||||
let start = (f32::from(world.x), f32::from(world.y));
|
||||
let initial = self.collect_move_initials();
|
||||
if !initial.is_empty() {
|
||||
self.edgeless.authoring.gesture = Some(EdgelessGesture::DragSelection {
|
||||
start_world: start,
|
||||
current_world: start,
|
||||
initial,
|
||||
shift: event.modifiers.shift,
|
||||
alt_clone: event.modifiers.alt,
|
||||
pending_dblclick: None,
|
||||
});
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PlaygroundView {
|
||||
@@ -157,7 +128,36 @@ impl PlaygroundView {
|
||||
self.edgeless_shape_picker_presence = None;
|
||||
}
|
||||
|
||||
pub(super) fn sync_element_panel(&mut self, viewport: ui::Size<ui::Pixels>) {
|
||||
pub(super) fn render_element_toolbar(
|
||||
&mut self,
|
||||
viewport: Size<Pixels>,
|
||||
palette: &Palette,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<(AnyElement, Vec<FlowRect>)> {
|
||||
self.sync_element_panel(viewport);
|
||||
if self.edgeless_readonly
|
||||
|| self.form_factor == FormFactor::Phone
|
||||
|| self.edgeless.drag_pan_anchor.is_some()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
super::build_edgeless_element_toolbar(
|
||||
self.snapshot.as_ref()?,
|
||||
&self.edgeless.authoring,
|
||||
self.edgeless.camera,
|
||||
f32::from(viewport.width),
|
||||
f32::from(viewport.height),
|
||||
self.edgeless_element_color_picker(),
|
||||
palette,
|
||||
self.theme,
|
||||
|source_id| self.can_download_blob(source_id),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
|
||||
fn sync_element_panel(&mut self, viewport: ui::Size<ui::Pixels>) {
|
||||
let state = &self.edgeless.authoring;
|
||||
if state.open_sub_menu.is_none() && self.edgeless_element_color_picker.is_none() {
|
||||
self.edgeless.authoring.element_panel_anchor = None;
|
||||
@@ -169,6 +169,7 @@ impl PlaygroundView {
|
||||
.is_none_or(|(camera, selection)| {
|
||||
*camera != self.edgeless.camera || *selection != state.selection
|
||||
})
|
||||
|| self.edgeless.drag_pan_anchor.is_some()
|
||||
|| state.gesture.is_some()
|
||||
|| state.inline_edit.is_some()
|
||||
|| state.selection_world_aabb().is_none_or(|bounds| {
|
||||
|
||||
@@ -109,8 +109,6 @@ impl PlaygroundView {
|
||||
{
|
||||
super::sync_selection_from_snapshot(&mut self.edgeless.authoring, snap);
|
||||
}
|
||||
self.sync_element_panel(vp_size);
|
||||
let open_color_picker = self.edgeless_element_color_picker();
|
||||
let note_slicer = (toolbar_visible
|
||||
&& !self.is_page_write_readonly()
|
||||
&& self.edgeless.authoring.inline_edit.is_none()
|
||||
@@ -142,25 +140,7 @@ impl PlaygroundView {
|
||||
)
|
||||
})
|
||||
.flatten();
|
||||
let element_toolbar_built = (toolbar_visible
|
||||
&& !self.edgeless.authoring.selection.is_empty()
|
||||
&& self.form_factor != crate::block_flow::FormFactor::Phone)
|
||||
.then(|| {
|
||||
let snap = self.snapshot.as_ref()?;
|
||||
super::build_edgeless_element_toolbar(
|
||||
snap,
|
||||
&self.edgeless.authoring,
|
||||
self.edgeless.camera,
|
||||
viewport_width,
|
||||
viewport_height,
|
||||
open_color_picker,
|
||||
palette,
|
||||
self.theme,
|
||||
|source_id| self.can_download_blob(source_id),
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.flatten();
|
||||
let element_toolbar_built = self.render_element_toolbar(vp_size, palette, window, cx);
|
||||
let element_toolbar = if let Some((el, hitboxes)) = element_toolbar_built {
|
||||
self.edgeless.authoring.toolbar_hitboxes = hitboxes;
|
||||
Some(el)
|
||||
|
||||
Reference in new issue
Block a user