dear_imgui_rs/context/
fonts.rs1use crate::fonts::{FontAtlas, SharedFontAtlas};
2
3use super::Context;
4use super::binding::CTX_MUTEX;
5
6impl Context {
7 pub fn font_atlas(&self) -> &FontAtlas {
13 let _guard = CTX_MUTEX.lock();
14
15 #[cfg(all(target_arch = "wasm32", feature = "wasm-font-atlas-experimental"))]
20 unsafe {
21 let io = self.io_ptr("Context::font_atlas()");
22 let atlas_ptr = (*io).Fonts;
23 assert!(
24 !atlas_ptr.is_null(),
25 "ImGui IO Fonts pointer is null on wasm; provider not initialized?"
26 );
27 FontAtlas::from_raw(atlas_ptr)
28 }
29
30 #[cfg(all(target_arch = "wasm32", not(feature = "wasm-font-atlas-experimental")))]
32 {
33 panic!(
34 "font_atlas() is not supported on wasm32 targets without \
35 `wasm-font-atlas-experimental` feature; \
36 see docs/WASM.md for current limitations."
37 );
38 }
39
40 #[cfg(not(target_arch = "wasm32"))]
41 unsafe {
42 let io = self.io_ptr("Context::font_atlas()");
43 let atlas_ptr = (*io).Fonts;
44 FontAtlas::from_raw(atlas_ptr)
45 }
46 }
47
48 pub fn clone_shared_font_atlas(&self) -> Option<SharedFontAtlas> {
50 self.shared_font_atlas.clone()
51 }
52}