Struct egui::CtxRef[][src]

pub struct CtxRef(_);

A wrapper around Arc<Context>. This is how you will normally create and access a Context.

Almost all methods are marked &self, Context has interior mutability (protected by mutexes).

CtxRef is cheap to clone, and any clones refers to the same mutable data.

Example:

let mut ctx = egui::CtxRef::default();

// Game loop:
loop {
    let raw_input = egui::RawInput::default();
    ctx.begin_frame(raw_input);

    egui::CentralPanel::default().show(&ctx, |ui| {
        ui.label("Hello world!");
        if ui.button("Click me").clicked() {
            /* take some action here */
        }
    });

    let (output, shapes) = ctx.end_frame();
    let clipped_meshes = ctx.tessellate(shapes); // create triangles to paint
    handle_output(output);
    paint(clipped_meshes);
}

Implementations

impl CtxRef[src]

pub fn begin_frame(&mut self, new_input: RawInput)[src]

Call at the start of every frame. Match with a call to Context::end_frame.

This will modify the internal reference to point to a new generation of Context. Any old clones of this CtxRef will refer to the old Context, which will not get new input.

Put your widgets into a SidePanel, TopPanel, CentralPanel, Window or Area.

pub fn debug_painter(&self) -> Painter[src]

Methods from Deref<Target = Context>

pub fn available_rect(&self) -> Rect[src]

How much space is still available after panels has been added. This is the “background” area, what egui doesn’t cover with panels (but may cover with windows). This is also the area to which windows are constrained.

pub fn memory(&self) -> MutexGuard<'_, Memory>[src]

Stores all the egui state. If you want to store/restore egui, serialize this.

pub fn output(&self) -> MutexGuard<'_, Output>[src]

What egui outputs each frame.

pub fn request_repaint(&self)[src]

Call this if there is need to repaint the UI, i.e. if you are showing an animation. If this is called at least once in a frame, then there will be another frame right after this. Call as many times as you wish, only one repaint will be issued.

pub fn input(&self) -> &InputState[src]

pub fn fonts(&self) -> &Fonts[src]

Not valid until first call to CtxRef::begin_frame(). That’s because since we don’t know the proper pixels_per_point until then.

pub fn texture(&self) -> Arc<Texture>[src]

The egui texture, containing font characters etc. Not valid until first call to CtxRef::begin_frame(). That’s because since we don’t know the proper pixels_per_point until then.

pub fn set_fonts(&self, font_definitions: FontDefinitions)[src]

Will become active at the start of the next frame.

pub fn style(&self) -> Arc<Style>[src]

The Style used by all subsequent windows, panels etc.

pub fn set_style(&self, style: impl Into<Arc<Style>>)[src]

The Style used by all new windows, panels etc.

Example:

let mut style: egui::Style = (*ctx.style()).clone();
style.spacing.item_spacing = egui::vec2(10.0, 20.0);
ctx.set_style(style);

pub fn set_visuals(&self, visuals: Visuals)[src]

The Visuals used by all subsequent windows, panels etc.

You can also use Ui::visuals_mut to change the visuals of a single Ui.

Example:

ctx.set_visuals(egui::Visuals::light()); // Switch to light mode

pub fn pixels_per_point(&self) -> f32[src]

The number of physical pixels for each logical point.

pub fn set_pixels_per_point(&self, pixels_per_point: f32)[src]

Set the number of physical pixels for each logical point. Will become active at the start of the next frame.

Note that this may be overwritten by input from the integration via RawInput::pixels_per_point. For instance, when using egui_web the browsers native zoom level will always be used.

#[must_use]
pub fn end_frame(&self) -> (Output, Vec<ClippedShape>)
[src]

Call at the end of each frame. Returns what has happened this frame crate::Output as well as what you need to paint. You can transform the returned shapes into triangles with a call to Context::tessellate.

pub fn tessellate(&self, shapes: Vec<ClippedShape>) -> Vec<ClippedMesh>[src]

Tessellate the given shapes into triangle meshes.

pub fn used_rect(&self) -> Rect[src]

How much space is used by panels and windows.

pub fn used_size(&self) -> Vec2[src]

How much space is used by panels and windows. You can shrink your egui area to this size and still fit all egui components.

pub fn is_pointer_over_area(&self) -> bool[src]

Is the pointer (mouse/touch) over any egui area?

pub fn wants_pointer_input(&self) -> bool[src]

True if egui is currently interested in the pointer (mouse or touch). Could be the pointer is hovering over a Window or the user is dragging a widget. If false, the pointer is outside of any egui area and so you may be interested in what it is doing (e.g. controlling your game). Returns false if a drag started outside of egui and then moved over an egui area.

pub fn is_using_pointer(&self) -> bool[src]

Is egui currently using the pointer position (e.g. dragging a slider). NOTE: this will return false if the pointer is just hovering over an egui area.

pub fn wants_mouse_input(&self) -> bool[src]

👎 Deprecated:

Renamed wants_pointer_input

pub fn is_using_mouse(&self) -> bool[src]

👎 Deprecated:

Renamed is_using_pointer

pub fn wants_keyboard_input(&self) -> bool[src]

If true, egui is currently listening on text input (e.g. typing text in a TextEdit).

pub fn translate_layer(&self, layer_id: LayerId, delta: Vec2)[src]

Move all the graphics at the given layer. Can be used to implement drag-and-drop (see relevant demo).

pub fn layer_id_at(&self, pos: Pos2) -> Option<LayerId>[src]

pub fn animate_bool(&self, id: Id, value: bool) -> f32[src]

Returns a value in the range [0, 1], to indicate “how on” this thing is.

The first time called it will return if value { 1.0 } else { 0.0 } Calling this with value = true will always yield a number larger than zero, quickly going towards one. Calling this with value = false will always yield a number less than one, quickly going towards zero.

The function will call Self::request_repaint() when appropriate.

pub fn clear_animations(&self)[src]

Clear memory of any animations.

pub fn settings_ui(&self, ui: &mut Ui)[src]

pub fn inspection_ui(&self, ui: &mut Ui)[src]

pub fn memory_ui(&self, ui: &mut Ui)[src]

pub fn style_ui(&self, ui: &mut Ui)[src]

Trait Implementations

impl AsRef<Context> for CtxRef[src]

fn as_ref(&self) -> &Context[src]

Performs the conversion.

impl Borrow<Context> for CtxRef[src]

fn borrow(&self) -> &Context[src]

Immutably borrows from an owned value. Read more

impl Clone for CtxRef[src]

fn clone(&self) -> CtxRef[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Default for CtxRef[src]

fn default() -> Self[src]

Returns the “default value” for a type. Read more

impl Deref for CtxRef[src]

type Target = Context

The resulting type after dereferencing.

fn deref(&self) -> &Context[src]

Dereferences the value.

impl PartialEq<CtxRef> for CtxRef[src]

fn eq(&self, other: &CtxRef) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

Auto Trait Implementations

impl !RefUnwindSafe for CtxRef

impl Send for CtxRef

impl Sync for CtxRef

impl Unpin for CtxRef

impl !UnwindSafe for CtxRef

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.