Fix tree branch rendering in collab panel

This commit is contained in:
Max Brunsfeld 2023-12-05 10:14:40 -08:00
parent 2299730538
commit 5e79807f6f
2 changed files with 20 additions and 27 deletions

View file

@ -169,7 +169,7 @@ use editor::Editor;
use feature_flags::{ChannelsAlpha, FeatureFlagAppExt, FeatureFlagViewExt}; use feature_flags::{ChannelsAlpha, FeatureFlagAppExt, FeatureFlagViewExt};
use fuzzy::{match_strings, StringMatchCandidate}; use fuzzy::{match_strings, StringMatchCandidate};
use gpui::{ use gpui::{
actions, canvas, div, img, overlay, point, prelude::*, px, rems, serde_json, Action, actions, canvas, div, img, overlay, point, prelude::*, px, rems, serde_json, size, Action,
AppContext, AsyncWindowContext, Bounds, ClipboardItem, DismissEvent, Div, EventEmitter, AppContext, AsyncWindowContext, Bounds, ClipboardItem, DismissEvent, Div, EventEmitter,
FocusHandle, Focusable, FocusableView, Hsla, InteractiveElement, IntoElement, Length, Model, FocusHandle, Focusable, FocusableView, Hsla, InteractiveElement, IntoElement, Length, Model,
MouseDownEvent, ParentElement, Pixels, Point, PromptLevel, Quad, Render, RenderOnce, MouseDownEvent, ParentElement, Pixels, Point, PromptLevel, Quad, Render, RenderOnce,
@ -1204,14 +1204,9 @@ impl CollabPanel {
.detach_and_log_err(cx); .detach_and_log_err(cx);
}); });
})) }))
.left_child(IconButton::new(0, Icon::Folder)) .left_child(render_tree_branch(is_last, cx))
.child( .child(IconButton::new(0, Icon::Folder))
h_stack() .child(Label::new(project_name.clone()))
.w_full()
.justify_between()
.child(render_tree_branch(is_last, cx))
.child(Label::new(project_name.clone())),
)
.tooltip(move |cx| Tooltip::text(format!("Open {}", project_name), cx)) .tooltip(move |cx| Tooltip::text(format!("Open {}", project_name), cx))
// enum JoinProject {} // enum JoinProject {}
@ -3119,30 +3114,24 @@ impl CollabPanel {
} }
fn render_tree_branch(is_last: bool, cx: &mut WindowContext) -> impl IntoElement { fn render_tree_branch(is_last: bool, cx: &mut WindowContext) -> impl IntoElement {
let text_style = cx.text_style();
let rem_size = cx.rem_size(); let rem_size = cx.rem_size();
let text_system = cx.text_system(); let line_height = cx.text_style().line_height_in_pixels(rem_size);
let font_id = text_system.font_id(&text_style.font()).unwrap(); let width = rem_size * 1.5;
let font_size = text_style.font_size.to_pixels(rem_size);
let line_height = text_style.line_height_in_pixels(rem_size);
let cap_height = text_system.cap_height(font_id, font_size);
let baseline_offset = text_system.baseline_offset(font_id, font_size, line_height);
let width = cx.rem_size() * 2.5;
let thickness = px(2.); let thickness = px(2.);
let color = cx.theme().colors().text; let color = cx.theme().colors().text;
canvas(move |bounds, cx| { canvas(move |bounds, cx| {
let start_x = bounds.left() + (bounds.size.width / 2.) - (width / 2.); let start_x = (bounds.left() + bounds.right() - thickness) / 2.;
let end_x = bounds.right(); let start_y = (bounds.top() + bounds.bottom() - thickness) / 2.;
let start_y = bounds.top(); let right = bounds.right();
let end_y = bounds.top() + baseline_offset - (cap_height / 2.); let top = bounds.top();
cx.paint_quad( cx.paint_quad(
Bounds::from_corners( Bounds::from_corners(
point(start_x, start_y), point(start_x, top),
point( point(
start_x + thickness, start_x + thickness,
if is_last { end_y } else { bounds.bottom() }, if is_last { start_y } else { bounds.bottom() },
), ),
), ),
Default::default(), Default::default(),
@ -3151,7 +3140,7 @@ fn render_tree_branch(is_last: bool, cx: &mut WindowContext) -> impl IntoElement
Hsla::transparent_black(), Hsla::transparent_black(),
); );
cx.paint_quad( cx.paint_quad(
Bounds::from_corners(point(start_x, end_y), point(end_x, end_y + thickness)), Bounds::from_corners(point(start_x, start_y), point(right, start_y + thickness)),
Default::default(), Default::default(),
color, color,
Default::default(), Default::default(),

View file

@ -1,9 +1,11 @@
use crate::{Bounds, Element, IntoElement, Pixels, StyleRefinement, Styled, WindowContext}; use refineable::Refineable as _;
use crate::{Bounds, Element, IntoElement, Pixels, Style, StyleRefinement, Styled, WindowContext};
pub fn canvas(callback: impl 'static + FnOnce(Bounds<Pixels>, &mut WindowContext)) -> Canvas { pub fn canvas(callback: impl 'static + FnOnce(Bounds<Pixels>, &mut WindowContext)) -> Canvas {
Canvas { Canvas {
paint_callback: Box::new(callback), paint_callback: Box::new(callback),
style: Default::default(), style: StyleRefinement::default(),
} }
} }
@ -32,7 +34,9 @@ impl Element for Canvas {
_: Option<Self::State>, _: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> (crate::LayoutId, Self::State) { ) -> (crate::LayoutId, Self::State) {
let layout_id = cx.request_layout(&self.style.clone().into(), []); let mut style = Style::default();
style.refine(&self.style);
let layout_id = cx.request_layout(&style, []);
(layout_id, ()) (layout_id, ())
} }