Add configurable text color to textwrap

This commit is contained in:
mars 2022-12-05 20:26:12 -07:00
parent 70f9ca4405
commit 38674c2580
1 changed files with 10 additions and 4 deletions

View File

@ -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);
}