mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 22:30:03 -04:00
Add ui.data(), ctx.data(), ctx.options() and ctx.tessellation_options() (#1175)
Helpful access deeper into Memory
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user