1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Add ui.data(), ctx.data(), ctx.options() and ctx.tessellation_options() (#1175)

Helpful access deeper into Memory
This commit is contained in:
Emil Ernerfeldt
2022-01-29 17:53:41 +01:00
committed by GitHub
parent 3333d63b91
commit b618636425
19 changed files with 91 additions and 72 deletions

View File

@@ -19,7 +19,7 @@ pub fn password_ui(ui: &mut egui::Ui, password: &mut String) -> egui::Response {
// Get state for this widget.
// You should get state by value, not by reference to avoid borrowing of `Memory`.
let mut show_plaintext = ui.memory().data.get_temp::<bool>(state_id).unwrap_or(false);
let mut show_plaintext = ui.data().get_temp::<bool>(state_id).unwrap_or(false);
// Process ui, change a local copy of the state
// We want TextEdit to fill entire space, and have button after that, so in that case we can
@@ -42,7 +42,7 @@ pub fn password_ui(ui: &mut egui::Ui, password: &mut String) -> egui::Response {
});
// Store the (possibly changed) state:
ui.memory().data.insert_temp(state_id, show_plaintext);
ui.data().insert_temp(state_id, show_plaintext);
// All done! Return the interaction response so the user can check what happened
// (hovered, clicked, …) and maybe show a tooltip:

View File

@@ -127,9 +127,9 @@ impl BackendPanel {
ui.separator();
{
let mut screen_reader = ui.ctx().memory().options.screen_reader;
let mut screen_reader = ui.ctx().options().screen_reader;
ui.checkbox(&mut screen_reader, "🔈 Screen reader").on_hover_text("Experimental feature: checking this will turn on the screen reader on supported platforms");
ui.ctx().memory().options.screen_reader = screen_reader;
ui.ctx().options().screen_reader = screen_reader;
}
if !frame.is_web() {

View File

@@ -146,13 +146,11 @@ impl CodeTheme {
pub fn from_memory(ctx: &egui::Context) -> Self {
if ctx.style().visuals.dark_mode {
ctx.memory()
.data
ctx.data()
.get_persisted(egui::Id::new("dark"))
.unwrap_or_else(CodeTheme::dark)
} else {
ctx.memory()
.data
ctx.data()
.get_persisted(egui::Id::new("light"))
.unwrap_or_else(CodeTheme::light)
}
@@ -160,13 +158,9 @@ impl CodeTheme {
pub fn store_in_memory(self, ctx: &egui::Context) {
if self.dark_mode {
ctx.memory()
.data
.insert_persisted(egui::Id::new("dark"), self);
ctx.data().insert_persisted(egui::Id::new("dark"), self);
} else {
ctx.memory()
.data
.insert_persisted(egui::Id::new("light"), self);
ctx.data().insert_persisted(egui::Id::new("light"), self);
}
}
}
@@ -237,8 +231,7 @@ impl CodeTheme {
ui.horizontal_top(|ui| {
let selected_id = egui::Id::null();
let mut selected_tt: TokenType = *ui
.memory()
.data
.data()
.get_persisted_mut_or(selected_id, TokenType::Comment);
ui.vertical(|ui| {
@@ -281,7 +274,7 @@ impl CodeTheme {
ui.add_space(16.0);
ui.memory().data.insert_persisted(selected_id, selected_tt);
ui.data().insert_persisted(selected_id, selected_tt);
egui::Frame::group(ui.style())
.margin(egui::Vec2::splat(2.0))