Struct dotrix_egui::CtxRef[][src]

pub struct CtxRef(_);
Expand description

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

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, TopBottomPanel, CentralPanel, Window or Area.

Get a full-screen painter for a new or existing layer

Paint on top of everything else

Methods from Deref<Target = Context>

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.

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

What egui outputs each frame.

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.

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

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.

Tell egui which fonts to use.

The default egui fonts only support latin and cyrillic alphabets, but you can call this to install additional fonts that support e.g. korean characters.

The new fonts will become active at the start of the next frame.

The Style used by all subsequent windows, panels etc.

The Style used by all new windows, panels etc.

You can also use Ui::style_mut to change the style of a single Ui.

Example:

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

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

The number of physical pixels for each logical point.

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.

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.

Tessellate the given shapes into triangle meshes.

How much space is used by panels and windows.

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

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

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.

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.

👎 Deprecated:

Renamed wants_pointer_input

👎 Deprecated:

Renamed is_using_pointer

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

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

Top-most layer at the given position.

Wether or not to debug widget layout on hover.

Turn on/off wether or not to debug widget layout on hover.

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.

Clear memory of any animations.

Trait Implementations

Performs the conversion.

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

The resulting type after dereferencing.

Dereferences the value.

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

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

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

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

Performs the conversion.

Constructs wrapped service

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

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

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

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.