State

Struct State 

Source
pub struct State {
Show 14 fields pub(crate) egui_ctx: Context, pub(crate) viewport_id: ViewportId, pub(crate) start_time: Instant, pub(crate) egui_input: RawInput, pub(crate) pointer_pos_in_points: Option<Pos2>, pub(crate) any_pointer_button_down: bool, pub(crate) current_cursor_icon: Option<CursorIcon>, pub(crate) clipboard: Clipboard, pub(crate) simulate_touch_screen: bool, pub(crate) pointer_touch_id: Option<u64>, pub(crate) has_sent_ime_enabled: bool, pub accesskit: Option<Adapter>, pub(crate) allow_ime: bool, pub(crate) ime_rect_px: Option<Rect>,
}
Expand description

Handles the integration between egui and a winit Window.

Instantiate one of these per viewport/window.

Fields§

§egui_ctx: Context

Shared clone.

§viewport_id: ViewportId§start_time: Instant§egui_input: RawInput§pointer_pos_in_points: Option<Pos2>§any_pointer_button_down: bool§current_cursor_icon: Option<CursorIcon>§clipboard: Clipboard§simulate_touch_screen: bool

If true, mouse inputs will be treated as touches. Useful for debugging touch support in egui.

Creates duplicate touches, if real touch inputs are coming.

§pointer_touch_id: Option<u64>

Is Some(…) when a touch is being translated to a pointer.

Only one touch will be interpreted as pointer at any time.

§has_sent_ime_enabled: bool

track ime state

§accesskit: Option<Adapter>§allow_ime: bool§ime_rect_px: Option<Rect>

Implementations§

Source§

impl State

Source

pub fn new( egui_ctx: Context, viewport_id: ViewportId, display_target: &dyn HasDisplayHandle, native_pixels_per_point: Option<f32>, theme: Option<Theme>, max_texture_side: Option<usize>, ) -> Self

Construct a new instance

Source

pub fn init_accesskit<T: From<Event> + Send>( &mut self, event_loop: &ActiveEventLoop, window: &Window, event_loop_proxy: EventLoopProxy<T>, )

Source

pub fn set_max_texture_side(&mut self, max_texture_side: usize)

Call this once a graphics context has been created to update the maximum texture dimensions that egui will use.

Source

pub fn clipboard_text(&mut self) -> Option<String>

Fetches text from the clipboard and returns it.

Source

pub fn set_clipboard_text(&mut self, text: String)

Places the text onto the clipboard.

Source

pub fn allow_ime(&self) -> bool

Returns false or the last value that Window::set_ime_allowed() was called with, used for debouncing.

Source

pub fn set_allow_ime(&mut self, allow: bool)

Set the last value that Window::set_ime_allowed() was called with.

Source

pub fn egui_ctx(&self) -> &Context

Source

pub fn egui_input(&self) -> &RawInput

The current input state. This is changed by Self::on_window_event and cleared by Self::take_egui_input.

Source

pub fn egui_input_mut(&mut self) -> &mut RawInput

The current input state. This is changed by Self::on_window_event and cleared by Self::take_egui_input.

Source

pub fn take_egui_input(&mut self, window: &Window) -> RawInput

Prepare for a new frame by extracting the accumulated input,

as well as setting the time and screen rectangle.

You need to set egui::RawInput::viewports yourself though. Use update_viewport_info to update the info for each viewport.

Source

pub fn on_window_event( &mut self, window: &Window, event: &WindowEvent, ) -> EventResponse

Call this when there is a new event.

The result can be found in Self::egui_input and be extracted with Self::take_egui_input.

Source

pub(crate) fn try_on_ime_processed_keyboard_input( &mut self, _event: &KeyEvent, _egui_wants_keyboard_input: bool, ) -> Option<EventResponse>

Source

pub(crate) fn on_ime(&mut self, ime: &Ime)

§NOTE

on Mac even Cmd-C is pressed during ime, a c is pushed to Preedit. So no need to check is_mac_cmd.

§How events are emitted by winit across different setups in various situations

This is done by uncommenting the code block at the top of this method and checking console outputs.

winit version: 0.30.12.

§Setups
  • a-macos15-apple_shuangpin: macOS 15.7.3 aarch64, IME: builtin Chinese Shuangpin - Simplified. (Demo app shows: renderer: wgpu, backend: Metal.)
  • b-debian13_gnome48_wayland-fcitx5_shuangpin: Debian 13 aarch64, Gnome 48, Wayland, IME: Fcitx5 with fcitx5-chinese-addons’s Shuangpin. (Demo app shows: renderer: wgpu, backend: Gl.)
  • c-windows11-ms_pinyin: Windows11 23H2 x86_64, IME: builtin Microsoft Pinyin. (Demo app shows: renderer: wgpu, backend: Vulkan & Dx12, others: Dx12 & Gl.)
§Situation: pressed space to select the first candidate “测试”
SetupEvents in Order
a-macos15-apple_shuangpinPreedit("", None) -> Commit("测试")
b-debian13_gnome48_wayland-fcitx5_shuangpinPreedit("", None) -> Commit("测试") -> Preedit("", Some(0, 0)) -> Preedit("", None) (duplicate until TextEdit blurred)
c-windows11-ms_pinyinPreedit("测试", Some(…)) -> Preedit("", None) -> Commit("测试") -> Disabled
§Situation: pressed backspace to delete the last character in the composition

| Setup | Events in Order | | a-macos15-apple_shuangpin | Preedit("", None) | | b-debian13_gnome48_wayland-fcitx5_shuangpin | Preedit("", Some(0, 0)) -> Preedit("", None) (duplicate until TextEdit blurred) | | c-windows11-ms_pinyin | Preedit("", Some(0, 0)) -> Preedit("", None) -> Commit("") -> Disabled |

§Situation: clicked somewhere else while there is an active composition with the pre-edit text “ce”
SetupEvents in Order
a-macos15-apple_shuangpinnothing emitted
b-debian13_gnome48_wayland-fcitx5_shuangpinPreedit("", Some(0, 0)) (duplicate) -> Preedit("", None) (duplicate until TextEdit blurred)
c-windows11-ms_pinyinnothing emitted
Source

pub fn ime_event_enable(&mut self)

Source

pub fn ime_event_disable(&mut self)

Source

pub fn on_mouse_motion(&mut self, delta: (f64, f64)) -> bool

Returns true if the event was sent to egui.

Source

pub fn is_pointer_in_window(&self) -> bool

Returns true when the pointer is currently inside the window.

Source

pub fn is_any_pointer_button_down(&self) -> bool

Returns true if any pointer button is currently held down.

Source

pub fn on_accesskit_action_request(&mut self, request: ActionRequest)

Call this when there is a new accesskit::ActionRequest.

The result can be found in Self::egui_input and be extracted with Self::take_egui_input.

Source

pub(crate) fn on_mouse_button_input( &mut self, state: ElementState, button: MouseButton, )

Source

pub(crate) fn on_cursor_moved( &mut self, window: &Window, pos_in_pixels: PhysicalPosition<f64>, )

Source

pub(crate) fn on_touch(&mut self, window: &Window, touch: &Touch)

Source

pub(crate) fn on_mouse_wheel( &mut self, window: &Window, delta: MouseScrollDelta, phase: TouchPhase, )

Source

pub(crate) fn on_keyboard_input(&mut self, event: &KeyEvent)

Source

pub fn handle_platform_output( &mut self, window: &Window, platform_output: PlatformOutput, )

Call with the output given by egui.

This will, if needed:

  • update the cursor
  • copy text to the clipboard
  • open any clicked urls
  • update the IME
Source

pub(crate) fn set_cursor_icon( &mut self, window: &Window, cursor_icon: CursorIcon, )

Auto Trait Implementations§

§

impl Freeze for State

§

impl !RefUnwindSafe for State

§

impl Send for State

§

impl !Sync for State

§

impl Unpin for State

§

impl !UnwindSafe for State

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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