Compiling layout!

co-authored-by: Max <max@zed.dev>
This commit is contained in:
Mikayla 2023-12-01 16:21:12 -08:00
parent 39887be7d0
commit b0f9144167
No known key found for this signature in database

View file

@ -182,7 +182,7 @@ impl TerminalElement {
// terminal_theme: &TerminalStyle, // terminal_theme: &TerminalStyle,
text_system: &TextSystem, text_system: &TextSystem,
hyperlink: Option<(HighlightStyle, &RangeInclusive<AlacPoint>)>, hyperlink: Option<(HighlightStyle, &RangeInclusive<AlacPoint>)>,
cx: &mut WindowContext<'_>, cx: &WindowContext<'_>,
) -> (Vec<LayoutCell>, Vec<LayoutRect>) { ) -> (Vec<LayoutCell>, Vec<LayoutRect>) {
let theme_colors = cx.theme().colors(); let theme_colors = cx.theme().colors();
let mut cells = vec![]; let mut cells = vec![];
@ -362,35 +362,41 @@ impl TerminalElement {
} }
fn compute_layout(&self, bounds: Bounds<gpui::Pixels>, cx: &mut WindowContext) -> LayoutState { fn compute_layout(&self, bounds: Bounds<gpui::Pixels>, cx: &mut WindowContext) -> LayoutState {
let settings = ThemeSettings::get_global(cx); let settings = ThemeSettings::get_global(cx).clone();
let terminal_settings = TerminalSettings::get_global(cx);
//Setup layout information //Setup layout information
// todo!(Terminal tooltips) // todo!(Terminal tooltips)
// let link_style = settings.theme.editor.link_definition; // let link_style = settings.theme.editor.link_definition;
// let tooltip_style = settings.theme.tooltip.clone(); // let tooltip_style = settings.theme.tooltip.clone();
let text_system = cx.text_system(); let buffer_font_size = settings.buffer_font_size(cx);
let font_size = font_size(&terminal_settings, cx).unwrap_or(settings.buffer_font_size(cx));
let font_family: SharedString = terminal_settings let terminal_settings = TerminalSettings::get_global(cx);
let font_family = terminal_settings
.font_family .font_family
.as_ref() .as_ref()
.map(|string| SharedString::from(*string)) .map(|string| string.clone().into())
.unwrap_or(settings.buffer_font.family); .unwrap_or(settings.buffer_font.family);
let font_features = terminal_settings let font_features = terminal_settings
.font_features .font_features
.as_ref() .clone()
.unwrap_or(&settings.buffer_font.features); .unwrap_or(settings.buffer_font.features.clone());
let line_height = terminal_settings.line_height.value();
let font_size = terminal_settings.font_size.clone();
let font_size =
font_size.map_or(buffer_font_size, |size| theme::adjusted_font_size(size, cx));
let settings = ThemeSettings::get_global(cx); let settings = ThemeSettings::get_global(cx);
let theme = cx.theme(); let theme = cx.theme().clone();
let text_style = TextStyle { let text_style = TextStyle {
font_family, font_family,
font_features: *font_features, font_features,
font_size: font_size.into(), font_size: font_size.into(),
font_style: FontStyle::Normal, font_style: FontStyle::Normal,
line_height: terminal_settings.line_height.value().into(), line_height: line_height.into(),
background_color: None, background_color: None,
white_space: WhiteSpace::Normal, white_space: WhiteSpace::Normal,
// These are going to be overridden per-cell // These are going to be overridden per-cell
@ -399,14 +405,14 @@ impl TerminalElement {
font_weight: FontWeight::NORMAL, font_weight: FontWeight::NORMAL,
}; };
let text_system = cx.text_system();
let selection_color = theme.players().local(); let selection_color = theme.players().local();
let match_color = theme.colors().search_match_background; let match_color = theme.colors().search_match_background;
let gutter; let gutter;
let dimensions = { let dimensions = {
let rem_size = cx.rem_size(); let rem_size = cx.rem_size();
let font_pixels = text_style.font_size.to_pixels(rem_size); let font_pixels = text_style.font_size.to_pixels(rem_size);
let line_height = let line_height = font_pixels * line_height.to_pixels(rem_size);
font_pixels * terminal_settings.line_height.value().to_pixels(rem_size);
let font_id = cx.text_system().font_id(&text_style.font()).unwrap(); let font_id = cx.text_system().font_id(&text_style.font()).unwrap();
// todo!(do we need to keep this unwrap?) // todo!(do we need to keep this unwrap?)
@ -475,7 +481,7 @@ impl TerminalElement {
selection, selection,
cursor, cursor,
.. ..
} = { &terminal_handle.read(cx).last_content }; } = &terminal_handle.read(cx).last_content;
// searches, highlights to a single range representations // searches, highlights to a single range representations
let mut relative_highlighted_ranges = Vec::new(); let mut relative_highlighted_ranges = Vec::new();
@ -516,12 +522,13 @@ impl TerminalElement {
theme.players().local().cursor theme.players().local().cursor
}; };
let len = str_trxt.len();
cx.text_system() cx.text_system()
.layout_line( .shape_line(
&str_trxt, str_trxt.into(),
text_style.font_size.to_pixels(cx.rem_size()), text_style.font_size.to_pixels(cx.rem_size()),
&[TextRun { &[TextRun {
len: str_trxt.len(), len,
font: text_style.font(), font: text_style.font(),
color, color,
background_color: None, background_color: None,
@ -549,7 +556,7 @@ impl TerminalElement {
cursor_position, cursor_position,
block_width, block_width,
dimensions.line_height, dimensions.line_height,
terminal_theme.cursor, theme.players().local().cursor,
shape, shape,
text, text,
) )
@ -964,12 +971,6 @@ fn to_highlighted_range_lines(
Some((start_y, highlighted_range_lines)) Some((start_y, highlighted_range_lines))
} }
fn font_size(terminal_settings: &TerminalSettings, cx: &mut AppContext) -> Option<Pixels> {
terminal_settings
.font_size
.map(|size| theme::adjusted_font_size(size, cx))
}
// mappings::colors::convert_color // mappings::colors::convert_color
fn convert_color(fg: &terminal::alacritty_terminal::ansi::Color, colors: &ThemeColors) -> Hsla { fn convert_color(fg: &terminal::alacritty_terminal::ansi::Color, colors: &ThemeColors) -> Hsla {
todo!() todo!()