Paint lines

This commit is contained in:
Antonio Scandurra
2023-11-07 12:25:33 +01:00
parent e460f6a27c
commit a866370dc1
8 changed files with 164 additions and 178 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ impl<V: 'static> Element<V> for Text<V> {
) -> LayoutId {
let text_system = cx.text_system().clone();
let text_style = cx.text_style();
let font_size = text_style.font_size * cx.rem_size();
let font_size = text_style.font_size.to_pixels(cx.rem_size());
let line_height = text_style
.line_height
.to_pixels(font_size.into(), cx.rem_size());
+3 -3
View File
@@ -1,7 +1,7 @@
use crate::{
black, phi, point, rems, AbsoluteLength, BorrowAppContext, BorrowWindow, Bounds, ContentMask,
Corners, CornersRefinement, DefiniteLength, Edges, EdgesRefinement, Font, FontFeatures,
FontStyle, FontWeight, Hsla, Length, Pixels, Point, PointRefinement, Rems, Result, Rgba,
FontStyle, FontWeight, Hsla, Length, Pixels, Point, PointRefinement, Result, Rgba,
SharedString, Size, SizeRefinement, Styled, TextRun, ViewContext, WindowContext,
};
use refineable::{Cascade, Refineable};
@@ -121,7 +121,7 @@ pub struct TextStyle {
pub color: Hsla,
pub font_family: SharedString,
pub font_features: FontFeatures,
pub font_size: Rems,
pub font_size: AbsoluteLength,
pub line_height: DefiniteLength,
pub font_weight: FontWeight,
pub font_style: FontStyle,
@@ -134,7 +134,7 @@ impl Default for TextStyle {
color: black(),
font_family: "Helvetica".into(), // todo!("Get a font we know exists on the system")
font_features: FontFeatures::default(),
font_size: rems(1.),
font_size: rems(1.).into(),
line_height: phi(),
font_weight: FontWeight::default(),
font_style: FontStyle::default(),
+11 -10
View File
@@ -1,6 +1,7 @@
use crate::{
self as gpui2, hsla, point, px, relative, rems, AlignItems, DefiniteLength, Display, Fill,
FlexDirection, Hsla, JustifyContent, Length, Position, Rems, SharedString, StyleRefinement,
self as gpui2, hsla, point, px, relative, rems, AbsoluteLength, AlignItems, DefiniteLength,
Display, Fill, FlexDirection, Hsla, JustifyContent, Length, Position, SharedString,
StyleRefinement,
};
use crate::{BoxShadow, TextStyleRefinement};
use smallvec::smallvec;
@@ -384,7 +385,7 @@ pub trait Styled {
self
}
fn text_size(mut self, size: impl Into<Rems>) -> Self
fn text_size(mut self, size: impl Into<AbsoluteLength>) -> Self
where
Self: Sized,
{
@@ -400,7 +401,7 @@ pub trait Styled {
{
self.text_style()
.get_or_insert_with(Default::default)
.font_size = Some(rems(0.75));
.font_size = Some(rems(0.75).into());
self
}
@@ -410,7 +411,7 @@ pub trait Styled {
{
self.text_style()
.get_or_insert_with(Default::default)
.font_size = Some(rems(0.875));
.font_size = Some(rems(0.875).into());
self
}
@@ -420,7 +421,7 @@ pub trait Styled {
{
self.text_style()
.get_or_insert_with(Default::default)
.font_size = Some(rems(1.0));
.font_size = Some(rems(1.0).into());
self
}
@@ -430,7 +431,7 @@ pub trait Styled {
{
self.text_style()
.get_or_insert_with(Default::default)
.font_size = Some(rems(1.125));
.font_size = Some(rems(1.125).into());
self
}
@@ -440,7 +441,7 @@ pub trait Styled {
{
self.text_style()
.get_or_insert_with(Default::default)
.font_size = Some(rems(1.25));
.font_size = Some(rems(1.25).into());
self
}
@@ -450,7 +451,7 @@ pub trait Styled {
{
self.text_style()
.get_or_insert_with(Default::default)
.font_size = Some(rems(1.5));
.font_size = Some(rems(1.5).into());
self
}
@@ -460,7 +461,7 @@ pub trait Styled {
{
self.text_style()
.get_or_insert_with(Default::default)
.font_size = Some(rems(1.875));
.font_size = Some(rems(1.875).into());
self
}
@@ -82,18 +82,6 @@ impl LineLayout {
self.width
}
pub fn font_for_index(&self, index: usize) -> Option<FontId> {
for run in &self.runs {
for glyph in &run.glyphs {
if glyph.index >= index {
return Some(run.font_id);
}
}
}
None
}
fn compute_wrap_boundaries(
&self,
text: &str,