From 38991de6b11642d7de20eee89c0369b266ce1e60 Mon Sep 17 00:00:00 2001 From: obellish Date: Mon, 19 Feb 2024 07:12:53 -0500 Subject: [PATCH] add Deref for Ui --- crates/egui/src/painter.rs | 2 +- crates/egui/src/ui.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/painter.rs b/crates/egui/src/painter.rs index 8689ec815..df1379696 100644 --- a/crates/egui/src/painter.rs +++ b/crates/egui/src/painter.rs @@ -16,7 +16,7 @@ use epaint::{ #[derive(Clone)] pub struct Painter { /// Source of fonts and destination of shapes - ctx: Context, + pub(crate) ctx: Context, /// Where we paint layer_id: LayerId, diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index 182c5782f..839c4c850 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -1,7 +1,7 @@ #![warn(missing_docs)] // Let's keep `Ui` well-documented. #![allow(clippy::use_self)] -use std::{any::Any, hash::Hash, sync::Arc}; +use std::{any::Any, hash::Hash, ops::Deref, sync::Arc}; use epaint::mutex::RwLock; @@ -2320,6 +2320,14 @@ impl Ui { } } +impl Deref for Ui { + type Target = Context; + + fn deref(&self) -> &Self::Target { + self.ctx() + } +} + #[cfg(debug_assertions)] impl Drop for Ui { fn drop(&mut self) {