mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Support multiple fonts
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use emigui::{math::*, types::*, widgets::*, Region};
|
||||
use emigui::{math::*, types::*, widgets::*, Region, TextStyle};
|
||||
|
||||
pub struct App {
|
||||
checked: bool,
|
||||
@@ -25,6 +25,7 @@ impl Default for App {
|
||||
|
||||
impl App {
|
||||
pub fn show_gui(&mut self, gui: &mut Region) {
|
||||
gui.add(label("Emigui").text_style(TextStyle::Heading));
|
||||
gui.add(label("Emigui is an Immediate mode GUI written in Rust, compiled to WebAssembly, rendered with WebGL."));
|
||||
|
||||
gui.add(label(format!(
|
||||
|
||||
@@ -5,9 +5,7 @@ extern crate wasm_bindgen;
|
||||
|
||||
extern crate emigui;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use emigui::{widgets::label, Emigui, Font, RawInput, TextureAtlas};
|
||||
use emigui::{widgets::label, Emigui, RawInput};
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
@@ -32,20 +30,8 @@ pub struct State {
|
||||
|
||||
impl State {
|
||||
fn new(canvas_id: &str) -> Result<State, JsValue> {
|
||||
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, texture)?;
|
||||
let emigui = Emigui::new();
|
||||
let webgl_painter = webgl::Painter::new(canvas_id, emigui.texture())?;
|
||||
Ok(State {
|
||||
app: Default::default(),
|
||||
emigui,
|
||||
|
||||
@@ -34,7 +34,7 @@ impl Painter {
|
||||
|
||||
pub fn new(
|
||||
canvas_id: &str,
|
||||
(tex_width, tex_height, pixels): (u16, u16, Vec<u8>),
|
||||
(tex_width, tex_height, pixels): (u16, u16, &[u8]),
|
||||
) -> Result<Painter, JsValue> {
|
||||
let document = web_sys::window().unwrap().document().unwrap();
|
||||
let canvas = document.get_element_by_id(canvas_id).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user