Compare commits

...

1 Commits

Author SHA1 Message Date
Nate Butler
b73935b441 start on basic high contrast poc 2025-03-04 11:53:38 -05:00
2 changed files with 43 additions and 20 deletions

View File

@@ -4367,7 +4367,7 @@ impl EditorElement {
);
Some((
hunk_bounds,
cx.theme().colors().version_control_modified,
Color::VersionControlModified.color(cx),
Corners::all(px(0.)),
DiffHunkStatus::modified_none(),
))
@@ -4379,19 +4379,19 @@ impl EditorElement {
} => hitbox.as_ref().map(|hunk_hitbox| match status.kind {
DiffHunkStatusKind::Added => (
hunk_hitbox.bounds,
cx.theme().colors().version_control_added,
Color::VersionControlAdded.color(cx),
Corners::all(px(0.)),
*status,
),
DiffHunkStatusKind::Modified => (
hunk_hitbox.bounds,
cx.theme().colors().version_control_modified,
Color::VersionControlModified.color(cx),
Corners::all(px(0.)),
*status,
),
DiffHunkStatusKind::Deleted if !display_row_range.is_empty() => (
hunk_hitbox.bounds,
cx.theme().colors().version_control_deleted,
Color::VersionControlDeleted.color(cx),
Corners::all(px(0.)),
*status,
),
@@ -4403,7 +4403,7 @@ impl EditorElement {
),
size(hunk_hitbox.size.width * px(2.), hunk_hitbox.size.height),
),
cx.theme().colors().version_control_deleted,
Color::VersionControlDeleted.color(cx),
Corners::all(1. * line_height),
*status,
),
@@ -5093,6 +5093,10 @@ impl EditorElement {
let theme = cx.theme().clone();
let scrollbar_settings = EditorSettings::get_global(cx).scrollbar;
let added_color = Color::VersionControlAdded.color(cx);
let modified_color = Color::VersionControlModified.color(cx);
let deleted_color = Color::VersionControlDeleted.color(cx);
editor.scrollbar_marker_state.dirty = false;
editor.scrollbar_marker_state.pending_refresh =
Some(cx.spawn_in(window, |editor, mut cx| async move {
@@ -5116,15 +5120,9 @@ impl EditorElement {
end_display_row.0 -= 1;
}
let color = match &hunk.status().kind {
DiffHunkStatusKind::Added => {
theme.colors().version_control_added
}
DiffHunkStatusKind::Modified => {
theme.colors().version_control_modified
}
DiffHunkStatusKind::Deleted => {
theme.colors().version_control_deleted
}
DiffHunkStatusKind::Added => added_color,
DiffHunkStatusKind::Modified => modified_color,
DiffHunkStatusKind::Deleted => deleted_color,
};
ColoredRange {
start: start_display_row,
@@ -6732,10 +6730,8 @@ impl Element for EditorElement {
};
let background_color = match diff_status.kind {
DiffHunkStatusKind::Added => cx.theme().colors().version_control_added,
DiffHunkStatusKind::Deleted => {
cx.theme().colors().version_control_deleted
}
DiffHunkStatusKind::Added => Color::VersionControlAdded.color(cx),
DiffHunkStatusKind::Deleted => Color::VersionControlDeleted.color(cx),
DiffHunkStatusKind::Modified => {
debug_panic!("modified diff status for row info");
continue;

View File

@@ -58,12 +58,20 @@ pub enum Color {
Success,
/// A color used to indicate a warning condition.
Warning,
VersionControlAdded,
VersionControlModified,
VersionControlDeleted,
}
impl Color {
/// Returns the Color's HSLA value.
/// Returns the Color's HSLA value based on the current theme.
///
/// Using this method over directly accessing it from the theme
/// allows us to dynamically adjust colors for accessibility and such.
pub fn color(&self, cx: &App) -> Hsla {
match self {
let high_contrast_enabled = true;
let mut color = match self {
Color::Default => cx.theme().colors().text,
Color::Muted => cx.theme().colors().text_muted,
Color::Created => cx.theme().status().created,
@@ -83,7 +91,26 @@ impl Color {
Color::Success => cx.theme().status().success,
Color::Warning => cx.theme().status().warning,
Color::Custom(color) => *color,
Color::VersionControlAdded => cx.theme().colors().version_control_added,
Color::VersionControlModified => cx.theme().colors().version_control_modified,
Color::VersionControlDeleted => cx.theme().colors().version_control_deleted,
};
if high_contrast_enabled {
let start_green_hue = 70.0;
let end_green_hue = 150.0;
let start_blue_hue = 210.0;
let end_blue_hue = 270.0;
let hue = color.h * 360.0;
if hue > start_green_hue && hue < end_green_hue {
let ratio = (hue - start_green_hue) / (end_green_hue - start_green_hue);
let new_hue = start_blue_hue + ratio * (end_blue_hue - start_blue_hue);
color.h = new_hue / 360.0;
}
}
color
}
}