mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
Choose your own font and size (#1154)
* Refactor text layout: don't need &Fonts in all functions * Replace indexing in Fonts with member function * Wrap Fonts in a Mutex * Remove mutex for Font::glyph_info_cache * Remove RwLock around Font::characters * Put FontsImpl and GalleyCache behind the same Mutex * Round font sizes to whole pixels before deduplicating them * Make TextStyle !Copy * Implement user-named TextStyle:s * round font size earlier * Cache fonts based on family and size * Move TextStyle into egui and Style * Remove body_text_style * Query graphics about max texture size and use that as font atlas size * Recreate texture atlas when it is getting full
This commit is contained in:
@@ -143,6 +143,8 @@ impl AppRunner {
|
||||
textures_delta: Default::default(),
|
||||
};
|
||||
|
||||
runner.input.raw.max_texture_side = runner.painter.max_texture_side();
|
||||
|
||||
{
|
||||
runner
|
||||
.app
|
||||
|
||||
@@ -40,6 +40,10 @@ impl WrappedGlowPainter {
|
||||
}
|
||||
|
||||
impl crate::Painter for WrappedGlowPainter {
|
||||
fn max_texture_side(&self) -> usize {
|
||||
self.painter.max_texture_side()
|
||||
}
|
||||
|
||||
fn set_texture(&mut self, tex_id: egui::TextureId, delta: &egui::epaint::ImageDelta) {
|
||||
self.painter.set_texture(&self.glow_ctx, tex_id, delta);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use wasm_bindgen::prelude::JsValue;
|
||||
|
||||
pub trait Painter {
|
||||
/// Max size of one side of a texture.
|
||||
fn max_texture_side(&self) -> usize;
|
||||
|
||||
fn set_texture(&mut self, tex_id: egui::TextureId, delta: &egui::epaint::ImageDelta);
|
||||
|
||||
fn free_texture(&mut self, tex_id: egui::TextureId);
|
||||
|
||||
@@ -289,6 +289,21 @@ impl epi::NativeTexture for WebGlPainter {
|
||||
}
|
||||
|
||||
impl crate::Painter for WebGlPainter {
|
||||
fn max_texture_side(&self) -> usize {
|
||||
if let Ok(max_texture_side) = self
|
||||
.gl
|
||||
.get_parameter(web_sys::WebGlRenderingContext::MAX_TEXTURE_SIZE)
|
||||
{
|
||||
if let Some(max_texture_side) = max_texture_side.as_f64() {
|
||||
return max_texture_side as usize;
|
||||
}
|
||||
}
|
||||
|
||||
crate::console_error("Failed to query max texture size");
|
||||
|
||||
2048
|
||||
}
|
||||
|
||||
fn set_texture(&mut self, tex_id: egui::TextureId, delta: &egui::epaint::ImageDelta) {
|
||||
match &delta.image {
|
||||
egui::ImageData::Color(image) => {
|
||||
|
||||
@@ -273,6 +273,21 @@ impl epi::NativeTexture for WebGl2Painter {
|
||||
}
|
||||
|
||||
impl crate::Painter for WebGl2Painter {
|
||||
fn max_texture_side(&self) -> usize {
|
||||
if let Ok(max_texture_side) = self
|
||||
.gl
|
||||
.get_parameter(web_sys::WebGl2RenderingContext::MAX_TEXTURE_SIZE)
|
||||
{
|
||||
if let Some(max_texture_side) = max_texture_side.as_f64() {
|
||||
return max_texture_side as usize;
|
||||
}
|
||||
}
|
||||
|
||||
crate::console_error("Failed to query max texture size");
|
||||
|
||||
2048
|
||||
}
|
||||
|
||||
fn set_texture(&mut self, tex_id: egui::TextureId, delta: &egui::epaint::ImageDelta) {
|
||||
match &delta.image {
|
||||
egui::ImageData::Color(image) => {
|
||||
|
||||
Reference in New Issue
Block a user