mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Add fake italics (tilt text)
This commit is contained in:
@@ -114,37 +114,33 @@ impl Mesh {
|
||||
}
|
||||
|
||||
/// Rectangle with a texture and color.
|
||||
pub fn add_rect_with_uv(&mut self, pos: Rect, uv: Rect, color: Color32) {
|
||||
pub fn add_rect_with_uv(&mut self, rect: Rect, uv: Rect, color: Color32) {
|
||||
#![allow(clippy::identity_op)]
|
||||
|
||||
let idx = self.vertices.len() as u32;
|
||||
self.add_triangle(idx + 0, idx + 1, idx + 2);
|
||||
self.add_triangle(idx + 2, idx + 1, idx + 3);
|
||||
|
||||
let right_top = Vertex {
|
||||
pos: pos.right_top(),
|
||||
uv: uv.right_top(),
|
||||
color,
|
||||
};
|
||||
let left_top = Vertex {
|
||||
pos: pos.left_top(),
|
||||
self.vertices.push(Vertex {
|
||||
pos: rect.left_top(),
|
||||
uv: uv.left_top(),
|
||||
color,
|
||||
};
|
||||
let left_bottom = Vertex {
|
||||
pos: pos.left_bottom(),
|
||||
});
|
||||
self.vertices.push(Vertex {
|
||||
pos: rect.right_top(),
|
||||
uv: uv.right_top(),
|
||||
color,
|
||||
});
|
||||
self.vertices.push(Vertex {
|
||||
pos: rect.left_bottom(),
|
||||
uv: uv.left_bottom(),
|
||||
color,
|
||||
};
|
||||
let right_bottom = Vertex {
|
||||
pos: pos.right_bottom(),
|
||||
});
|
||||
self.vertices.push(Vertex {
|
||||
pos: rect.right_bottom(),
|
||||
uv: uv.right_bottom(),
|
||||
color,
|
||||
};
|
||||
self.vertices.push(left_top);
|
||||
self.vertices.push(right_top);
|
||||
self.vertices.push(left_bottom);
|
||||
self.vertices.push(right_bottom);
|
||||
});
|
||||
}
|
||||
|
||||
/// Uniformly colored rectangle.
|
||||
|
||||
@@ -46,6 +46,8 @@ pub enum Shape {
|
||||
galley: Galley,
|
||||
text_style: TextStyle, // TODO: Font?
|
||||
color: Color32,
|
||||
/// If true, tilt the letters for an ugly italics effect
|
||||
fake_italics: bool,
|
||||
},
|
||||
Mesh(Mesh),
|
||||
}
|
||||
@@ -138,6 +140,7 @@ impl Shape {
|
||||
galley,
|
||||
text_style,
|
||||
color,
|
||||
fake_italics: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,6 +545,7 @@ impl Tessellator {
|
||||
galley,
|
||||
text_style,
|
||||
color,
|
||||
fake_italics,
|
||||
} => {
|
||||
if options.debug_paint_text_rects {
|
||||
self.tessellate_rect(
|
||||
@@ -557,7 +558,7 @@ impl Tessellator {
|
||||
out,
|
||||
);
|
||||
}
|
||||
self.tessellate_text(fonts, pos, &galley, text_style, color, out);
|
||||
self.tessellate_text(fonts, pos, &galley, text_style, color, fake_italics, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -592,6 +593,7 @@ impl Tessellator {
|
||||
stroke_path(&path.0, Closed, stroke, self.options, out);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn tessellate_text(
|
||||
&mut self,
|
||||
fonts: &Fonts,
|
||||
@@ -599,6 +601,7 @@ impl Tessellator {
|
||||
galley: &super::Galley,
|
||||
text_style: super::TextStyle,
|
||||
color: Color32,
|
||||
fake_italics: bool,
|
||||
out: &mut Mesh,
|
||||
) {
|
||||
if color == Color32::TRANSPARENT {
|
||||
@@ -636,12 +639,42 @@ impl Tessellator {
|
||||
left_top.x = font.round_to_pixel(left_top.x); // Pixel-perfection.
|
||||
left_top.y = font.round_to_pixel(left_top.y); // Pixel-perfection.
|
||||
|
||||
let pos = Rect::from_min_max(left_top, left_top + glyph.size);
|
||||
let rect = Rect::from_min_max(left_top, left_top + glyph.size);
|
||||
let uv = Rect::from_min_max(
|
||||
pos2(glyph.min.0 as f32 / tex_w, glyph.min.1 as f32 / tex_h),
|
||||
pos2(glyph.max.0 as f32 / tex_w, glyph.max.1 as f32 / tex_h),
|
||||
);
|
||||
out.add_rect_with_uv(pos, uv, color);
|
||||
|
||||
if fake_italics {
|
||||
let idx = out.vertices.len() as u32;
|
||||
out.add_triangle(idx, idx + 1, idx + 2);
|
||||
out.add_triangle(idx + 2, idx + 1, idx + 3);
|
||||
|
||||
let top_offset = rect.height() * 0.25 * Vec2::X;
|
||||
|
||||
out.vertices.push(Vertex {
|
||||
pos: rect.left_top() + top_offset,
|
||||
uv: uv.left_top(),
|
||||
color,
|
||||
});
|
||||
out.vertices.push(Vertex {
|
||||
pos: rect.right_top() + top_offset,
|
||||
uv: uv.right_top(),
|
||||
color,
|
||||
});
|
||||
out.vertices.push(Vertex {
|
||||
pos: rect.left_bottom(),
|
||||
uv: uv.left_bottom(),
|
||||
color,
|
||||
});
|
||||
out.vertices.push(Vertex {
|
||||
pos: rect.right_bottom(),
|
||||
uv: uv.right_bottom(),
|
||||
color,
|
||||
});
|
||||
} else {
|
||||
out.add_rect_with_uv(rect, uv, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
if line.ends_with_newline {
|
||||
|
||||
Reference in New Issue
Block a user