Accept colors in styling runs passed to layout_str
Also move from the runs being expressed as ranges to the runs being expressed as a sequence of contiguous scalar lengths.
This commit is contained in:
@@ -14,10 +14,7 @@ use gpui::{
|
||||
use json::json;
|
||||
use smallvec::SmallVec;
|
||||
use std::cmp::Ordering;
|
||||
use std::{
|
||||
cmp::{self},
|
||||
sync::Arc,
|
||||
};
|
||||
use std::cmp::{self};
|
||||
|
||||
pub struct BufferElement {
|
||||
view: WeakViewHandle<BufferView>,
|
||||
@@ -188,13 +185,12 @@ impl BufferElement {
|
||||
for (ix, line) in layout.line_number_layouts.iter().enumerate() {
|
||||
let line_origin = rect.origin()
|
||||
+ vec2f(
|
||||
rect.width() - line.width - layout.gutter_padding,
|
||||
rect.width() - line.width() - layout.gutter_padding,
|
||||
ix as f32 * line_height - (scroll_top % line_height),
|
||||
);
|
||||
line.paint(
|
||||
line_origin,
|
||||
RectF::new(vec2f(0., 0.), vec2f(line.width, line_height)),
|
||||
&[(0..line.len, ColorU::black())],
|
||||
RectF::new(vec2f(0., 0.), vec2f(line.width(), line_height)),
|
||||
ctx,
|
||||
);
|
||||
}
|
||||
@@ -259,7 +255,7 @@ impl BufferElement {
|
||||
+ line_layout.x_for_index(range_end.column() as usize)
|
||||
- scroll_left
|
||||
} else {
|
||||
content_origin.x() + line_layout.width + corner_radius * 2.0
|
||||
content_origin.x() + line_layout.width() + corner_radius * 2.0
|
||||
- scroll_left
|
||||
},
|
||||
}
|
||||
@@ -292,7 +288,6 @@ impl BufferElement {
|
||||
line.paint(
|
||||
content_origin + vec2f(-scroll_left, row as f32 * line_height - scroll_top),
|
||||
RectF::new(vec2f(scroll_left, 0.), vec2f(bounds.width(), line_height)),
|
||||
&[(0..line.len, ColorU::black())],
|
||||
ctx,
|
||||
);
|
||||
}
|
||||
@@ -377,8 +372,8 @@ impl Element for BufferElement {
|
||||
}
|
||||
Ok(layouts) => {
|
||||
for line in &layouts {
|
||||
if line.width > max_visible_line_width {
|
||||
max_visible_line_width = line.width;
|
||||
if line.width() > max_visible_line_width {
|
||||
max_visible_line_width = line.width();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -506,8 +501,8 @@ pub struct LayoutState {
|
||||
gutter_size: Vector2F,
|
||||
gutter_padding: f32,
|
||||
text_size: Vector2F,
|
||||
line_layouts: Vec<Arc<text_layout::Line>>,
|
||||
line_number_layouts: Vec<Arc<text_layout::Line>>,
|
||||
line_layouts: Vec<text_layout::Line>,
|
||||
line_number_layouts: Vec<text_layout::Line>,
|
||||
max_visible_line_width: f32,
|
||||
autoscroll_horizontally: bool,
|
||||
}
|
||||
@@ -524,7 +519,7 @@ impl LayoutState {
|
||||
let longest_line_width = view
|
||||
.layout_line(row, font_cache, layout_cache, app)
|
||||
.unwrap()
|
||||
.width;
|
||||
.width();
|
||||
longest_line_width.max(self.max_visible_line_width) + view.em_width(font_cache)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,10 @@ use super::{
|
||||
use crate::{settings::Settings, util::post_inc, workspace, worktree::FileHandle};
|
||||
use anyhow::Result;
|
||||
use gpui::{
|
||||
fonts::Properties as FontProperties, geometry::vector::Vector2F, keymap::Binding, text_layout,
|
||||
AppContext, ClipboardItem, Element, ElementBox, Entity, FontCache, ModelHandle,
|
||||
MutableAppContext, Task, TextLayoutCache, View, ViewContext, WeakViewHandle,
|
||||
color::ColorU, fonts::Properties as FontProperties, geometry::vector::Vector2F,
|
||||
keymap::Binding, text_layout, AppContext, ClipboardItem, Element, ElementBox, Entity,
|
||||
FontCache, ModelHandle, MutableAppContext, Task, TextLayoutCache, View, ViewContext,
|
||||
WeakViewHandle,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use postage::watch;
|
||||
@@ -448,7 +449,7 @@ impl BufferView {
|
||||
viewport_width: f32,
|
||||
scroll_width: f32,
|
||||
max_glyph_width: f32,
|
||||
layouts: &[Arc<text_layout::Line>],
|
||||
layouts: &[text_layout::Line],
|
||||
ctx: &AppContext,
|
||||
) {
|
||||
let mut target_left = std::f32::INFINITY;
|
||||
@@ -2077,9 +2078,9 @@ impl BufferView {
|
||||
.layout_str(
|
||||
"1".repeat(digit_count).as_str(),
|
||||
font_size,
|
||||
&[(0..digit_count, font_id)],
|
||||
&[(digit_count, font_id, ColorU::black())],
|
||||
)
|
||||
.width)
|
||||
.width())
|
||||
}
|
||||
|
||||
pub fn layout_line_numbers(
|
||||
@@ -2088,7 +2089,7 @@ impl BufferView {
|
||||
font_cache: &FontCache,
|
||||
layout_cache: &TextLayoutCache,
|
||||
ctx: &AppContext,
|
||||
) -> Result<Vec<Arc<text_layout::Line>>> {
|
||||
) -> Result<Vec<text_layout::Line>> {
|
||||
let settings = self.settings.borrow();
|
||||
let font_size = settings.buffer_font_size;
|
||||
let font_id =
|
||||
@@ -2114,7 +2115,7 @@ impl BufferView {
|
||||
layouts.push(layout_cache.layout_str(
|
||||
&line_number,
|
||||
font_size,
|
||||
&[(0..line_number.len(), font_id)],
|
||||
&[(line_number.len(), font_id, ColorU::black())],
|
||||
));
|
||||
}
|
||||
|
||||
@@ -2127,7 +2128,7 @@ impl BufferView {
|
||||
font_cache: &FontCache,
|
||||
layout_cache: &TextLayoutCache,
|
||||
ctx: &AppContext,
|
||||
) -> Result<Vec<Arc<text_layout::Line>>> {
|
||||
) -> Result<Vec<text_layout::Line>> {
|
||||
rows.end = cmp::min(rows.end, self.display_map.max_point(ctx).row() + 1);
|
||||
if rows.start >= rows.end {
|
||||
return Ok(Vec::new());
|
||||
@@ -2151,7 +2152,7 @@ impl BufferView {
|
||||
layouts.push(layout_cache.layout_str(
|
||||
&line,
|
||||
font_size,
|
||||
&[(0..line.len(), font_id)],
|
||||
&[(line.len(), font_id, ColorU::black())],
|
||||
));
|
||||
line.clear();
|
||||
row += 1;
|
||||
@@ -2171,7 +2172,7 @@ impl BufferView {
|
||||
font_cache: &FontCache,
|
||||
layout_cache: &TextLayoutCache,
|
||||
app: &AppContext,
|
||||
) -> Result<Arc<text_layout::Line>> {
|
||||
) -> Result<text_layout::Line> {
|
||||
let settings = self.settings.borrow();
|
||||
let font_id =
|
||||
font_cache.select_font(settings.buffer_font_family, &FontProperties::new())?;
|
||||
@@ -2181,7 +2182,7 @@ impl BufferView {
|
||||
Ok(layout_cache.layout_str(
|
||||
&line,
|
||||
settings.buffer_font_size,
|
||||
&[(0..self.line_len(row, app) as usize, font_id)],
|
||||
&[(self.line_len(row, app) as usize, font_id, ColorU::black())],
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user