chore(release): v0.1.4 - 1:1 SyncLyrics, scroll isolation, object-fit cover, Concerts icon, friends' likes & duplicate-title albums
This commit is contained in:
parent
0b2561503f
commit
f063382410
21 changed files with 1287 additions and 288 deletions
|
|
@ -452,6 +452,68 @@ impl TextEngine {
|
|||
size
|
||||
}
|
||||
|
||||
/// Draw wrapped multi-line text vertically centered inside `rect` and uniformly scaled
|
||||
/// around `rect.center()` by `scale` (1-to-1 CSS `transform: scale(...)` with zero wrap-jump
|
||||
/// or fractional-size glyph atlas churn).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn draw_text_wrapped_scaled(
|
||||
&mut self,
|
||||
dl: &mut DisplayList,
|
||||
textures: &mut TextureRegistry,
|
||||
text: &str,
|
||||
style: TextStyle,
|
||||
rect: Rect,
|
||||
scale: f32,
|
||||
align: TextAlign,
|
||||
) -> Vec2 {
|
||||
if text.is_empty() || style.color.a == 0 || rect.w <= 1.0 || scale <= 0.001 {
|
||||
return Vec2::ZERO;
|
||||
}
|
||||
let (key, size) = self.get_or_shape(text, style, Some(rect.w), None, false, align);
|
||||
let origin = Pos2::new(rect.x, rect.center_y() - size.y * 0.5);
|
||||
if (scale - 1.0).abs() < 0.0005 {
|
||||
self.emit_cached_buffer(dl, textures, key, origin, style.color, None);
|
||||
return size;
|
||||
}
|
||||
let Some((buffer, _)) = self.shape_cache.get(&key) else {
|
||||
return size;
|
||||
};
|
||||
|
||||
let dpi = self.scale_factor;
|
||||
let inv_dpi = 1.0 / dpi;
|
||||
let origin_px = (origin.x * dpi).round();
|
||||
let center = rect.center();
|
||||
|
||||
let mut glyphs_to_draw = Vec::with_capacity(64);
|
||||
for run in buffer.layout_runs() {
|
||||
let baseline_py = ((origin.y + run.line_y) * dpi).floor();
|
||||
for glyph in run.glyphs.iter() {
|
||||
let phys = glyph.physical((0.0, 0.0), dpi);
|
||||
glyphs_to_draw.push((phys, baseline_py));
|
||||
}
|
||||
}
|
||||
for (phys, baseline_py) in glyphs_to_draw {
|
||||
if let Some(entry) = self.atlas.get_or_insert(
|
||||
phys.cache_key,
|
||||
&mut self.font_system,
|
||||
&mut self.swash_cache,
|
||||
textures,
|
||||
) {
|
||||
let gx = (origin_px + (phys.x + entry.left) as f32) * inv_dpi;
|
||||
let gy = (baseline_py + (phys.y - entry.top) as f32) * inv_dpi;
|
||||
let gw = entry.width as f32 * inv_dpi;
|
||||
let gh = entry.height as f32 * inv_dpi;
|
||||
|
||||
let sx = center.x + (gx - center.x) * scale;
|
||||
let sy = center.y + (gy - center.y) * scale;
|
||||
let sw = gw * scale;
|
||||
let sh = gh * scale;
|
||||
dl.push_glyph(Rect::from_xywh(sx, sy, sw, sh), entry.uv, style.color);
|
||||
}
|
||||
}
|
||||
size
|
||||
}
|
||||
|
||||
/// Draw multi-span rich text (e.g. clickable `SeparatedArtists` or `Title + Version`) inside `rect`.
|
||||
/// Returns screen-space bounding `Rect`s for every span whose `metadata != 0` so callers can
|
||||
/// perform exact per-span hover & click hit-testing!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue