summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-14 03:00:33 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-14 03:00:57 +0100
commit00479d8bcdf619dab8a3eaa47ff551c6c3a0ac1a (patch)
tree467f700ebc630d1f27baf620eb6f6e8306351d7e /wgpu
parentbe5466a0a7ee6a16b5c07e61c9a22068ad8e127f (diff)
downloadiced-00479d8bcdf619dab8a3eaa47ff551c6c3a0ac1a.tar.gz
iced-00479d8bcdf619dab8a3eaa47ff551c6c3a0ac1a.tar.bz2
iced-00479d8bcdf619dab8a3eaa47ff551c6c3a0ac1a.zip
Fix text bounds in `iced_wgpu` on nonintegral DPI
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/renderer.rs18
-rw-r--r--wgpu/src/text.rs2
2 files changed, 18 insertions, 2 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/text.rs b/wgpu/src/text.rs
index 3205fe55..81fc1fb5 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -91,7 +91,7 @@ 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 font, hence we subtract 1.
//
// This should go away once we improve the debug view and integrate
// it as just another UI app.