Assign player colors from the theme (#3805)

This PR updates the `theme_importer` to pull in the player colors so
that we can assign them based on the current theme.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2023-12-22 22:28:41 -05:00 committed by GitHub
parent 5a910aa874
commit e5148b4a1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 1730 additions and 30 deletions

View file

@ -316,8 +316,9 @@ fn main() -> Result<()> {
#[allow(unused)]
use crate::{{
Appearance, StatusColorsRefinement, ThemeColorsRefinement, UserHighlightStyle, UserSyntaxTheme,
UserTheme, UserThemeFamily, UserThemeStylesRefinement, UserFontWeight, UserFontStyle
Appearance, PlayerColor, PlayerColors, StatusColorsRefinement, ThemeColorsRefinement,
UserHighlightStyle, UserSyntaxTheme, UserTheme, UserThemeFamily, UserThemeStylesRefinement,
UserFontWeight, UserFontStyle
}};
pub fn {theme_family_slug}() -> UserThemeFamily {{

View file

@ -107,6 +107,16 @@ impl<'a> Debug for UserThemeStylesRefinementPrinter<'a> {
f.debug_struct("UserThemeStylesRefinement")
.field("colors", &ThemeColorsRefinementPrinter(&self.0.colors))
.field("status", &StatusColorsRefinementPrinter(&self.0.status))
.field(
"player",
&OptionPrinter(
&self
.0
.player
.as_ref()
.map(|player_colors| PlayerColorsPrinter(player_colors)),
),
)
.field(
"syntax",
&OptionPrinter(

View file

@ -61,6 +61,7 @@ impl VsCodeThemeConverter {
styles: UserThemeStylesRefinement {
colors: theme_colors_refinements,
status: status_color_refinements,
player: None,
syntax: Some(syntax_theme),
},
})

View file

@ -3,8 +3,9 @@ use gpui::{Hsla, Rgba};
use gpui1::color::Color as Zed1Color;
use gpui1::fonts::HighlightStyle as Zed1HighlightStyle;
use theme::{
Appearance, StatusColorsRefinement, ThemeColorsRefinement, UserFontStyle, UserFontWeight,
UserHighlightStyle, UserSyntaxTheme, UserTheme, UserThemeStylesRefinement,
Appearance, PlayerColor, PlayerColors, StatusColorsRefinement, ThemeColorsRefinement,
UserFontStyle, UserFontWeight, UserHighlightStyle, UserSyntaxTheme, UserTheme,
UserThemeStylesRefinement,
};
use theme1::Theme as Zed1Theme;
@ -50,6 +51,7 @@ impl Zed1ThemeConverter {
let status_colors_refinement = self.convert_status_colors()?;
let theme_colors_refinement = self.convert_theme_colors()?;
let player_colors = self.convert_player_colors()?;
let syntax_theme = self.convert_syntax_theme()?;
Ok(UserTheme {
@ -58,6 +60,7 @@ impl Zed1ThemeConverter {
styles: UserThemeStylesRefinement {
colors: theme_colors_refinement,
status: status_colors_refinement,
player: Some(player_colors),
syntax: Some(syntax_theme),
},
})
@ -82,6 +85,31 @@ impl Zed1ThemeConverter {
})
}
fn convert_player_colors(&self) -> Result<PlayerColors> {
let player_one = self.theme.editor.selection;
let mut player_colors = vec![PlayerColor {
cursor: zed1_color_to_hsla(player_one.cursor),
selection: zed1_color_to_hsla(player_one.selection),
background: zed1_color_to_hsla(player_one.cursor),
}];
for index in 1..8 {
let player = self
.theme
.editor
.selection_style_for_room_participant(index);
player_colors.push(PlayerColor {
cursor: zed1_color_to_hsla(player.cursor),
selection: zed1_color_to_hsla(player.selection),
background: zed1_color_to_hsla(player.cursor),
});
}
Ok(PlayerColors(player_colors))
}
fn convert_theme_colors(&self) -> Result<ThemeColorsRefinement> {
fn convert(color: Zed1Color) -> Option<Hsla> {
Some(zed1_color_to_hsla(color))