pub struct Context { /* private fields */ }
Expand description
An imgui-rs 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 = imgui::Context::create();
// ctx is dropped naturally when it goes out of scope, which deactivates and destroys the
// context
Never try to create an active context when another one is active:
let ctx1 = imgui::Context::create();
let ctx2 = imgui::Context::create(); // PANIC
Suspending an active context allows you to create another active context:
let ctx1 = imgui::Context::create();
let suspended1 = ctx1.suspend();
let ctx2 = imgui::Context::create(); // this is now OK
Implementations§
source§impl Context
impl Context
Creates a new active imgui-rs context with a shared font atlas.
Panics
Panics if an active context already exists
sourcepub fn suspend(self) -> SuspendedContext
pub fn suspend(self) -> SuspendedContext
Suspends this context so another context can be the active context.
sourcepub fn ini_filename(&self) -> Option<PathBuf>
pub fn ini_filename(&self) -> Option<PathBuf>
Returns the path to the ini file, or None if not set
sourcepub fn set_ini_filename<T: Into<Option<PathBuf>>>(&mut self, ini_filename: T)
pub fn set_ini_filename<T: Into<Option<PathBuf>>>(&mut self, ini_filename: T)
Sets the path to the ini file (default is “imgui.ini”)
Pass None to disable automatic .Ini saving.
sourcepub fn log_filename(&self) -> Option<PathBuf>
pub fn log_filename(&self) -> Option<PathBuf>
Returns the path to the log file, or None if not set
sourcepub fn set_log_filename<T: Into<Option<PathBuf>>>(&mut self, log_filename: T)
pub fn set_log_filename<T: Into<Option<PathBuf>>>(&mut self, log_filename: T)
Sets the log filename (default is “imgui_log.txt”).
sourcepub fn platform_name(&self) -> Option<&str>
pub fn platform_name(&self) -> Option<&str>
Returns the backend platform name, or None if not set
sourcepub fn set_platform_name<T: Into<Option<String>>>(&mut self, platform_name: T)
pub fn set_platform_name<T: Into<Option<String>>>(&mut self, platform_name: T)
Sets the backend platform name
sourcepub fn renderer_name(&self) -> Option<&str>
pub fn renderer_name(&self) -> Option<&str>
Returns the backend renderer name, or None if not set
sourcepub fn set_renderer_name<T: Into<Option<String>>>(&mut self, renderer_name: T)
pub fn set_renderer_name<T: Into<Option<String>>>(&mut self, renderer_name: T)
Sets the backend renderer name
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: ClipboardBackend>(&mut self, backend: T)
pub fn set_clipboard_backend<T: ClipboardBackend>(&mut self, backend: T)
Sets the clipboard backend used for clipboard operations
source§impl Context
impl Context
sourcepub fn style_mut(&mut self) -> &mut Style
pub fn style_mut(&mut self) -> &mut Style
Returns a mutable reference to the user interface style
Attempts to clone the interior shared font atlas if it exists.
sourcepub fn new_frame(&mut self) -> &mut Ui
pub fn new_frame(&mut self) -> &mut Ui
Starts a new frame and returns an Ui
instance for constructing a user interface.
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 should only be called after calling new_frame
.
sourcepub fn mouse_cursor(&self) -> Option<MouseCursor>
pub fn mouse_cursor(&self) -> Option<MouseCursor>
source§impl Context
impl Context
sourcepub fn platform_io(&self) -> &PlatformIo
pub fn platform_io(&self) -> &PlatformIo
Returns an immutable reference to the Context’s PlatformIo
object.
sourcepub fn platform_io_mut(&mut self) -> &mut PlatformIo
pub fn platform_io_mut(&mut self) -> &mut PlatformIo
Returns a mutable reference to the Context’s PlatformIo
object.
sourcepub fn main_viewport(&self) -> &Viewport
pub fn main_viewport(&self) -> &Viewport
Returns an immutable reference to the main Viewport
sourcepub fn main_viewport_mut(&mut self) -> &mut Viewport
pub fn main_viewport_mut(&mut self) -> &mut Viewport
Returns a mutable reference to the main Viewport
sourcepub fn viewport_by_id(&self, id: Id) -> Option<&Viewport>
pub fn viewport_by_id(&self, id: Id) -> Option<&Viewport>
sourcepub fn viewport_by_id_mut(&mut self, id: Id) -> Option<&mut Viewport>
pub fn viewport_by_id_mut(&mut self, id: Id) -> Option<&mut Viewport>
sourcepub fn viewports(&self) -> impl Iterator<Item = &Viewport>
pub fn viewports(&self) -> impl Iterator<Item = &Viewport>
Returns an iterator containing every Viewport
that currently exists.
sourcepub fn viewports_mut(&mut self) -> impl Iterator<Item = &mut Viewport>
pub fn viewports_mut(&mut self) -> impl Iterator<Item = &mut Viewport>
Returns an iterator containing every Viewport
that currently exists.
sourcepub fn set_platform_backend<T: PlatformViewportBackend>(&mut self, backend: T)
pub fn set_platform_backend<T: PlatformViewportBackend>(&mut self, backend: T)
Installs a PlatformViewportBackend
that is used to
create platform windows on demand if a window is dragged outside of the main viewport.
sourcepub fn set_renderer_backend<T: RendererViewportBackend>(&mut self, backend: T)
pub fn set_renderer_backend<T: RendererViewportBackend>(&mut self, backend: T)
Installs a RendererViewportBackend
that is used to
render extra viewports created by ImGui.
sourcepub fn update_platform_windows(&mut self)
pub fn update_platform_windows(&mut self)
Updates the extra Viewports created by ImGui. Has to be called every frame if Viewports are enabled.
sourcepub fn render_platform_windows_default(&mut self)
pub fn render_platform_windows_default(&mut self)
Basically just calls the PlatformViewportBackend
and RendererViewportBackend
functions. If you render your extra viewports manually this function is not needed at all.