summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/renderer.rs18
-rw-r--r--wgpu/src/renderer/widget/checkbox.rs17
-rw-r--r--wgpu/src/text.rs13
-rw-r--r--wgpu/src/text/icons.ttfbin0 -> 4912 bytes
4 files changed, 36 insertions, 12 deletions
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs
index d3bdc878..52764248 100644
--- a/wgpu/src/renderer.rs
+++ b/wgpu/src/renderer.rs
@@ -344,11 +344,27 @@ impl Renderer {
for text in layer.text.iter() {
// Target physical coordinates directly to avoid blurry text
let text = wgpu_glyph::Section {
+ // TODO: We `round` here to avoid rerasterizing text when
+ // its position changes slightly. This can make text feel a
+ // bit "jumpy". We may be able to do better once we improve
+ // our text rendering/caching pipeline.
screen_position: (
(text.screen_position.0 * dpi).round(),
(text.screen_position.1 * dpi).round(),
),
- bounds: (text.bounds.0 * dpi, text.bounds.1 * dpi),
+ // TODO: Fix precision issues with some DPI factors.
+ //
+ // The `ceil` here can cause some words to render on the
+ // same line when they should not.
+ //
+ // Ideally, `wgpu_glyph` should be able to compute layout
+ // using logical positions, and then apply the proper
+ // DPI scaling. This would ensure that both measuring and
+ // rendering follow the same layout rules.
+ bounds: (
+ (text.bounds.0 * dpi).ceil(),
+ (text.bounds.1 * dpi).ceil(),
+ ),
scale: wgpu_glyph::Scale {
x: text.scale.x * dpi,
y: text.scale.y * dpi,
diff --git a/wgpu/src/renderer/widget/checkbox.rs b/wgpu/src/renderer/widget/checkbox.rs
index c2d7911c..aedb821c 100644
--- a/wgpu/src/renderer/widget/checkbox.rs
+++ b/wgpu/src/renderer/widget/checkbox.rs
@@ -74,14 +74,15 @@ impl checkbox::Renderer for Renderer {
(
Primitive::Group {
primitives: if checkbox.is_checked {
- // TODO: Draw an actual icon
- let (check, _) = text::Renderer::draw(
- self,
- &Text::new("X")
- .horizontal_alignment(HorizontalAlignment::Center)
- .vertical_alignment(VerticalAlignment::Center),
- checkbox_layout,
- );
+ let check = Primitive::Text {
+ content: crate::text::CHECKMARK_ICON.to_string(),
+ font: crate::text::BUILTIN_ICONS,
+ size: checkbox_bounds.height * 0.7,
+ bounds: checkbox_bounds,
+ color: [0.3, 0.3, 0.3].into(),
+ horizontal_alignment: HorizontalAlignment::Center,
+ vertical_alignment: VerticalAlignment::Center,
+ };
vec![checkbox_border, checkbox_box, check, label]
} else {
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs
index 3205fe55..da070f5c 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -5,6 +5,13 @@ use crate::Transformation;
use std::cell::RefCell;
use std::collections::HashMap;
+pub const BUILTIN_ICONS: iced_native::Font = iced_native::Font::External {
+ name: "iced_wgpu icons",
+ bytes: include_bytes!("text/icons.ttf"),
+};
+
+pub const CHECKMARK_ICON: char = '\u{F00C}';
+
pub struct Pipeline {
draw_brush: RefCell<wgpu_glyph::GlyphBrush<'static, ()>>,
draw_font_map: RefCell<HashMap<String, wgpu_glyph::FontId>>,
@@ -91,10 +98,10 @@ impl Pipeline {
// TODO: This is a bit hacky. We are loading the debug font as the
// first font in the `draw_brush`. The `measure_brush` does not
- // contain this font.
+ // contain this, hence we subtract 1.
//
- // This should go away once we improve the debug view and integrate
- // it as just another UI app.
+ // This should go away once we unify `draw_brush` and
+ // `measure_brush`.
font_id: wgpu_glyph::FontId(font_id - 1),
..Default::default()
};
diff --git a/wgpu/src/text/icons.ttf b/wgpu/src/text/icons.ttf
new file mode 100644
index 00000000..1c832f86
--- /dev/null
+++ b/wgpu/src/text/icons.ttf
Binary files differ