1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Share font atlas

This commit is contained in:
Emil Ernerfeldt
2019-01-13 00:19:53 +01:00
parent 2fc191eed4
commit 1b8a45a514
7 changed files with 31 additions and 35 deletions

View File

@@ -5,9 +5,9 @@ extern crate wasm_bindgen;
extern crate emigui;
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use emigui::{widgets::label, Emigui, Font, RawInput};
use emigui::{widgets::label, Emigui, Font, RawInput, TextureAtlas};
use wasm_bindgen::prelude::*;
@@ -32,9 +32,20 @@ pub struct State {
impl State {
fn new(canvas_id: &str) -> Result<State, JsValue> {
let font = Arc::new(Font::new(20));
let mut atlas = TextureAtlas::new(128, 8); // TODO: better default?
// Make one white pixel for use for various stuff:
let pos = atlas.allocate((1, 1));
atlas[pos] = 255;
let atlas = Arc::new(Mutex::new(atlas));
let font = Arc::new(Font::new(20, atlas.clone()));
let texture = atlas.lock().unwrap().clone().into_texture();
let emigui = Emigui::new(font);
let webgl_painter = webgl::Painter::new(canvas_id, emigui.texture())?;
let webgl_painter = webgl::Painter::new(canvas_id, texture)?;
Ok(State {
app: Default::default(),
emigui,

View File

@@ -34,7 +34,7 @@ impl Painter {
pub fn new(
canvas_id: &str,
(tex_width, tex_height, pixels): (u16, u16, &[u8]),
(tex_width, tex_height, pixels): (u16, u16, Vec<u8>),
) -> Result<Painter, JsValue> {
let document = web_sys::window().unwrap().document().unwrap();
let canvas = document.get_element_by_id(canvas_id).unwrap();