use super::*;
impl EuvMermaid {
#[must_use]
pub fn on_copy<CallbackFn>(mut self, handler: CallbackFn) -> Self
where
CallbackFn: Fn(&str) + 'static,
{
self.set_on_copy(Some(Rc::new(handler)));
self
}
}
#[component]
impl EuvMermaid {
fn render(&self) -> NodeId {
let ctx: Context = current_context();
bind_fullscreen_context(&ctx);
let base_tokens: ThemeTokens = self.get_tokens();
let tokens: ThemeTokens = live_tokens_untracked(base_tokens);
let geometry: ThemeGeometry = tokens.get_geometry();
let ctrl_sm: f32 = geometry.get_control_sm();
let eva: CodeThemePalette = CodeThemePalette::resolve(tokens.get_mode());
let Self {
source,
style,
on_copy,
..
} = self;
let diagram: Rc<MermaidDiagram> = Rc::new(parse_mermaid_diagram(source));
let nat_sz: Size = measure_mermaid_diagram(&diagram);
let badge: &'static str = mermaid_badge_label(&diagram);
let title_raw: String = mermaid_diagram_title(&diagram);
let header_title_rc: Option<Rc<str>> = if title_raw.is_empty() {
None
} else {
Some(Rc::from(title_raw))
};
let inline_max_h: f32 =
match style.map(|computed_style: Style| computed_style.get_layout().get_max_height()) {
Some(Length::Px(px)) if px > 0.0 => px,
_ => MERMAID_DEFAULT_MAX_HEIGHT,
};
let copied_sig: Signal<bool> = Signal::new(false);
let fs_open: Signal<bool> = Signal::new(false);
let source_rc: Rc<str> = Rc::from(source.as_str());
let copy_src: Rc<str> = Rc::clone(&source_rc);
let copy_cb: Option<MarkdownStrCallback> = on_copy.clone();
let ctx_copy: Context = ctx.clone();
let on_copy_click = move |_: &UiEvent| {
let _: bool = ctx_copy.copy_to_clipboard(©_src);
let _: bool = copied_sig.set(true);
if let Some(callback_fn) = copy_cb.as_ref() {
callback_fn(©_src);
}
};
let paint_inline_copy_icon = move |bounds: Rect, display_list: &mut DisplayList| {
let cur_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let cur_eva: CodeThemePalette = CodeThemePalette::resolve(cur_tok.get_mode());
if copied_sig.get_untracked() {
draw_euv_icon(
EuvIconName::Check,
bounds,
display_list,
cur_tok.get_palette().get_success(),
);
} else {
draw_euv_icon(
EuvIconName::Copy,
bounds,
display_list,
cur_eva.get_function(),
);
}
};
let on_open_fs = move |_: &UiEvent| {
let _: bool = fs_open.set_if_changed(true);
};
let diag_inline: Rc<MermaidDiagram> = Rc::clone(&diagram);
let inline_cache: RefCell<Option<(Rect, ThemeTokens, Vec<DrawCommand>)>> =
RefCell::new(None);
let paint_inline = move |bounds: Rect, draw_commands: &mut DisplayList| {
let live_tok: ThemeTokens = live_tokens_untracked(base_tokens);
if let Ok(guard) = inline_cache.try_borrow()
&& let Some((cached_bounds, cached_tok, cached_cmds)) = guard.as_ref()
&& *cached_bounds == bounds
&& *cached_tok == live_tok
{
draw_commands
.get_mut_commands()
.extend_from_slice(cached_cmds.as_slice());
return;
}
let mut scratch: DisplayList = DisplayList::default();
draw_mermaid_diagram(&diag_inline, bounds, &mut scratch, live_tok);
let cmds: Vec<DrawCommand> = take(scratch.get_mut_commands());
draw_commands
.get_mut_commands()
.extend_from_slice(cmds.as_slice());
if let Ok(mut guard) = inline_cache.try_borrow_mut() {
*guard = Some((bounds, live_tok, cmds));
}
};
let paint_fs_icon = move |bounds: Rect, command_list: &mut DisplayList| {
let live_eva: CodeThemePalette =
CodeThemePalette::resolve(live_tokens_untracked(base_tokens).get_mode());
draw_code_fullscreen_icon(bounds, command_list, live_eva.get_function());
};
let diag_fs: Rc<MermaidDiagram> = Rc::clone(&diagram);
let fs_src_copy: Rc<str> = Rc::clone(&source_rc);
let fs_cb_copy: Option<MarkdownStrCallback> = on_copy.clone();
let fs_title_rc: Option<Rc<str>> = header_title_rc.clone();
let ctx_fs_copy: Context = ctx.clone();
let build_fs_panel = move || -> NodeId {
let live_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let live_p: ThemePalette = live_tok.get_palette();
let live_g: ThemeGeometry = live_tok.get_geometry();
let modal_ctrl_h: f32 = live_g.get_control_sm();
let close_surface: SurfaceColors = live_p.surface(SurfaceRole::Primary);
let live_eva: CodeThemePalette = CodeThemePalette::resolve(live_tok.get_mode());
let diag_modal: Rc<MermaidDiagram> = Rc::clone(&diag_fs);
let modal_base_w: f32 = nat_sz.get_width().max(640.0);
let modal_base_h: f32 = nat_sz.get_height().max(320.0);
let zoom_sig: Signal<f32> = Signal::new(1.0);
let modal_cache: RefCell<Option<MermaidModalPaintEntry>> = RefCell::new(None);
let paint_modal = move |bounds: Rect, display_list_primary: &mut DisplayList| {
let cur_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let cur_zoom: f32 = zoom_sig.get_untracked();
let zoom_bits: u32 = cur_zoom.to_bits();
if let Ok(guard) = modal_cache.try_borrow()
&& let Some(cached) = guard.as_ref()
&& cached.bounds == bounds
&& cached.tokens == cur_tok
&& cached.zoom_bits == zoom_bits
{
display_list_primary
.get_mut_commands()
.extend_from_slice(cached.commands.as_slice());
return;
}
let mut scratch: DisplayList = DisplayList::default();
let base_rect: Rect =
Rect::new(bounds.get_x(), bounds.get_y(), modal_base_w, modal_base_h);
draw_mermaid_diagram(&diag_modal, base_rect, &mut scratch, cur_tok);
scale_mermaid_display_list(
scratch.get_mut_commands(),
Point::new(bounds.get_x(), bounds.get_y()),
cur_zoom,
);
let cmds: Vec<DrawCommand> = take(scratch.get_mut_commands());
display_list_primary
.get_mut_commands()
.extend_from_slice(cmds.as_slice());
if let Ok(mut guard) = modal_cache.try_borrow_mut() {
*guard = Some(MermaidModalPaintEntry {
bounds,
tokens: cur_tok,
zoom_bits,
commands: cmds,
});
}
};
let modal_src: Rc<str> = Rc::clone(&fs_src_copy);
let modal_cb: Option<MarkdownStrCallback> = fs_cb_copy.clone();
let ctx_m: Context = ctx_fs_copy.clone();
let modal_copy_icon_cell: Rc<Cell<NodeId>> = Rc::new(Cell::new(NodeId::default()));
let modal_copy_icon_cb: Rc<Cell<NodeId>> = Rc::clone(&modal_copy_icon_cell);
let modal_copy_btn_cell: Rc<Cell<NodeId>> = Rc::new(Cell::new(NodeId::default()));
let modal_copy_btn_cb: Rc<Cell<NodeId>> = Rc::clone(&modal_copy_btn_cell);
let on_modal_copy = move |_: &UiEvent| {
let _: bool = ctx_m.copy_to_clipboard(&modal_src);
let _: bool = copied_sig.set(true);
let m_icon: NodeId = modal_copy_icon_cb.get();
let m_btn: NodeId = modal_copy_btn_cb.get();
ctx_m.get_scene().with_write(
|tree: &mut SceneTree| {
if let Some(item_count) = tree.get_node_mut(m_btn) {
*item_count.get_mut_a11y() = Some(A11yProps::new(
A11yRole::Button,
MERMAID_BUTTON_COPIED.to_string(),
));
}
tree.mark_dirty(m_icon, DIRTY_PAINT);
},
(),
);
if let Some(handler_cb) = modal_cb.as_ref() {
handler_cb(&modal_src);
}
};
let paint_modal_copy_icon = move |bounds: Rect, draw_list: &mut DisplayList| {
let cur_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let cur_eva: CodeThemePalette = CodeThemePalette::resolve(cur_tok.get_mode());
if copied_sig.get_untracked() {
draw_euv_icon(
EuvIconName::Check,
bounds,
draw_list,
cur_tok.get_palette().get_success(),
);
} else {
draw_euv_icon(EuvIconName::Copy, bounds, draw_list, cur_eva.get_function());
}
};
let paint_close_icon = move |bounds: Rect, display_list_next: &mut DisplayList| {
let cur_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
let close_fg: Color = cur_p.surface(SurfaceRole::Primary).get_fg();
draw_euv_icon(EuvIconName::Minimize, bounds, display_list_next, close_fg);
};
let on_close_fs = move |_: &UiEvent| {
let _: bool = fs_open.set_if_changed(false);
};
let on_zoom_out = move |_: &UiEvent| {
let _: bool = {
if let Some(mut updated_value) = zoom_sig.try_get_untracked() {
{
let pos_z: &mut f32 = &mut updated_value;
*pos_z = (*pos_z - MERMAID_ZOOM_STEP)
.clamp(MERMAID_ZOOM_MIN, MERMAID_ZOOM_MAX);
}
zoom_sig.set(updated_value)
} else {
false
}
};
};
let on_zoom_in = move |_: &UiEvent| {
let _: bool = {
if let Some(mut updated_value) = zoom_sig.try_get_untracked() {
{
let coord_z: &mut f32 = &mut updated_value;
*coord_z = (*coord_z + MERMAID_ZOOM_STEP)
.clamp(MERMAID_ZOOM_MIN, MERMAID_ZOOM_MAX);
}
zoom_sig.set(updated_value)
} else {
false
}
};
};
let body_scroll_cell: Rc<Cell<NodeId>> = Rc::new(Cell::new(NodeId::default()));
let body_scroll_reset: Rc<Cell<NodeId>> = Rc::clone(&body_scroll_cell);
let scene_reset: SceneHandle = ctx_fs_copy.get_scene().clone();
let on_zoom_reset = move |_: &UiEvent| {
let _: bool = zoom_sig.set_if_changed(1.0);
let node_id: NodeId = body_scroll_reset.get();
scene_reset.with_write(
|tree: &mut SceneTree| {
tree.set_scroll_offset(node_id, Point::default());
},
(),
);
};
let init_copy_a11y: String = if copied_sig.get_untracked() {
MERMAID_BUTTON_COPIED.to_string()
} else {
MERMAID_BUTTON_COPY.to_string()
};
let modal_title_str: &str = fs_title_rc.as_deref().unwrap_or(badge);
let safe_sig: Signal<SafeAreaInsets> = ctx_fs_copy.get_safe_area();
let vp_sig: Signal<Size> = ctx_fs_copy.get_viewport_size();
let init_fs: FullscreenSafeLayout =
resolve_fullscreen_safe_layout(vp_sig.get_untracked(), safe_sig.get_untracked());
let init_body: Edges = init_fs.get_body_padding();
let mut modal_scroll_st: Style = Style::default();
modal_scroll_st
.get_mut_layout()
.set_flex_direction(FlexDirection::Column);
let mut top_bar_node: NodeId = NodeId::default();
let mut body_scroll_node: NodeId = NodeId::default();
let mut modal_canvas_node: NodeId = NodeId::default();
let mut zoom_reset_txt: NodeId = NodeId::default();
let mut modal_copy_btn: NodeId = NodeId::default();
let mut modal_copy_icon: NodeId = NodeId::default();
let column_secondary_style: Style = style! {
Width(Length::Percent(100.0))
Height(Length::Percent(100.0))
FlexGrow(1.0)
Padding(Edges::all(0.0))
Margin(Edges::all(0.0))
Background(live_eva.get_background())
Border::new(0.0, COLOR_TRANSPARENT)
Radius(0.0)
Overflow::Hidden
StopEventPropagation(true)
};
let row_sixth_style: Style = style! {
Width(Length::Percent(100.0))
FlexShrink(0.0)
Padding(init_fs.get_header_padding())
JustifyContent::SpaceBetween
AlignItems::Center
Gap(SPACE_SM)
Overflow::Hidden
Background(live_eva.get_header_bg())
};
let row_seventh_style: Style = style! {
FlexGrow(1.0)
FlexShrink(1.0)
MinWidth(Length::Px(0.0))
AlignItems::Center
Gap(SPACE_SM)
Overflow::Hidden
};
let row_eighth_style: Style = style! {
Height(Length::Px(modal_ctrl_h))
Padding(Edges::symmetric(0.0, SPACE_SM))
JustifyContent::Center
AlignItems::Center
Radius(live_g.get_radius_sm())
Overflow::Hidden
Background(live_eva.get_background())
Border::new(1.0, live_eva.get_border())
};
let text_tertiary_style: Style = style! {
FontSize(10.5)
FontWeight::Bold
TextColor(live_eva.get_keyword())
TextOverflow::Clip
};
let text_quaternary_style: Style = style! {
FlexShrink(1.0)
MinWidth(Length::Px(0.0))
Overflow::Hidden
TextOverflow::Ellipsis
FontSize(13.0)
FontWeight::SemiBold
TextColor(live_p.get_foreground())
};
let row_ninth_style: Style = style! {
FlexShrink(0.0)
AlignItems::Center
Gap(SPACE_XS)
};
let row_tenth_style: Style = style! {
Width(Length::Px(modal_ctrl_h))
Height(Length::Px(modal_ctrl_h))
JustifyContent::Center
AlignItems::Center
Radius(live_g.get_radius_sm())
Overflow::Hidden
CursorIcon::Pointer
Background(live_eva.get_background())
Border::new(1.0, live_eva.get_border())
};
let text_fifth_style: Style = style! {
FontSize(14.0)
FontWeight::Bold
TextColor(live_p.get_foreground())
TextOverflow::Clip
};
let row_eleventh_style: Style = style! {
Height(Length::Px(modal_ctrl_h))
Padding(Edges::symmetric(0.0, SPACE_SM))
JustifyContent::Center
AlignItems::Center
Radius(live_g.get_radius_sm())
Overflow::Hidden
CursorIcon::Pointer
Background(live_eva.get_background())
Border::new(1.0, live_eva.get_border())
};
let text_sixth_style: Style = style! {
FontSize(11.0)
FontFamily::Monospace
FontWeight::SemiBold
TextColor(live_p.get_foreground())
TextOverflow::Clip
};
let canvas_tertiary_style: Style = style! {
Width(Length::Px(14.0))
Height(Length::Px(14.0))
};
let row_twelfth_style: Style = style! {
Width(Length::Px(modal_ctrl_h))
Height(Length::Px(modal_ctrl_h))
JustifyContent::Center
AlignItems::Center
Radius(live_g.get_radius_sm())
Overflow::Hidden
CursorIcon::Pointer
Background(close_surface.get_bg())
};
let view_secondary_style: Style = style! {
Width(Length::Percent(100.0))
Height(Length::Px(1.0))
Background(live_eva.get_border())
};
let scroll_secondary_style: Style = style! {
modal_scroll_st
FlexGrow(1.0)
FlexShrink(1.0)
MinHeight(Length::Px(0.0))
Width(Length::Percent(100.0))
AlignItems::Start
Padding(Edges::new(
SPACE_MD,
SPACE_MD + init_body.get_right(),
SPACE_MD + init_body.get_bottom(),
SPACE_MD + init_body.get_left()
))
StopScrollPropagation(true)
};
let canvas_quaternary_style: Style = style! {
Width(Length::Px(modal_base_w))
Height(Length::Px(modal_base_h))
FlexShrink(0.0)
CursorIcon::Grab
};
let modal_panel: NodeId = view! {
column {
style: column_secondary_style
row {
node_ref: top_bar_node
style: row_sixth_style
row {
style: row_seventh_style
row {
style: row_eighth_style
text {
style: text_tertiary_style
{ badge }
}
}
text {
style: text_quaternary_style
{ modal_title_str }
}
}
row {
style: row_ninth_style
row {
style: row_tenth_style
role: A11yRole::Button
a11y_label: MERMAID_BUTTON_ZOOM_OUT.to_string()
on_click: on_zoom_out
text {
style: text_fifth_style
{ MERMAID_ZOOM_MINUS }
}
}
row {
style: row_eleventh_style
role: A11yRole::Button
a11y_label: MERMAID_BUTTON_ZOOM_RESET.to_string()
on_click: on_zoom_reset
text {
node_ref: zoom_reset_txt
style: text_sixth_style
{ MERMAID_ZOOM_INIT_LABEL }
}
}
row {
style: row_tenth_style
role: A11yRole::Button
a11y_label: MERMAID_BUTTON_ZOOM_IN.to_string()
on_click: on_zoom_in
text {
style: text_fifth_style
{ MERMAID_ZOOM_PLUS }
}
}
row {
node_ref: modal_copy_btn
style: row_tenth_style
role: A11yRole::Button
a11y_label: init_copy_a11y
on_click: on_modal_copy
canvas {
node_ref: modal_copy_icon
style: canvas_tertiary_style
painter: paint_modal_copy_icon
}
}
row {
style: row_twelfth_style
role: A11yRole::Button
a11y_label: MERMAID_BUTTON_CLOSE.to_string()
on_click: on_close_fs
canvas {
style: canvas_tertiary_style
painter: paint_close_icon
}
}
}
}
view {
style: view_secondary_style
}
scroll {
node_ref: body_scroll_node
style: scroll_secondary_style
canvas {
node_ref: modal_canvas_node
style: canvas_quaternary_style
painter: paint_modal
}
}
}
};
body_scroll_cell.set(body_scroll_node);
let handle_safe: SceneHandle = ctx_fs_copy.get_scene().clone();
let handle_zoom: SceneHandle = handle_safe.clone();
let (safe_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
let _: Effect = Effect::new(move || {
let depth_z: f32 = zoom_sig.get();
let next_w: f32 = (modal_base_w * depth_z).max(240.0);
let next_h: f32 = (modal_base_h * depth_z).max(160.0);
if !fs_open.get_untracked() {
return;
}
let pct_label: String = format!("{}%", (depth_z * 100.0).round() as u32);
handle_zoom.with_write(
|tree: &mut SceneTree| {
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
if let Some(node_entry) = tree.get_node_mut(modal_canvas_node) {
let lay: &mut LayoutStyle =
node_entry.get_mut_style().get_mut_layout();
lay.set_width(Length::Px(next_w))
.set_height(Length::Px(next_h));
tree.mark_dirty(modal_canvas_node, dirty_l | DIRTY_PAINT);
}
tree.set_text(zoom_reset_txt, pct_label);
},
(),
);
});
Effect::new(move || {
let fs_lay: FullscreenSafeLayout =
resolve_fullscreen_safe_layout(vp_sig.get(), safe_sig.get());
let fs_body: Edges = fs_lay.get_body_padding();
handle_safe.with_write(
|tree: &mut SceneTree| {
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
if let Some(normal_vec) = tree.get_node_mut(top_bar_node) {
normal_vec
.get_mut_style()
.get_mut_layout()
.set_padding(fs_lay.get_header_padding());
tree.mark_dirty(top_bar_node, dirty_l | DIRTY_PAINT);
}
if let Some(total_len) = tree.get_node_mut(body_scroll_node) {
total_len
.get_mut_style()
.get_mut_layout()
.set_padding(Edges::new(
SPACE_MD,
SPACE_MD + fs_body.get_right(),
SPACE_MD + fs_body.get_bottom(),
SPACE_MD + fs_body.get_left(),
));
tree.mark_dirty(body_scroll_node, dirty_l | DIRTY_PAINT);
}
},
(),
);
})
});
ctx_fs_copy.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_scope(modal_panel, safe_scope);
},
(),
);
modal_copy_btn_cell.set(modal_copy_btn);
modal_copy_icon_cell.set(modal_copy_icon);
modal_panel
};
let mut fs_portal: NodeId = NodeId::default();
let mut inline_copy_btn: NodeId = NodeId::default();
let mut inline_copy_icon: NodeId = NodeId::default();
let mut inline_scroll_st: Style = Style::default();
inline_scroll_st
.get_mut_layout()
.set_flex_direction(FlexDirection::Column);
let column_style: Style = style! {
Width(Length::Percent(100.0))
Background(eva.get_background())
Border::new(1.0, eva.get_border())
Radius(geometry.get_radius_lg())
Overflow::Hidden
};
let row_style: Style = style! {
Width(Length::Percent(100.0))
Padding(Edges::symmetric(SPACE_SM, SPACE_MD))
JustifyContent::SpaceBetween
AlignItems::Center
Gap(SPACE_SM)
Overflow::Hidden
Background(eva.get_header_bg())
};
let row_secondary_style: Style = style! {
FlexGrow(1.0)
FlexShrink(1.0)
MinWidth(Length::Px(0.0))
AlignItems::Center
Gap(SPACE_SM)
Overflow::Hidden
};
let row_tertiary_style: Style = style! {
FlexShrink(0.0)
Height(Length::Px(ctrl_sm))
Padding(Edges::symmetric(0.0, SPACE_SM))
JustifyContent::Center
AlignItems::Center
Radius(geometry.get_radius_sm())
Overflow::Hidden
Background(eva.get_background())
Border::new(1.0, eva.get_border())
};
let text_style: Style = style! {
FontSize(10.5)
FontWeight::Bold
TextColor(eva.get_keyword())
TextOverflow::Clip
};
let text_secondary_style: Style = style! {
FlexGrow(1.0)
FlexShrink(1.0)
MinWidth(Length::Px(0.0))
Overflow::Hidden
TextOverflow::Ellipsis
FontSize(12.0)
FontWeight::SemiBold
TextColor(eva.get_foreground())
};
let row_quaternary_style: Style = style! {
FlexShrink(0.0)
AlignItems::Center
Gap(SPACE_XS)
};
let row_fifth_style: Style = style! {
Width(Length::Px(ctrl_sm))
Height(Length::Px(ctrl_sm))
Radius(geometry.get_radius_sm())
Overflow::Hidden
JustifyContent::Center
AlignItems::Center
CursorIcon::Pointer
Background(eva.get_background())
Border::new(1.0, eva.get_border())
};
let canvas_style: Style = style! {
Width(Length::Px(13.0))
Height(Length::Px(13.0))
};
let view_style: Style = style! {
Width(Length::Percent(100.0))
Height(Length::Px(1.0))
Background(eva.get_border())
};
let scroll_style: Style = style! {
inline_scroll_st
Width(Length::Percent(100.0))
MaxHeight(Length::Px(inline_max_h))
AlignItems::Start
};
let canvas_secondary_style: Style = style! {
Width(Length::Px(nat_sz.get_width()))
Height(Length::Px(nat_sz.get_height()))
FlexShrink(0.0)
CursorIcon::Grab
};
let portal_style: Style = style! {
FlexDirection::Column
Display::None
Position::Fixed
Inset(Some(0.0), Some(0.0), Some(0.0), Some(0.0))
Width(Length::Percent(100.0))
Height(Length::Percent(100.0))
Padding(Edges::all(0.0))
Margin(Edges::all(0.0))
JustifyContent::Start
AlignItems::Stretch
Background(eva.get_background())
Border::new(0.0, COLOR_TRANSPARENT)
Radius(0.0)
Overflow::Hidden
PointerEvents::None
StopScrollPropagation(true)
StopEventPropagation(true)
ZIndex(Z_INDEX_FULLSCREEN)
};
let root: NodeId = view! {
column {
style: column_style
row {
style: row_style
row {
style: row_secondary_style
row {
style: row_tertiary_style
text {
style: text_style
{ badge }
}
}
if let Some(title_text) = header_title_rc.as_deref() {
text {
style: text_secondary_style
{ title_text }
}
}
}
row {
style: row_quaternary_style
row {
style: row_fifth_style
role: A11yRole::Button
a11y_label: MERMAID_BUTTON_FULLSCREEN.to_string()
on_click: on_open_fs
canvas {
style: canvas_style
painter: paint_fs_icon
}
}
row {
node_ref: inline_copy_btn
style: row_fifth_style
role: A11yRole::Button
a11y_label: MERMAID_BUTTON_COPY.to_string()
on_click: on_copy_click
canvas {
node_ref: inline_copy_icon
style: canvas_style
painter: paint_inline_copy_icon
}
}
}
}
view {
style: view_style
}
scroll {
style: scroll_style
canvas {
style: canvas_secondary_style
painter: paint_inline
}
}
portal {
node_ref: fs_portal
style: portal_style
}
}
};
let handle: SceneHandle = ctx.get_scene().clone();
let handle_copy: SceneHandle = handle.clone();
let ctx_build: Context = ctx.clone();
let prev_open: Rc<Cell<bool>> = Rc::new(Cell::new(false));
let fs_acquired: Rc<Cell<bool>> = Rc::new(Cell::new(false));
let fs_cleanup: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
on_cleanup(move || {
if fs_cleanup.replace(false) {
exit_fullscreen();
}
});
let _: Effect = Effect::new(move || {
let is_copied: bool = copied_sig.get();
let next_label: &str = if is_copied {
MERMAID_BUTTON_COPIED
} else {
MERMAID_BUTTON_COPY
};
handle_copy.with_write(
|tree: &mut SceneTree| {
if let Some(item_count_primary) = tree.get_node_mut(inline_copy_btn) {
*item_count_primary.get_mut_a11y() =
Some(A11yProps::new(A11yRole::Button, next_label.to_string()));
}
tree.mark_dirty(inline_copy_icon, DIRTY_PAINT);
},
(),
);
});
let _: Effect = EuvOverlayStack::bind_signal(
fs_open,
MERMAID_FULLSCREEN_OVERLAY_NAME,
Z_INDEX_FULLSCREEN,
);
let vp_sig: Signal<Size> = ctx_build.get_viewport_size();
let handle_vp: SceneHandle = handle.clone();
let _: Effect = Effect::new(move || {
let box_size: Size = vp_sig.get();
if !fs_open.get() {
return;
}
let vw: f32 = box_size.get_width().max(1.0);
let vh: f32 = box_size.get_height().max(1.0);
handle_vp.with_write(
|scene_tree: &mut SceneTree| {
if let Some(item_count_secondary) = scene_tree.get_node_mut(fs_portal) {
item_count_secondary
.get_mut_style()
.get_mut_layout()
.set_width(Length::Px(vw))
.set_height(Length::Px(vh));
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
scene_tree.mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
notify_frame_needed();
}
},
(),
);
});
let in_enter_guard: Rc<Cell<bool>> = Rc::new(Cell::new(false));
let global_fs_sig: Signal<bool> = use_fullscreen_active();
let ctx_fs_sig: Signal<bool> = ctx_build.immersive_fullscreen_signal();
let saw_global_fs: Rc<Cell<bool>> = Rc::new(Cell::new(false));
let saw_ctx_fs: Rc<Cell<bool>> = Rc::new(Cell::new(false));
let saw_global_reset: Rc<Cell<bool>> = Rc::clone(&saw_global_fs);
let saw_ctx_reset: Rc<Cell<bool>> = Rc::clone(&saw_ctx_fs);
let fs_acquired_sync: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
let enter_guard_sync: Rc<Cell<bool>> = Rc::clone(&in_enter_guard);
let _: Effect = Effect::new(move || {
let g_active: bool = global_fs_sig.get();
let c_active: bool = ctx_fs_sig.get();
if enter_guard_sync.get() {
if g_active {
saw_global_fs.set(true);
}
if c_active {
saw_ctx_fs.set(true);
}
return;
}
if !fs_acquired_sync.get() {
saw_global_fs.set(false);
saw_ctx_fs.set(false);
return;
}
if g_active {
saw_global_fs.set(true);
}
if c_active {
saw_ctx_fs.set(true);
}
let external_exit: bool =
(saw_global_fs.get() && !g_active) || (saw_ctx_fs.get() && !c_active);
if external_exit {
let _: bool = fs_open.set_if_changed(false);
}
});
Effect::new(move || {
let is_open: bool = fs_open.get();
if is_open == prev_open.replace(is_open) {
return;
}
if is_open {
in_enter_guard.set(true);
saw_global_reset.set(false);
saw_ctx_reset.set(false);
let live_eva: CodeThemePalette =
CodeThemePalette::resolve(live_tokens_untracked(base_tokens).get_mode());
let vp_now: Size = vp_sig.get_untracked();
let vw: f32 = vp_now.get_width().max(1.0);
let vh: f32 = vp_now.get_height().max(1.0);
let modal_panel: NodeId = with_context(ctx_build.clone(), &build_fs_panel);
let portal_shown: bool = modal_panel != NodeId::default()
&& handle.with_write(
|tree: &mut SceneTree| {
if tree.get_node(fs_portal).is_none()
|| tree.get_node(modal_panel).is_none()
{
return false;
}
tree.cancel_subtree_transitions(fs_portal);
tree.replace_children(fs_portal, vec![modal_panel]);
if let Some(item_count_next) = tree.get_node_mut(fs_portal) {
let element_style: &mut Style = item_count_next.get_mut_style();
element_style
.get_mut_layout()
.set_display(Display::Flex)
.set_width(Length::Px(vw))
.set_height(Length::Px(vh));
element_style
.get_mut_paint()
.set_background(Some(live_eva.get_background()))
.set_pointer_events(PointerEvents::Auto)
.set_opacity(1.0)
.set_transform(Transform2D::default());
}
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
tree.mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
notify_frame_needed();
true
},
false,
);
let entered: bool = portal_shown
&& (fs_acquired.get()
|| enter_fullscreen_for_portal(&ctx_build, fs_portal));
if entered {
fs_acquired.set(true);
} else {
handle.dismiss_portal_immediate(fs_portal);
if fs_acquired.replace(false) {
exit_fullscreen();
}
prev_open.set(false);
let _: bool = fs_open.set_if_changed(false);
}
in_enter_guard.set(false);
notify_frame_needed();
} else {
in_enter_guard.set(false);
if fs_acquired.replace(false) {
exit_fullscreen();
}
handle.dismiss_portal_immediate(fs_portal);
}
})
});
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_scope(root, scope);
},
(),
);
root
}
}