Struct imgui::Context

source ·
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

source

pub fn create() -> Self

Creates a new active imgui-rs context.

Panics

Panics if an active context already exists

source

pub fn create_with_shared_font_atlas(shared_font_atlas: SharedFontAtlas) -> Self

Creates a new active imgui-rs context with a shared font atlas.

Panics

Panics if an active context already exists

source

pub fn suspend(self) -> SuspendedContext

Suspends this context so another context can be the active context.

source

pub fn ini_filename(&self) -> Option<PathBuf>

Returns the path to the ini file, or None if not set

source

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.

source

pub fn log_filename(&self) -> Option<PathBuf>

Returns the path to the log file, or None if not set

source

pub fn set_log_filename<T: Into<Option<PathBuf>>>(&mut self, log_filename: T)

Sets the log filename (default is “imgui_log.txt”).

source

pub fn platform_name(&self) -> Option<&str>

Returns the backend platform name, or None if not set

source

pub fn set_platform_name<T: Into<Option<String>>>(&mut self, platform_name: T)

Sets the backend platform name

source

pub fn renderer_name(&self) -> Option<&str>

Returns the backend renderer name, or None if not set

source

pub fn set_renderer_name<T: Into<Option<String>>>(&mut self, renderer_name: T)

Sets the backend renderer name

source

pub fn load_ini_settings(&mut self, data: &str)

Loads settings from a string slice containing settings in .Ini file format

source

pub fn save_ini_settings(&mut self, buf: &mut String)

Saves settings to a mutable string buffer in .Ini file format

source

pub fn set_clipboard_backend<T: ClipboardBackend>(&mut self, backend: T)

Sets the clipboard backend used for clipboard operations

source§

impl Context

source

pub fn io(&self) -> &Io

Returns an immutable reference to the inputs/outputs object

source

pub fn io_mut(&mut self) -> &mut Io

Returns a mutable reference to the inputs/outputs object

source

pub fn style(&self) -> &Style

Returns an immutable reference to the user interface style

source

pub fn style_mut(&mut self) -> &mut Style

Returns a mutable reference to the user interface style

source

pub fn fonts(&mut self) -> &mut FontAtlas

Returns a mutable reference to the font atlas.

source

pub fn clone_shared_font_atlas(&mut self) -> Option<SharedFontAtlas>

Attempts to clone the interior shared font atlas if it exists.

source

pub fn frame(&mut self) -> &mut Ui

Starts a new frame. Use new_frame instead.

source

pub fn new_frame(&mut self) -> &mut Ui

Starts a new frame and returns an Ui instance for constructing a user interface.

source

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.

source

pub fn mouse_cursor(&self) -> Option<MouseCursor>

Returns the currently desired mouse cursor type.

This was set last frame by the Ui object, and will be reset when new_frame is called.

Returns None if no cursor should be displayed

source§

impl Context

source

pub fn platform_io(&self) -> &PlatformIo

Returns an immutable reference to the Context’s PlatformIo object.

source

pub fn platform_io_mut(&mut self) -> &mut PlatformIo

Returns a mutable reference to the Context’s PlatformIo object.

source

pub fn main_viewport(&self) -> &Viewport

Returns an immutable reference to the main Viewport

source

pub fn main_viewport_mut(&mut self) -> &mut Viewport

Returns a mutable reference to the main Viewport

source

pub fn viewport_by_id(&self, id: Id) -> Option<&Viewport>

Tries to find and return a Viewport identified by id.

Returns

A Viewport with the given id or None if no Viewport exists.

source

pub fn viewport_by_id_mut(&mut self, id: Id) -> Option<&mut Viewport>

Tries to find and return a Viewport identified by id.

Returns

A Viewport with the given id or None if no Viewport exists.

source

pub fn viewports(&self) -> impl Iterator<Item = &Viewport>

Returns an iterator containing every Viewport that currently exists.

source

pub fn viewports_mut(&mut self) -> impl Iterator<Item = &mut Viewport>

Returns an iterator containing every Viewport that currently exists.

source

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.

source

pub fn set_renderer_backend<T: RendererViewportBackend>(&mut self, backend: T)

Installs a RendererViewportBackend that is used to render extra viewports created by ImGui.

source

pub fn update_platform_windows(&mut self)

Updates the extra Viewports created by ImGui. Has to be called every frame if Viewports are enabled.

source

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.

source§

impl Context

source

pub fn time(&self) -> f64

Returns the global imgui-rs time.

Incremented by Io::delta_time every frame.

source

pub fn frame_count(&self) -> i32

Returns the global imgui-rs frame count.

Incremented by 1 every frame.

Trait Implementations§

source§

impl Debug for Context

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Context

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Context

§

impl !Send for Context

§

impl !Sync for Context

§

impl Unpin for Context

§

impl !UnwindSafe for Context

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.