chore: reduce component overhead (#3)
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
+13
-11
@@ -1,9 +1,9 @@
|
||||
use gpui::AppContext as _;
|
||||
use gpui::{
|
||||
AnyView, App, Bounds, Context, ElementId, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Pixels, Render, SharedString, Styled as _, Window, canvas, div, point, px,
|
||||
ParentElement as _, Pixels, Render, SharedString, Styled as _, Window, canvas, div, point,
|
||||
};
|
||||
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH};
|
||||
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, TOOLTIP_MAX_WIDTH, TOOLTIP_OFFSET};
|
||||
use gpui_native_utils::{anchor_bounds, record_anchor_bounds};
|
||||
|
||||
const PANEL_BOUNDS_ID: &str = "tooltip-panel-bounds";
|
||||
@@ -34,8 +34,8 @@ impl Tooltip {
|
||||
{
|
||||
let text = text.into();
|
||||
let anchor_id = anchor_id.into();
|
||||
move |_window, cx| {
|
||||
let anchor = anchor_bounds(&anchor_id, cx);
|
||||
move |window, cx| {
|
||||
let anchor = anchor_bounds(window.window_handle().window_id(), &anchor_id, cx);
|
||||
cx.new(|_| Self {
|
||||
text: text.clone(),
|
||||
anchor,
|
||||
@@ -76,7 +76,7 @@ impl Render for Tooltip {
|
||||
.debug_selector(|| "tooltip-panel".to_string())
|
||||
.px_2()
|
||||
.py_1()
|
||||
.max_w(px(360.))
|
||||
.max_w(TOOLTIP_MAX_WIDTH)
|
||||
.bg(surface)
|
||||
.border_1()
|
||||
.border_color(border)
|
||||
@@ -89,14 +89,16 @@ impl Render for Tooltip {
|
||||
|
||||
let (wrapper, panel) = match self.anchor {
|
||||
Some(parent) => {
|
||||
let origin = window.mouse_position() + point(px(1.), px(1.));
|
||||
let origin = window.mouse_position() + point(TOOLTIP_OFFSET, TOOLTIP_OFFSET);
|
||||
let viewport_height = window.viewport_size().height;
|
||||
|
||||
let height = anchor_bounds(&ElementId::from(PANEL_BOUNDS_ID), cx)
|
||||
.map(|bounds| bounds.size.height)
|
||||
.unwrap_or_else(|| {
|
||||
text_size * 1.5 + window.rem_size() * 0.5 + BORDER_WIDTH * 2.0
|
||||
});
|
||||
let height = anchor_bounds(
|
||||
window.window_handle().window_id(),
|
||||
&ElementId::from(PANEL_BOUNDS_ID),
|
||||
cx,
|
||||
)
|
||||
.map(|bounds| bounds.size.height)
|
||||
.unwrap_or_else(|| text_size * 1.5 + window.rem_size() * 0.5 + BORDER_WIDTH * 2.0);
|
||||
|
||||
let below = viewport_height - spacing_unit - parent.bottom();
|
||||
let above = parent.top() - spacing_unit;
|
||||
|
||||
Reference in New Issue
Block a user