From 38674c25808c00007a45100f76870a7fc0fb032d Mon Sep 17 00:00:00 2001 From: mars Date: Mon, 5 Dec 2022 20:26:12 -0700 Subject: [PATCH] Add configurable text color to textwrap --- crates/textwrap/src/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/textwrap/src/lib.rs b/crates/textwrap/src/lib.rs index 6e602a2..d6feb28 100644 --- a/crates/textwrap/src/lib.rs +++ b/crates/textwrap/src/lib.rs @@ -163,11 +163,18 @@ pub struct Layout { } impl Layout { - pub fn draw(&self, cache: &TextCache, ctx: &DrawContext, scale: f32, line_height: f32) { + pub fn draw( + &self, + cache: &TextCache, + ctx: &DrawContext, + scale: f32, + line_height: f32, + color: Color, + ) { let mut cursor = Vec2::ZERO; for line in self.lines.iter() { let ctx = ctx.with_offset(cursor); - line.draw(cache, &ctx, scale); + line.draw(cache, &ctx, scale, color); cursor.y += line_height; } } @@ -208,13 +215,12 @@ impl Line { Self { fragments } } - pub fn draw(&self, cache: &TextCache, ctx: &DrawContext, scale: f32) { + pub fn draw(&self, cache: &TextCache, ctx: &DrawContext, scale: f32, color: Color) { let mut cursor = Vec2::ZERO; for fragment in self.fragments.iter() { if !fragment.hidden { let text = cache.get(fragment.text); let offset = cursor + fragment.offset; - let color = Color::WHITE; ctx.draw_text_layout(text.layout, offset, scale, color); }