mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 13:50:04 -04:00
Fix WASM build: rename ScaledMetrics to StyledMetrics, fix web-sys API
- ScaledMetrics was renamed to StyledMetrics but canvas_renderer.rs and font.rs still referenced the old name - web-sys 0.3.91 changed get_image_data params from f64 to i32
This commit is contained in:
@@ -4,7 +4,7 @@ use wasm_bindgen::prelude::*;
|
|||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
|
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
|
||||||
|
|
||||||
use crate::text::font::ScaledMetrics;
|
use crate::text::font::StyledMetrics;
|
||||||
|
|
||||||
/// Data for a glyph rendered via HTML5 canvas
|
/// Data for a glyph rendered via HTML5 canvas
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -63,7 +63,7 @@ impl CanvasGlyphRenderer {
|
|||||||
pub fn render_glyph(
|
pub fn render_glyph(
|
||||||
&mut self,
|
&mut self,
|
||||||
chr: char,
|
chr: char,
|
||||||
metrics: &ScaledMetrics,
|
metrics: &StyledMetrics,
|
||||||
font_families: &[String],
|
font_families: &[String],
|
||||||
bin: crate::text::font::SubpixelBin,
|
bin: crate::text::font::SubpixelBin,
|
||||||
) -> Option<CanvasGlyphData> {
|
) -> Option<CanvasGlyphData> {
|
||||||
@@ -162,7 +162,7 @@ impl CanvasGlyphRenderer {
|
|||||||
// Extract image data (now at device pixel resolution)
|
// Extract image data (now at device pixel resolution)
|
||||||
let image_data = self
|
let image_data = self
|
||||||
.context
|
.context
|
||||||
.get_image_data(0.0, 0.0, width as f64, height as f64)
|
.get_image_data(0, 0, width as i32, height as i32)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
|
|
||||||
let rgba_data = image_data.data().0;
|
let rgba_data = image_data.data().0;
|
||||||
@@ -210,7 +210,7 @@ fn ensure_canvas_renderer() -> Result<(), JsValue> {
|
|||||||
/// Render a glyph using the thread-local canvas renderer
|
/// Render a glyph using the thread-local canvas renderer
|
||||||
pub fn render_glyph_with_canvas(
|
pub fn render_glyph_with_canvas(
|
||||||
chr: char,
|
chr: char,
|
||||||
metrics: &ScaledMetrics,
|
metrics: &StyledMetrics,
|
||||||
font_families: &[String],
|
font_families: &[String],
|
||||||
bin: crate::text::font::SubpixelBin,
|
bin: crate::text::font::SubpixelBin,
|
||||||
) -> Option<CanvasGlyphData> {
|
) -> Option<CanvasGlyphData> {
|
||||||
|
|||||||
@@ -644,7 +644,7 @@ impl FontFace {
|
|||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
fn try_allocate_canvas_glyph_static(
|
fn try_allocate_canvas_glyph_static(
|
||||||
atlas: &mut TextureAtlas,
|
atlas: &mut TextureAtlas,
|
||||||
metrics: &ScaledMetrics,
|
metrics: &StyledMetrics,
|
||||||
chr: char,
|
chr: char,
|
||||||
bin: SubpixelBin,
|
bin: SubpixelBin,
|
||||||
) -> Option<GlyphAllocation> {
|
) -> Option<GlyphAllocation> {
|
||||||
@@ -826,7 +826,7 @@ fn invisible_char(c: char) -> bool {
|
|||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub(super) fn allocate_canvas_glyph(
|
pub(super) fn allocate_canvas_glyph(
|
||||||
atlas: &mut TextureAtlas,
|
atlas: &mut TextureAtlas,
|
||||||
metrics: &ScaledMetrics,
|
metrics: &StyledMetrics,
|
||||||
canvas_data: crate::text::canvas_renderer::CanvasGlyphData,
|
canvas_data: crate::text::canvas_renderer::CanvasGlyphData,
|
||||||
) -> GlyphAllocation {
|
) -> GlyphAllocation {
|
||||||
use crate::text::canvas_renderer::CanvasGlyphData;
|
use crate::text::canvas_renderer::CanvasGlyphData;
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ fn layout_section(
|
|||||||
|
|
||||||
let mut last_glyph_id = None;
|
let mut last_glyph_id = None;
|
||||||
|
|
||||||
// Optimization: only recompute `ScaledMetrics` when the concrete `FontImpl` changes.
|
// Optimization: only recompute `StyledMetrics` when the concrete `FontImpl` changes.
|
||||||
let mut current_font = FontFaceKey::INVALID;
|
let mut current_font = FontFaceKey::INVALID;
|
||||||
let mut current_font_face_metrics = StyledMetrics::default();
|
let mut current_font_face_metrics = StyledMetrics::default();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user