pub struct WindowTextSystem { /* private fields */ }Expand description
The GPUI text layout subsystem.
Implementations§
Source§impl WindowTextSystem
impl WindowTextSystem
Sourcepub fn new(text_system: Arc<TextSystem>) -> Self
pub fn new(text_system: Arc<TextSystem>) -> Self
Create a new WindowTextSystem with the given TextSystem.
Sourcepub fn shape_line(
&self,
text: SharedString,
font_size: Pixels,
runs: &[TextRun],
force_width: Option<Pixels>,
) -> ShapedLine
pub fn shape_line( &self, text: SharedString, font_size: Pixels, runs: &[TextRun], force_width: Option<Pixels>, ) -> ShapedLine
Shape the given line, at the given font_size, for painting to the screen.
Subsets of the line can be styled independently with the runs parameter.
Note that this method can only shape a single line of text. It will panic
if the text contains newlines. If you need to shape multiple lines of text,
use Self::shape_text instead.
Sourcepub fn shape_line_by_hash(
&self,
text_hash: u64,
text_len: usize,
font_size: Pixels,
runs: &[TextRun],
force_width: Option<Pixels>,
materialize_text: impl FnOnce() -> SharedString,
) -> ShapedLine
pub fn shape_line_by_hash( &self, text_hash: u64, text_len: usize, font_size: Pixels, runs: &[TextRun], force_width: Option<Pixels>, materialize_text: impl FnOnce() -> SharedString, ) -> ShapedLine
Shape the given line using a caller-provided content hash as the cache key.
This enables cache hits without materializing a contiguous SharedString for the text.
If the cache misses, materialize_text is invoked to produce the SharedString for shaping.
Contract (caller enforced):
- Same
text_hashimplies identical text content (collision risk accepted by caller). text_lenshould be the UTF-8 byte length of the text (helps reduce accidental collisions).
Like Self::shape_line, this must be used only for single-line text (no \n).
Sourcepub fn shape_text(
&self,
text: SharedString,
font_size: Pixels,
runs: &[TextRun],
wrap_width: Option<Pixels>,
line_clamp: Option<usize>,
) -> Result<SmallVec<[WrappedLine; 1]>>
pub fn shape_text( &self, text: SharedString, font_size: Pixels, runs: &[TextRun], wrap_width: Option<Pixels>, line_clamp: Option<usize>, ) -> Result<SmallVec<[WrappedLine; 1]>>
Shape a multi line string of text, at the given font_size, for painting to the screen.
Subsets of the text can be styled independently with the runs parameter.
If wrap_width is provided, the line breaks will be adjusted to fit within the given width.
Sourcepub fn layout_line(
&self,
text: &str,
font_size: Pixels,
runs: &[TextRun],
force_width: Option<Pixels>,
) -> Arc<LineLayout> ⓘ
pub fn layout_line( &self, text: &str, font_size: Pixels, runs: &[TextRun], force_width: Option<Pixels>, ) -> Arc<LineLayout> ⓘ
Layout the given line of text, at the given font_size.
Subsets of the line can be styled independently with the runs parameter.
Generally, you should prefer to use Self::shape_line instead, which
can be painted directly.
Sourcepub fn try_layout_line_by_hash(
&self,
text_hash: u64,
text_len: usize,
font_size: Pixels,
runs: &[TextRun],
force_width: Option<Pixels>,
) -> Option<Arc<LineLayout>>
pub fn try_layout_line_by_hash( &self, text_hash: u64, text_len: usize, font_size: Pixels, runs: &[TextRun], force_width: Option<Pixels>, ) -> Option<Arc<LineLayout>>
Probe the line layout cache using a caller-provided content hash, without allocating.
Returns Some(layout) if the layout is already cached in either the current frame
or the previous frame. Returns None if it is not cached.
Contract (caller enforced):
- Same
text_hashimplies identical text content (collision risk accepted by caller). text_lenshould be the UTF-8 byte length of the text (helps reduce accidental collisions).
Sourcepub fn layout_line_by_hash(
&self,
text_hash: u64,
text_len: usize,
font_size: Pixels,
runs: &[TextRun],
force_width: Option<Pixels>,
materialize_text: impl FnOnce() -> SharedString,
) -> Arc<LineLayout> ⓘ
pub fn layout_line_by_hash( &self, text_hash: u64, text_len: usize, font_size: Pixels, runs: &[TextRun], force_width: Option<Pixels>, materialize_text: impl FnOnce() -> SharedString, ) -> Arc<LineLayout> ⓘ
Layout the given line of text using a caller-provided content hash as the cache key.
This enables cache hits without materializing a contiguous SharedString for the text.
If the cache misses, materialize_text is invoked to produce the SharedString for shaping.
Contract (caller enforced):
- Same
text_hashimplies identical text content (collision risk accepted by caller). text_lenshould be the UTF-8 byte length of the text (helps reduce accidental collisions).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WindowTextSystem
impl !RefUnwindSafe for WindowTextSystem
impl Send for WindowTextSystem
impl Sync for WindowTextSystem
impl Unpin for WindowTextSystem
impl UnsafeUnpin for WindowTextSystem
impl !UnwindSafe for WindowTextSystem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more