refactor: inline intermediate element builders in render methods
This commit is contained in:
@@ -119,18 +119,6 @@ impl Render for AppRoot {
|
||||
let workspace = self.workspace.read(cx);
|
||||
let main = workspace.active_main();
|
||||
|
||||
let prefix = h_flex()
|
||||
.gap_1()
|
||||
.child(titlebar_view.render_new_repository())
|
||||
.child(titlebar_view.render_explore())
|
||||
.child(titlebar_view.repository_switcher());
|
||||
|
||||
let tab_bar = h_flex()
|
||||
.gap_1()
|
||||
.when_some(titlebar_view.render_repo_tabs(workspace), |bar, tabs| {
|
||||
bar.child(tabs)
|
||||
});
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.size_full()
|
||||
@@ -151,8 +139,17 @@ impl Render for AppRoot {
|
||||
Shell::new("signed-shell")
|
||||
.titlebar(
|
||||
Titlebar::new("signed-titlebar")
|
||||
.prefix(prefix)
|
||||
.tab_bar(tab_bar)
|
||||
.prefix(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.child(titlebar_view.render_new_repository())
|
||||
.child(titlebar_view.render_explore())
|
||||
.child(titlebar_view.repository_switcher()),
|
||||
)
|
||||
.tab_bar(h_flex().gap_1().when_some(
|
||||
titlebar_view.render_repo_tabs(workspace),
|
||||
|bar, tabs| bar.child(tabs),
|
||||
))
|
||||
.when_some(titlebar_view.render_user_menu(cx), |titlebar, menu| {
|
||||
titlebar.suffix(menu)
|
||||
}),
|
||||
|
||||
@@ -165,12 +165,6 @@ impl Render for RepositorySwitcher {
|
||||
let list_weak = row_weak.clone();
|
||||
let list_on_open = on_open.clone();
|
||||
let list_scroll_handle = scroll_handle.clone();
|
||||
let create_hint = Kbd::binding_for_action(
|
||||
&CreateRepository,
|
||||
Some(REPOSITORY_KEY_CONTEXT),
|
||||
window,
|
||||
);
|
||||
|
||||
v_flex()
|
||||
.w(px(380.))
|
||||
.p_2()
|
||||
@@ -265,7 +259,14 @@ impl Render for RepositorySwitcher {
|
||||
.full_width(true)
|
||||
.icon(Icon::named(IconRole::CirclePlus))
|
||||
.child(div().flex_1().child("Create Repository"))
|
||||
.when_some(create_hint, |button, hint| button.child(hint))
|
||||
.when_some(
|
||||
Kbd::binding_for_action(
|
||||
&CreateRepository,
|
||||
Some(REPOSITORY_KEY_CONTEXT),
|
||||
window,
|
||||
),
|
||||
|button, hint| button.child(hint),
|
||||
)
|
||||
.on_click(move |_, window, cx| {
|
||||
log_dropped(create_weak.update(cx, |this, cx| {
|
||||
this.close(cx);
|
||||
|
||||
@@ -213,7 +213,8 @@ impl Render for Workspace {
|
||||
.gap_2()
|
||||
.when(self.details.len() > 1, |this| {
|
||||
let close_weak = weak.clone();
|
||||
let tabs = Tabs::new("signed-detail-tabs")
|
||||
this.child(
|
||||
Tabs::new("signed-detail-tabs")
|
||||
.variant(TabsVariant::Pill)
|
||||
.overflow_scroll(true)
|
||||
.selected(selected)
|
||||
@@ -235,8 +236,8 @@ impl Render for Workspace {
|
||||
log_dropped(close_weak.update(cx, |workspace, cx| {
|
||||
workspace.close_detail_at(index, cx);
|
||||
}));
|
||||
});
|
||||
this.child(tabs)
|
||||
}),
|
||||
)
|
||||
})
|
||||
.child(div().flex_1().min_h_0().w_full().children(body))
|
||||
}
|
||||
|
||||
@@ -437,36 +437,6 @@ impl Render for CodeViewState {
|
||||
let bounds_cell: std::rc::Rc<std::cell::RefCell<Option<Bounds<Pixels>>>> =
|
||||
std::rc::Rc::new(std::cell::RefCell::new(None));
|
||||
|
||||
let rows = uniform_list((id.clone(), "rows"), line_count, {
|
||||
let id = id.clone();
|
||||
let state = state.clone();
|
||||
move |range, _window, cx| {
|
||||
let code = state.read(cx);
|
||||
let active_line = code.active_line;
|
||||
let theme = cx.theme();
|
||||
|
||||
range
|
||||
.map(|line_ix| {
|
||||
code.render_row(
|
||||
&id,
|
||||
line_ix,
|
||||
active_line == Some(line_ix),
|
||||
selection,
|
||||
theme.mono_font,
|
||||
theme.colors,
|
||||
theme.ramps,
|
||||
text_size,
|
||||
line_height,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
})
|
||||
.track_scroll(&self.handle)
|
||||
.h_full()
|
||||
.w_full();
|
||||
|
||||
div()
|
||||
.id((id.clone(), "view"))
|
||||
.relative()
|
||||
@@ -596,7 +566,37 @@ impl Render for CodeViewState {
|
||||
.absolute()
|
||||
.inset_0(),
|
||||
)
|
||||
.child(rows)
|
||||
.child(
|
||||
uniform_list((id.clone(), "rows"), line_count, {
|
||||
let id = id.clone();
|
||||
let state = state.clone();
|
||||
move |range, _window, cx| {
|
||||
let code = state.read(cx);
|
||||
let active_line = code.active_line;
|
||||
let theme = cx.theme();
|
||||
|
||||
range
|
||||
.map(|line_ix| {
|
||||
code.render_row(
|
||||
&id,
|
||||
line_ix,
|
||||
active_line == Some(line_ix),
|
||||
selection,
|
||||
theme.mono_font,
|
||||
theme.colors,
|
||||
theme.ramps,
|
||||
text_size,
|
||||
line_height,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
})
|
||||
.track_scroll(&self.handle)
|
||||
.h_full()
|
||||
.w_full(),
|
||||
)
|
||||
.child(
|
||||
Scrollbar::vertical((self.id.clone(), "v-scrollbar"), self.handle.clone())
|
||||
.visibility(ScrollbarVisibility::Platform),
|
||||
|
||||
@@ -428,37 +428,6 @@ where
|
||||
let state = cx.entity();
|
||||
let open = self.highlight.is_some();
|
||||
|
||||
let chevron = h_flex()
|
||||
.id((id.clone(), "chevron"))
|
||||
.cursor_pointer()
|
||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
||||
.on_click({
|
||||
let state = state.clone();
|
||||
move |_, window, cx| {
|
||||
let focus = state.read(cx).query.read(cx).focus_handle();
|
||||
window.focus(&focus, cx);
|
||||
state.update(cx, |state, cx| {
|
||||
if state.highlight.is_some() {
|
||||
state.highlight = None;
|
||||
} else {
|
||||
if state.selected.is_some() {
|
||||
state.refilter("");
|
||||
} else {
|
||||
let query = state.query.read(cx).value().to_string();
|
||||
state.refilter(&query);
|
||||
}
|
||||
state.highlight = Some(0);
|
||||
}
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
})
|
||||
.child(
|
||||
icon(IconRole::ChevronDown)
|
||||
.size(self.size.dense_icon_rems())
|
||||
.color(colors.muted_foreground),
|
||||
);
|
||||
|
||||
let wrapper_bounds: Rc<RefCell<Option<Bounds<Pixels>>>> = Rc::new(RefCell::new(None));
|
||||
|
||||
div()
|
||||
@@ -525,7 +494,39 @@ where
|
||||
.top_0()
|
||||
.bottom_0()
|
||||
.items_center()
|
||||
.child(chevron),
|
||||
.child(
|
||||
h_flex()
|
||||
.id((id.clone(), "chevron"))
|
||||
.cursor_pointer()
|
||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
||||
.on_click({
|
||||
let state = state.clone();
|
||||
move |_, window, cx| {
|
||||
let focus = state.read(cx).query.read(cx).focus_handle();
|
||||
window.focus(&focus, cx);
|
||||
state.update(cx, |state, cx| {
|
||||
if state.highlight.is_some() {
|
||||
state.highlight = None;
|
||||
} else {
|
||||
if state.selected.is_some() {
|
||||
state.refilter("");
|
||||
} else {
|
||||
let query =
|
||||
state.query.read(cx).value().to_string();
|
||||
state.refilter(&query);
|
||||
}
|
||||
state.highlight = Some(0);
|
||||
}
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
})
|
||||
.child(
|
||||
icon(IconRole::ChevronDown)
|
||||
.size(self.size.dense_icon_rems())
|
||||
.color(colors.muted_foreground),
|
||||
),
|
||||
),
|
||||
)
|
||||
.when(open, |wrapper| {
|
||||
let visible = self.visible.clone();
|
||||
@@ -633,7 +634,9 @@ where
|
||||
.map(|bounds| bounds.size.width)
|
||||
.unwrap_or(COMBOBOX_WIDTH);
|
||||
|
||||
let panel = floating_panel(
|
||||
wrapper.child(crate::components::menu::anchored_overlay(
|
||||
None,
|
||||
floating_panel(
|
||||
cx,
|
||||
radius.overlay,
|
||||
v_flex()
|
||||
@@ -668,12 +671,14 @@ where
|
||||
if phase != gpui::DispatchPhase::Bubble {
|
||||
return;
|
||||
}
|
||||
let on_panel = panel_bounds
|
||||
.borrow()
|
||||
.is_some_and(|bounds| bounds.contains(&event.position));
|
||||
let on_wrapper = wrapper_bounds
|
||||
.borrow()
|
||||
.is_some_and(|bounds| bounds.contains(&event.position));
|
||||
let on_panel =
|
||||
panel_bounds.borrow().is_some_and(|bounds| {
|
||||
bounds.contains(&event.position)
|
||||
});
|
||||
let on_wrapper =
|
||||
wrapper_bounds.borrow().is_some_and(|bounds| {
|
||||
bounds.contains(&event.position)
|
||||
});
|
||||
if on_panel || on_wrapper {
|
||||
return;
|
||||
}
|
||||
@@ -688,11 +693,8 @@ where
|
||||
)
|
||||
.absolute()
|
||||
.inset_0(),
|
||||
);
|
||||
|
||||
wrapper.child(crate::components::menu::anchored_overlay(
|
||||
None,
|
||||
panel.into_any_element(),
|
||||
)
|
||||
.into_any_element(),
|
||||
None,
|
||||
))
|
||||
})
|
||||
|
||||
@@ -30,8 +30,8 @@ use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
AnyElement, App, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding,
|
||||
MouseButton, ParentElement as _, Render, Role, SharedString, StatefulInteractiveElement as _,
|
||||
StyleRefinement, Styled as _, Subscription, UniformListScrollHandle, Window, actions,
|
||||
deferred, div, relative, rems, uniform_list,
|
||||
StyleRefinement, Styled as _, Subscription, UniformListScrollHandle, Window, actions, deferred,
|
||||
div, relative, rems, uniform_list,
|
||||
};
|
||||
|
||||
use crate::components::common::{
|
||||
@@ -459,7 +459,30 @@ impl Render for CommandPaletteState {
|
||||
.into_any_element()
|
||||
};
|
||||
|
||||
let panel = floating_panel(
|
||||
deferred(
|
||||
div()
|
||||
.absolute()
|
||||
.inset_0()
|
||||
.flex()
|
||||
.justify_center()
|
||||
.items_start()
|
||||
.pt(titlebar_height)
|
||||
.child(
|
||||
div()
|
||||
.absolute()
|
||||
.inset_0()
|
||||
.bg(colors.overlay)
|
||||
.occlude()
|
||||
.on_mouse_down(MouseButton::Left, {
|
||||
let state = state.clone();
|
||||
move |_, _window, cx| {
|
||||
state.update(cx, |state, cx| state.close(cx));
|
||||
cx.stop_propagation();
|
||||
}
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
floating_panel(
|
||||
cx,
|
||||
radius.overlay,
|
||||
v_flex()
|
||||
@@ -513,31 +536,8 @@ impl Render for CommandPaletteState {
|
||||
.child(crate::components::menu::focus_capture(
|
||||
query_focus.clone(),
|
||||
move |window, cx| !query_focus.contains_focused(window, cx),
|
||||
));
|
||||
|
||||
let scrim = div()
|
||||
.absolute()
|
||||
.inset_0()
|
||||
.bg(colors.overlay)
|
||||
.occlude()
|
||||
.on_mouse_down(MouseButton::Left, {
|
||||
let state = state.clone();
|
||||
move |_, _window, cx| {
|
||||
state.update(cx, |state, cx| state.close(cx));
|
||||
cx.stop_propagation();
|
||||
}
|
||||
});
|
||||
|
||||
deferred(
|
||||
div()
|
||||
.absolute()
|
||||
.inset_0()
|
||||
.flex()
|
||||
.justify_center()
|
||||
.items_start()
|
||||
.pt(titlebar_height)
|
||||
.child(scrim)
|
||||
.child(panel),
|
||||
)),
|
||||
),
|
||||
)
|
||||
.with_priority(DIALOG_LAYER)
|
||||
.into_any_element()
|
||||
|
||||
@@ -324,7 +324,28 @@ impl RenderOnce for DropdownMenu {
|
||||
})
|
||||
};
|
||||
|
||||
let chevron_zone = h_flex()
|
||||
let trigger = h_flex()
|
||||
.debug_selector({
|
||||
let id = self.id.clone();
|
||||
move || format!("{id}-trigger")
|
||||
})
|
||||
.control_height(self.size)
|
||||
.when(icon_only, |trigger| trigger.control_width(self.size))
|
||||
.rounded(radius)
|
||||
.border_1()
|
||||
.border_color(border)
|
||||
.when_some(background, |trigger, background| trigger.bg(background))
|
||||
.when(self.disabled, |trigger| trigger.opacity(DISABLED_OPACITY))
|
||||
.when(!inert, |trigger| {
|
||||
trigger
|
||||
.track_focus(&focus)
|
||||
.focus_visible(move |style| style.shadow(focus_ring(ring)))
|
||||
})
|
||||
.child(main);
|
||||
|
||||
let trigger = if split {
|
||||
trigger.child(
|
||||
h_flex()
|
||||
.id((self.id.clone(), "chevron"))
|
||||
.debug_selector({
|
||||
let id = self.id.clone();
|
||||
@@ -358,29 +379,8 @@ impl RenderOnce for DropdownMenu {
|
||||
)
|
||||
.absolute()
|
||||
.inset_0(),
|
||||
);
|
||||
|
||||
let trigger = h_flex()
|
||||
.debug_selector({
|
||||
let id = self.id.clone();
|
||||
move || format!("{id}-trigger")
|
||||
})
|
||||
.control_height(self.size)
|
||||
.when(icon_only, |trigger| trigger.control_width(self.size))
|
||||
.rounded(radius)
|
||||
.border_1()
|
||||
.border_color(border)
|
||||
.when_some(background, |trigger, background| trigger.bg(background))
|
||||
.when(self.disabled, |trigger| trigger.opacity(DISABLED_OPACITY))
|
||||
.when(!inert, |trigger| {
|
||||
trigger
|
||||
.track_focus(&focus)
|
||||
.focus_visible(move |style| style.shadow(focus_ring(ring)))
|
||||
})
|
||||
.child(main);
|
||||
|
||||
let trigger = if split {
|
||||
trigger.child(chevron_zone)
|
||||
),
|
||||
)
|
||||
} else {
|
||||
trigger
|
||||
};
|
||||
|
||||
@@ -1459,7 +1459,13 @@ fn text_row(
|
||||
block_frame(quote, Rems::ZERO, bottom, ctx.block_id, cx).map(|frame| match marker {
|
||||
Some(marker) => {
|
||||
let line_height = rems(1.2);
|
||||
let marker_cell = div()
|
||||
|
||||
frame.child(
|
||||
div()
|
||||
.flex()
|
||||
.items_start()
|
||||
.child(
|
||||
div()
|
||||
.flex_none()
|
||||
.w(rems(1.75))
|
||||
.h(line_height)
|
||||
@@ -1478,11 +1484,12 @@ fn text_row(
|
||||
.whitespace_nowrap()
|
||||
.child(format!("{number}."))
|
||||
.into_any_element(),
|
||||
ListMarker::Task(checked) => task_toggle(checked, item_text(items), ctx),
|
||||
});
|
||||
|
||||
frame.child(
|
||||
div().flex().items_start().child(marker_cell).child(
|
||||
ListMarker::Task(checked) => {
|
||||
task_toggle(checked, item_text(items), ctx)
|
||||
}
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
@@ -1622,7 +1629,20 @@ fn code_row(
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
let actions_row = h_flex()
|
||||
indented_frame(
|
||||
indent,
|
||||
block_frame(quote, Rems::ZERO, rems(0.75), ctx.block_id, cx).child(
|
||||
v_flex()
|
||||
.w_full()
|
||||
.rounded(theme.radius.control)
|
||||
.bg(theme.colors.muted)
|
||||
.p_2()
|
||||
.font_family(theme.mono_font)
|
||||
.text_xs()
|
||||
.line_height(relative(CODE_LINE_HEIGHT))
|
||||
.overflow_hidden()
|
||||
.child(
|
||||
h_flex()
|
||||
.justify_between()
|
||||
.pb_1()
|
||||
.when_some(language.cloned(), |row, language| {
|
||||
@@ -1641,18 +1661,8 @@ fn code_row(
|
||||
.on_click(move |_, _, cx| {
|
||||
cx.write_to_clipboard(ClipboardItem::new_string(plain.clone()));
|
||||
}),
|
||||
);
|
||||
|
||||
let plate = v_flex()
|
||||
.w_full()
|
||||
.rounded(theme.radius.control)
|
||||
.bg(theme.colors.muted)
|
||||
.p_2()
|
||||
.font_family(theme.mono_font)
|
||||
.text_xs()
|
||||
.line_height(relative(CODE_LINE_HEIGHT))
|
||||
.overflow_hidden()
|
||||
.child(actions_row)
|
||||
),
|
||||
)
|
||||
.children(lines.lines.iter().enumerate().map(|(line_ix, line)| {
|
||||
let styled = code_line(line, theme.colors, theme.ramps);
|
||||
let layout = styled.layout().clone();
|
||||
@@ -1665,11 +1675,8 @@ fn code_row(
|
||||
ctx.piece_context(line_ix),
|
||||
layout,
|
||||
)
|
||||
}));
|
||||
|
||||
indented_frame(
|
||||
indent,
|
||||
block_frame(quote, Rems::ZERO, rems(0.75), ctx.block_id, cx).child(plate),
|
||||
})),
|
||||
),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
@@ -1702,7 +1709,10 @@ fn table_row(
|
||||
let row_count = table.rows.len();
|
||||
let mut cell_ix = 0usize;
|
||||
|
||||
let grid = v_flex()
|
||||
indented_frame(
|
||||
indent,
|
||||
block_frame(quote, Rems::ZERO, rems(0.75), ctx.block_id, cx).child(
|
||||
v_flex()
|
||||
.w_full()
|
||||
.border_1()
|
||||
.border_color(colors.border)
|
||||
@@ -1732,7 +1742,9 @@ fn table_row(
|
||||
.min_w_0()
|
||||
.px_2()
|
||||
.py_1()
|
||||
.when(row.header, |cell_element| cell_element.font_semibold())
|
||||
.when(row.header, |cell_element| {
|
||||
cell_element.font_semibold()
|
||||
})
|
||||
.child(text_child(&cell.spans, &cell_id, piece, cx))
|
||||
})
|
||||
// Ragged tables pad missing cells so rows align.
|
||||
@@ -1741,11 +1753,8 @@ fn table_row(
|
||||
.map(|_| div().flex_1().min_w_0().px_2().py_1()),
|
||||
),
|
||||
)
|
||||
}));
|
||||
|
||||
indented_frame(
|
||||
indent,
|
||||
block_frame(quote, Rems::ZERO, rems(0.75), ctx.block_id, cx).child(grid),
|
||||
})),
|
||||
),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ use gpui::{
|
||||
StyleRefinement, Styled as _, Window, div,
|
||||
};
|
||||
|
||||
use crate::components::common::{StyledExt as _, floating_panel, v_flex};
|
||||
use crate::components::menu::{
|
||||
ChangeHandler, TriggerBoundsCell, anchored_overlay, focus_capture, trigger_toggle,
|
||||
};
|
||||
use crate::components::common::{StyledExt as _, floating_panel, v_flex};
|
||||
use crate::theme::{ActiveTheme as _, POPOVER_MIN_WIDTH};
|
||||
|
||||
/// The element the panel anchors below, built during render.
|
||||
@@ -156,7 +156,9 @@ impl RenderOnce for Popover {
|
||||
let focus = crate::components::common::focus_handle(&self.id, window, cx);
|
||||
let content = self.content.map(|content| content(window, cx));
|
||||
|
||||
let panel = floating_panel(
|
||||
wrapper.child(anchored_overlay(
|
||||
None,
|
||||
floating_panel(
|
||||
cx,
|
||||
radius.overlay,
|
||||
v_flex()
|
||||
@@ -198,14 +200,10 @@ impl RenderOnce for Popover {
|
||||
}
|
||||
})
|
||||
.when_some(content, |panel, content| panel.child(content))
|
||||
.child(focus_capture(
|
||||
focus.clone(),
|
||||
move |window, cx| !focus.contains_focused(window, cx),
|
||||
));
|
||||
|
||||
wrapper.child(anchored_overlay(
|
||||
None,
|
||||
panel.into_any_element(),
|
||||
.child(focus_capture(focus.clone(), move |window, cx| {
|
||||
!focus.contains_focused(window, cx)
|
||||
}))
|
||||
.into_any_element(),
|
||||
Some(("popover-enter", enter_duration)),
|
||||
))
|
||||
})
|
||||
|
||||
@@ -108,7 +108,11 @@ impl RenderOnce for ScrollArea {
|
||||
let mut pane_style = self.style.clone();
|
||||
pane_style.padding = Default::default();
|
||||
|
||||
let pane = div()
|
||||
div()
|
||||
.relative()
|
||||
.refine_style(&self.style)
|
||||
.child(
|
||||
div()
|
||||
.id(self.id.clone())
|
||||
.h_full()
|
||||
.overflow_hidden()
|
||||
@@ -127,12 +131,8 @@ impl RenderOnce for ScrollArea {
|
||||
cx.stop_propagation();
|
||||
})
|
||||
.refine_style(&pane_style)
|
||||
.children(self.children);
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.refine_style(&self.style)
|
||||
.child(pane.into_any_element())
|
||||
.children(self.children),
|
||||
)
|
||||
.when_some(self.handle, |wrapper, handle| {
|
||||
let id = self.id.clone();
|
||||
|
||||
|
||||
@@ -340,7 +340,7 @@ where
|
||||
.collect()
|
||||
};
|
||||
|
||||
let menu = Menu::new(self.id)
|
||||
Menu::new(self.id)
|
||||
.open(is_open)
|
||||
.on_change({
|
||||
let open = open.clone();
|
||||
@@ -353,8 +353,7 @@ where
|
||||
}
|
||||
})
|
||||
.trigger(trigger)
|
||||
.items(items);
|
||||
|
||||
menu.when_some(selected_index, |menu, index| menu.initial_selection(index))
|
||||
.items(items)
|
||||
.when_some(selected_index, |menu, index| menu.initial_selection(index))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,7 +439,22 @@ impl RenderOnce for Sidebar {
|
||||
})
|
||||
.collect();
|
||||
|
||||
let body = div()
|
||||
let theme = cx.theme();
|
||||
|
||||
v_flex()
|
||||
.id(id.clone())
|
||||
.refine_style(&style)
|
||||
.debug_selector(move || format!("sidebar-{debug_id}"))
|
||||
.h_full()
|
||||
.w(width)
|
||||
.text_sm()
|
||||
.when(border_right, |sidebar| {
|
||||
sidebar
|
||||
.border_r(BORDER_WIDTH)
|
||||
.border_color(theme.colors.border)
|
||||
})
|
||||
.child(
|
||||
div()
|
||||
.id((id.clone(), "list"))
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
@@ -471,23 +486,8 @@ impl RenderOnce for Sidebar {
|
||||
.children(children),
|
||||
),
|
||||
)
|
||||
.into_any_element();
|
||||
|
||||
let theme = cx.theme();
|
||||
|
||||
v_flex()
|
||||
.id(id.clone())
|
||||
.refine_style(&style)
|
||||
.debug_selector(move || format!("sidebar-{debug_id}"))
|
||||
.h_full()
|
||||
.w(width)
|
||||
.text_sm()
|
||||
.when(border_right, |sidebar| {
|
||||
sidebar
|
||||
.border_r(BORDER_WIDTH)
|
||||
.border_color(theme.colors.border)
|
||||
})
|
||||
.child(body)
|
||||
.into_any_element(),
|
||||
)
|
||||
.when(material && grain, |sidebar| sidebar.child(grain_overlay()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1274,33 +1274,6 @@ impl RenderOnce for Tabs {
|
||||
return root.children(strip);
|
||||
};
|
||||
|
||||
let container_canvas = canvas(
|
||||
{
|
||||
let key = measure_key.clone();
|
||||
move |bounds, _, cx| {
|
||||
cx.default_global::<TabsMeasurements>()
|
||||
.record_container(&key, bounds.size.width);
|
||||
*root_bounds.borrow_mut() = Some(bounds);
|
||||
}
|
||||
},
|
||||
|_, _, _, _| {},
|
||||
)
|
||||
.absolute()
|
||||
.inset(shadow_bleed);
|
||||
|
||||
let trigger_canvas = canvas(
|
||||
{
|
||||
let key = measure_key;
|
||||
move |bounds, _, cx| {
|
||||
cx.default_global::<TabsMeasurements>()
|
||||
.record_trigger(&key, bounds.size.width);
|
||||
}
|
||||
},
|
||||
|_, _, _, _| {},
|
||||
)
|
||||
.absolute()
|
||||
.inset_0();
|
||||
|
||||
let control = match popover {
|
||||
Some(popover) => div().flex_none().relative().child(popover),
|
||||
None => div().flex_none().relative().child(
|
||||
@@ -1316,7 +1289,21 @@ impl RenderOnce for Tabs {
|
||||
.overflow_hidden()
|
||||
.p(shadow_bleed)
|
||||
.m(-shadow_bleed)
|
||||
.child(container_canvas)
|
||||
.child(
|
||||
canvas(
|
||||
{
|
||||
let key = measure_key.clone();
|
||||
move |bounds, _, cx| {
|
||||
cx.default_global::<TabsMeasurements>()
|
||||
.record_container(&key, bounds.size.width);
|
||||
*root_bounds.borrow_mut() = Some(bounds);
|
||||
}
|
||||
},
|
||||
|_, _, _, _| {},
|
||||
)
|
||||
.absolute()
|
||||
.inset(shadow_bleed),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex_none()
|
||||
@@ -1325,7 +1312,22 @@ impl RenderOnce for Tabs {
|
||||
.when(self.variant.is_capsule(), |row| row.items_center())
|
||||
.children(strip),
|
||||
)
|
||||
.child(control.child(trigger_canvas))
|
||||
.child(
|
||||
control.child(
|
||||
canvas(
|
||||
{
|
||||
let key = measure_key;
|
||||
move |bounds, _, cx| {
|
||||
cx.default_global::<TabsMeasurements>()
|
||||
.record_trigger(&key, bounds.size.width);
|
||||
}
|
||||
},
|
||||
|_, _, _, _| {},
|
||||
)
|
||||
.absolute()
|
||||
.inset_0(),
|
||||
),
|
||||
)
|
||||
} else if self.overflow_scroll {
|
||||
root.min_w_0()
|
||||
.overflow_x_scroll()
|
||||
@@ -1345,4 +1347,3 @@ impl RenderOnce for Tabs {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -249,26 +249,6 @@ impl RenderOnce for Resizable {
|
||||
.refine_style(&self.style)
|
||||
.children(self.panes.into_iter().enumerate().flat_map(|(ix, pane)| {
|
||||
let remainder = ix + 1 == pane_count;
|
||||
let pane_element = div()
|
||||
.overflow_hidden()
|
||||
.when(remainder, |pane_element| {
|
||||
pane_element
|
||||
.flex_1()
|
||||
.when(axis == Axis::Vertical, |p| p.min_h(pane.min))
|
||||
.when(axis == Axis::Horizontal, |p| p.min_w(pane.min))
|
||||
})
|
||||
.when(!remainder, |pane_element| {
|
||||
pane_element
|
||||
.flex_none()
|
||||
.when(axis == Axis::Vertical, |p| p.h(sizes[ix]).w_full())
|
||||
.when(axis == Axis::Horizontal, |p| p.w(sizes[ix]).h_full())
|
||||
})
|
||||
.when_some(debug_selector.clone(), |pane_element, selector| {
|
||||
let prefix = selector();
|
||||
pane_element.debug_selector(move || format!("{prefix}-{ix}"))
|
||||
})
|
||||
.child(pane.content)
|
||||
.into_any_element();
|
||||
|
||||
let divider = (!remainder).then(|| {
|
||||
// The positional index is a stable id: panes are append-only, never reordered.
|
||||
@@ -291,7 +271,29 @@ impl RenderOnce for Resizable {
|
||||
.into_any_element()
|
||||
});
|
||||
|
||||
std::iter::once(pane_element).chain(divider)
|
||||
std::iter::once(
|
||||
div()
|
||||
.overflow_hidden()
|
||||
.when(remainder, |pane_element| {
|
||||
pane_element
|
||||
.flex_1()
|
||||
.when(axis == Axis::Vertical, |p| p.min_h(pane.min))
|
||||
.when(axis == Axis::Horizontal, |p| p.min_w(pane.min))
|
||||
})
|
||||
.when(!remainder, |pane_element| {
|
||||
pane_element
|
||||
.flex_none()
|
||||
.when(axis == Axis::Vertical, |p| p.h(sizes[ix]).w_full())
|
||||
.when(axis == Axis::Horizontal, |p| p.w(sizes[ix]).h_full())
|
||||
})
|
||||
.when_some(debug_selector.clone(), |pane_element, selector| {
|
||||
let prefix = selector();
|
||||
pane_element.debug_selector(move || format!("{prefix}-{ix}"))
|
||||
})
|
||||
.child(pane.content)
|
||||
.into_any_element(),
|
||||
)
|
||||
.chain(divider)
|
||||
}))
|
||||
.when(pane_count > 0, |group| {
|
||||
group.child(
|
||||
|
||||
Reference in New Issue
Block a user