pub struct Context { /* private fields */ }Expand description
An imgui context.
A context needs to be created to access most library functions. Due to current Dear ImGui design choices, at most one active Context can exist at any time. This limitation will likely be removed in a future Dear ImGui version.
If you need more than one context, you can use suspended contexts. As long as only one context is active at a time, it’s possible to have multiple independent contexts.
§Examples
Creating a new active context:
let ctx = dear_imgui_rs::Context::create();
// ctx is dropped naturally when it goes out of scope, which deactivates and destroys the
// contextNever try to create an active context when another one is active:
let ctx1 = dear_imgui_rs::Context::create();
let ctx2 = dear_imgui_rs::Context::create(); // PANICImplementations§
Source§impl Context
impl Context
Sourcepub fn try_create() -> Result<Context, ImGuiError>
pub fn try_create() -> Result<Context, ImGuiError>
Tries to create a new active Dear ImGui context.
Returns an error if another context is already active or creation fails.
Tries to create a new active Dear ImGui context with a shared font atlas.
Sourcepub fn create() -> Context
pub fn create() -> Context
Creates a new active Dear ImGui context (panics on error).
This aligns with imgui-rs behavior. For fallible creation use try_create().
Creates a new active Dear ImGui context with a shared font atlas (panics on error).
Sourcepub fn io_mut(&mut self) -> &mut Io
pub fn io_mut(&mut self) -> &mut Io
Returns a mutable reference to the active context’s IO object
Sourcepub fn frame(&mut self) -> &mut Ui
pub fn frame(&mut self) -> &mut Ui
Creates a new frame and returns a Ui object for building the interface
Sourcepub fn frame_with<F, R>(&mut self, f: F) -> R
pub fn frame_with<F, R>(&mut self, f: F) -> R
Create a new frame with a callback
Sourcepub fn render(&mut self) -> &DrawData
pub fn render(&mut self) -> &DrawData
Renders the frame and returns a reference to the resulting draw data
This finalizes the Dear ImGui frame and prepares all draw data for rendering. The returned draw data contains all the information needed to render the frame.
Sourcepub fn draw_data(&self) -> Option<&DrawData>
pub fn draw_data(&self) -> Option<&DrawData>
Gets the draw data for the current frame
This returns the draw data without calling render. Only valid after
render() has been called and before the next new_frame().
Sourcepub fn set_ini_filename<P>(
&mut self,
filename: Option<P>,
) -> Result<(), ImGuiError>
pub fn set_ini_filename<P>( &mut self, filename: Option<P>, ) -> Result<(), ImGuiError>
Sets the INI filename for settings persistence
§Errors
Returns an error if the filename contains null bytes
Sourcepub fn set_log_filename<P>(
&mut self,
filename: Option<P>,
) -> Result<(), ImGuiError>
pub fn set_log_filename<P>( &mut self, filename: Option<P>, ) -> Result<(), ImGuiError>
Sourcepub fn set_platform_name<S>(
&mut self,
name: Option<S>,
) -> Result<(), ImGuiError>
pub fn set_platform_name<S>( &mut self, name: Option<S>, ) -> Result<(), ImGuiError>
Sourcepub fn set_renderer_name<S>(
&mut self,
name: Option<S>,
) -> Result<(), ImGuiError>
pub fn set_renderer_name<S>( &mut self, name: Option<S>, ) -> Result<(), ImGuiError>
Sourcepub fn suspend(self) -> SuspendedContext
pub fn suspend(self) -> SuspendedContext
Suspends this context so another context can be the active context
Sourcepub fn pop_font(&mut self)
pub fn pop_font(&mut self)
Pop a font from the font stack
This restores the previous font. Must be paired with a call to push_font().
Sourcepub fn current_font(&self) -> &Font
pub fn current_font(&self) -> &Font
Get the current font
Sourcepub fn current_font_size(&self) -> f32
pub fn current_font_size(&self) -> f32
Get the current font size
Sourcepub fn font_atlas(&self) -> FontAtlas
pub fn font_atlas(&self) -> FontAtlas
Get the font atlas from the IO structure
Sourcepub fn font_atlas_mut(&mut self) -> FontAtlas
pub fn font_atlas_mut(&mut self) -> FontAtlas
Get a mutable reference to the font atlas from the IO structure
Sourcepub fn fonts(&mut self) -> FontAtlas
pub fn fonts(&mut self) -> FontAtlas
Returns the font atlas (alias for font_atlas_mut)
This provides compatibility with imgui-rs naming convention
Attempts to clone the interior shared font atlas if it exists.
Sourcepub fn load_ini_settings(&mut self, data: &str)
pub fn load_ini_settings(&mut self, data: &str)
Loads settings from a string slice containing settings in .Ini file format
Sourcepub fn save_ini_settings(&mut self, buf: &mut String)
pub fn save_ini_settings(&mut self, buf: &mut String)
Saves settings to a mutable string buffer in .Ini file format
Sourcepub fn set_clipboard_backend<T>(&mut self, backend: T)where
T: ClipboardBackend,
pub fn set_clipboard_backend<T>(&mut self, backend: T)where
T: ClipboardBackend,
Sets the clipboard backend used for clipboard operations