Context

Struct Context 

Source
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
// context

Never 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(); // PANIC

Implementations§

Source§

impl Context

Source

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.

Source

pub fn try_create_with_shared_font_atlas( shared_font_atlas: SharedFontAtlas, ) -> Result<Context, ImGuiError>

Tries to create a new active Dear ImGui context with a shared font atlas.

Source

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().

Source

pub fn create_with_shared_font_atlas( shared_font_atlas: SharedFontAtlas, ) -> Context

Creates a new active Dear ImGui context with a shared font atlas (panics on error).

Source

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

Returns a mutable reference to the active context’s IO object

Source

pub fn io(&self) -> &Io

Get access to the IO structure

Source

pub fn style(&self) -> &Style

Get access to the Style structure

Source

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

Get mutable access to the Style structure

Source

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

Creates a new frame and returns a Ui object for building the interface

Source

pub fn frame_with<F, R>(&mut self, f: F) -> R
where F: FnOnce(&Ui) -> R,

Create a new frame with a callback

Source

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.

Source

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().

Source

pub fn set_ini_filename<P>( &mut self, filename: Option<P>, ) -> Result<(), ImGuiError>
where P: Into<PathBuf>,

Sets the INI filename for settings persistence

§Errors

Returns an error if the filename contains null bytes

Source

pub fn set_log_filename<P>( &mut self, filename: Option<P>, ) -> Result<(), ImGuiError>
where P: Into<PathBuf>,

Sets the log filename

§Errors

Returns an error if the filename contains null bytes

Source

pub fn set_platform_name<S>( &mut self, name: Option<S>, ) -> Result<(), ImGuiError>
where S: Into<String>,

Sets the platform name

§Errors

Returns an error if the name contains null bytes

Source

pub fn set_renderer_name<S>( &mut self, name: Option<S>, ) -> Result<(), ImGuiError>
where S: Into<String>,

Sets the renderer name

§Errors

Returns an error if the name contains null bytes

Source

pub fn suspend(self) -> SuspendedContext

Suspends this context so another context can be the active context

Source

pub fn push_font(&mut self, font: &Font)

Push a font onto the font stack

Source

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().

Source

pub fn current_font(&self) -> &Font

Get the current font

Source

pub fn current_font_size(&self) -> f32

Get the current font size

Source

pub fn font_atlas(&self) -> FontAtlas

Get the font atlas from the IO structure

Source

pub fn font_atlas_mut(&mut self) -> FontAtlas

Get a mutable reference to the font atlas from the IO structure

Source

pub fn fonts(&mut self) -> FontAtlas

Returns the font atlas (alias for font_atlas_mut)

This provides compatibility with imgui-rs naming convention

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 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>(&mut self, backend: T)

Sets the clipboard backend used for clipboard operations

Trait Implementations§

Source§

impl Debug for Context

Source§

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

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 !Freeze for Context

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more