feat: redesign commit diff view
This commit is contained in:
@@ -181,3 +181,95 @@ impl RenderOnce for Badge {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A pill pairing a green additions segment with a red deletions segment.
|
||||
#[derive(IntoElement)]
|
||||
#[must_use]
|
||||
pub struct GroupedBadge {
|
||||
id: ElementId,
|
||||
insertions: usize,
|
||||
deletions: usize,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl GroupedBadge {
|
||||
/// Creates a grouped badge from insertion and deletion counts.
|
||||
pub fn new<I>(id: I, insertions: usize, deletions: usize) -> Self
|
||||
where
|
||||
I: Into<ElementId>,
|
||||
{
|
||||
Self {
|
||||
id: id.into(),
|
||||
insertions,
|
||||
deletions,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for GroupedBadge {
|
||||
fn style(&mut self) -> &mut gpui::StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for GroupedBadge {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
|
||||
let additions = (
|
||||
theme.ramps.success.base.opacity(0.2),
|
||||
theme.ramps.success.base,
|
||||
);
|
||||
|
||||
let deletions = (
|
||||
theme.ramps.destructive.base.opacity(0.2),
|
||||
theme.ramps.destructive.base,
|
||||
);
|
||||
|
||||
h_flex()
|
||||
.id(self.id.clone())
|
||||
.debug_selector({
|
||||
let id = self.id.clone();
|
||||
move || format!("{id}")
|
||||
})
|
||||
.flex_none()
|
||||
.text_xs()
|
||||
.font_medium()
|
||||
.when(self.insertions > 0, |group| {
|
||||
group.child(
|
||||
h_flex()
|
||||
.justify_center()
|
||||
.h_5()
|
||||
.px_1p5()
|
||||
.bg(additions.0)
|
||||
.text_color(additions.1)
|
||||
.debug_selector({
|
||||
let id = self.id.clone();
|
||||
move || format!("{id}-additions")
|
||||
})
|
||||
.when(self.deletions == 0, |segment| segment.rounded_full())
|
||||
.when(self.deletions > 0, |segment| segment.rounded_l_full())
|
||||
.child(SharedString::from(format!("+{}", self.insertions))),
|
||||
)
|
||||
})
|
||||
.when(self.deletions > 0, |group| {
|
||||
group.child(
|
||||
h_flex()
|
||||
.justify_center()
|
||||
.h_5()
|
||||
.px_1p5()
|
||||
.bg(deletions.0)
|
||||
.text_color(deletions.1)
|
||||
.debug_selector({
|
||||
let id = self.id.clone();
|
||||
move || format!("{id}-deletions")
|
||||
})
|
||||
.when(self.insertions == 0, |segment| segment.rounded_full())
|
||||
.when(self.insertions > 0, |segment| segment.rounded_r_full())
|
||||
.child(SharedString::from(format!("-{}", self.deletions))),
|
||||
)
|
||||
})
|
||||
.refine_style(&self.style)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,6 +326,8 @@ impl RenderOnce for Button {
|
||||
|
||||
h_flex()
|
||||
.id(self.id.clone())
|
||||
.refine_style(&self.style)
|
||||
.flex_shrink_0()
|
||||
.when_some(self.debug_selector, |button, selector| {
|
||||
button.debug_selector(move || selector())
|
||||
})
|
||||
@@ -351,7 +353,6 @@ impl RenderOnce for Button {
|
||||
.border_color(border)
|
||||
.when_some(background, |button, background| button.bg(background))
|
||||
.text_color(foreground)
|
||||
.refine_style(&self.style)
|
||||
.when_some(a11y_label, |button, label| button.aria_label(label))
|
||||
.child(
|
||||
h_flex()
|
||||
|
||||
@@ -133,7 +133,7 @@ impl RenderOnce for Switch {
|
||||
|
||||
h_flex()
|
||||
.id(self.id)
|
||||
.gap_2()
|
||||
.gap_1()
|
||||
.control_text(self.size)
|
||||
.refine_style(&self.style)
|
||||
.role(Role::Switch)
|
||||
@@ -179,7 +179,11 @@ impl RenderOnce for Switch {
|
||||
.left(inset)
|
||||
.switch_knob(self.size)
|
||||
.rounded(theme.radius.full)
|
||||
.bg(colors.primary_foreground)
|
||||
.bg(if self.checked {
|
||||
colors.primary_foreground
|
||||
} else {
|
||||
colors.muted_foreground
|
||||
})
|
||||
.with_spring("switch-thumb", anim, move |thumb, offset| {
|
||||
thumb.left(inset + offset)
|
||||
}),
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"> <path d="M12 13.5L11.4697 14.0303C11.7626 14.3232 12.2374 14.3232 12.5303 14.0303L12 13.5ZM8.75 15.5C8.33579 15.5 8 15.8358 8 16.25C8 16.6642 8.33579 17 8.75 17V15.5ZM15.25 17C15.6642 17 16 16.6642 16 16.25C16 15.8358 15.6642 15.5 15.25 15.5V17ZM11.25 7.75V13.5H12.75V7.75H11.25ZM12.5303 14.0303L14.7803 11.7803L13.7197 10.7197L11.4697 12.9697L12.5303 14.0303ZM12.5303 12.9697L10.2803 10.7197L9.21967 11.7803L11.4697 14.0303L12.5303 12.9697ZM8.75 17H15.25V15.5H8.75V17ZM6.75 4.5H17.25V3H6.75V4.5ZM19.5 6.75V17.25H21V6.75H19.5ZM17.25 19.5H6.75V21H17.25V19.5ZM4.5 17.25V6.75H3V17.25H4.5ZM6.75 19.5C5.50736 19.5 4.5 18.4926 4.5 17.25H3C3 19.3211 4.67893 21 6.75 21V19.5ZM19.5 17.25C19.5 18.4926 18.4926 19.5 17.25 19.5V21C19.3211 21 21 19.3211 21 17.25H19.5ZM17.25 4.5C18.4926 4.5 19.5 5.50736 19.5 6.75H21C21 4.67893 19.3211 3 17.25 3V4.5ZM6.75 3C4.67893 3 3 4.67893 3 6.75H4.5C4.5 5.50736 5.50736 4.5 6.75 4.5V3Z" fill="black"/> </svg>
|
||||
|
After Width: | Height: | Size: 1008 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"> <path d="M15.25 9.75L13 12L15.25 14.25" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M3.75 6.75C3.75 5.09315 5.09315 3.75 6.75 3.75H17.25C18.9069 3.75 20.25 5.09315 20.25 6.75V17.25C20.25 18.9069 18.9069 20.25 17.25 20.25H6.75C5.09315 20.25 3.75 18.9069 3.75 17.25V6.75Z" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M8.25 3.75V20.25" stroke="black" stroke-width="1.5"/> </svg>
|
||||
|
After Width: | Height: | Size: 543 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"> <path d="M8 18.75L12 14.75L16 18.75" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M16 5.25L12 9.25L8 5.25" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>
|
||||
|
After Width: | Height: | Size: 316 B |
@@ -59,6 +59,9 @@ pub enum IconRole {
|
||||
ArrowUp,
|
||||
Inbox,
|
||||
Stack,
|
||||
PanelLeft,
|
||||
UnfoldVertical,
|
||||
Download,
|
||||
}
|
||||
|
||||
impl IconRole {
|
||||
@@ -106,6 +109,9 @@ impl IconRole {
|
||||
Self::ArrowUp => "arrow-up",
|
||||
Self::Inbox => "inbox",
|
||||
Self::Stack => "stack",
|
||||
Self::PanelLeft => "panel-left",
|
||||
Self::UnfoldVertical => "unfold-vertical",
|
||||
Self::Download => "download",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user