diff --git a/src/ui/account_management.rs b/src/ui/account_management.rs index 96a06cf..98dba2e 100644 --- a/src/ui/account_management.rs +++ b/src/ui/account_management.rs @@ -7,8 +7,8 @@ use crate::{ use egui::{Align, Button, Frame, Id, Layout, Margin, RichText, ScrollArea, Sense, Vec2}; use super::global_popup::GlobalPopupType; -use super::persist_state::PERSISTED_ACCOUNT_MANAGEMENT; use super::profile::preview::SimpleProfilePreview; +use super::state_in_memory::STATE_ACCOUNT_MANAGEMENT; pub struct AccountManagementView<'a> { account_manager: AccountManager<'a>, @@ -49,7 +49,7 @@ impl<'a> AccountManagementView<'a> { let maybe_remove = self.simple_preview_controller.set_profile_previews( &self.account_manager, ui, - PERSISTED_ACCOUNT_MANAGEMENT.get_state(ui.ctx()), + STATE_ACCOUNT_MANAGEMENT.get_state(ui.ctx()), desktop_account_card_ui(), ); @@ -66,7 +66,7 @@ impl<'a> AccountManagementView<'a> { let maybe_remove = self.simple_preview_controller.set_profile_previews( &self.account_manager, ui, - PERSISTED_ACCOUNT_MANAGEMENT.get_state(ui.ctx()), + STATE_ACCOUNT_MANAGEMENT.get_state(ui.ctx()), mobile_account_card_ui(), // closure for creating an account 'card' ); @@ -104,12 +104,12 @@ impl<'a> AccountManagementView<'a> { Vec2::new(ui.available_size_before_wrap().x, 32.0), Layout::left_to_right(egui::Align::Center), |ui| { - if PERSISTED_ACCOUNT_MANAGEMENT.get_state(ui.ctx()) { + if STATE_ACCOUNT_MANAGEMENT.get_state(ui.ctx()) { if ui.add(done_account_button()).clicked() { - PERSISTED_ACCOUNT_MANAGEMENT.set_state(ui.ctx(), false); + STATE_ACCOUNT_MANAGEMENT.set_state(ui.ctx(), false); } } else if ui.add(edit_account_button()).clicked() { - PERSISTED_ACCOUNT_MANAGEMENT.set_state(ui.ctx(), true); + STATE_ACCOUNT_MANAGEMENT.set_state(ui.ctx(), true); } }, ); diff --git a/src/ui/global_popup.rs b/src/ui/global_popup.rs index 0580c6c..2901796 100644 --- a/src/ui/global_popup.rs +++ b/src/ui/global_popup.rs @@ -3,7 +3,7 @@ use egui::{Align2, CentralPanel, RichText, Vec2, Window}; use crate::Damus; use super::{ - persist_state::{PERSISTED_GLOBAL_POPUP, PERSISTED_SIDE_PANEL}, + state_in_memory::{STATE_GLOBAL_POPUP, STATE_SIDE_PANEL}, AccountManagementView, View, }; @@ -67,8 +67,8 @@ impl<'a> DesktopGlobalPopup<'a> { let available_size = ui.available_size(); let window_size = available_size - MARGIN; - if let Some(popup) = PERSISTED_SIDE_PANEL.get_state(ctx) { - let mut show_global_popup = PERSISTED_GLOBAL_POPUP.get_state(ctx); + if let Some(popup) = STATE_SIDE_PANEL.get_state(ctx) { + let mut show_global_popup = STATE_GLOBAL_POPUP.get_state(ctx); if show_global_popup { overlay_window(&mut show_global_popup, window_size, popup.title()).show( ctx, @@ -82,7 +82,7 @@ impl<'a> DesktopGlobalPopup<'a> { ); // user could have closed the window, set the new state in egui memory - PERSISTED_GLOBAL_POPUP.set_state(ctx, show_global_popup); + STATE_GLOBAL_POPUP.set_state(ctx, show_global_popup); } } }); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index ce4caf5..5f05bd0 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -4,11 +4,11 @@ pub mod anim; pub mod global_popup; pub mod mention; pub mod note; -pub mod persist_state; pub mod preview; pub mod profile; pub mod relay; pub mod side_panel; +pub mod state_in_memory; pub mod username; pub use account_management::{AccountManagementView, AccountSelectionWidget}; diff --git a/src/ui/side_panel.rs b/src/ui/side_panel.rs index a46058d..2c9bb71 100644 --- a/src/ui/side_panel.rs +++ b/src/ui/side_panel.rs @@ -3,7 +3,7 @@ use egui::{Button, Layout, SidePanel, Vec2}; use crate::ui::global_popup::GlobalPopupType; use super::{ - persist_state::{PERSISTED_GLOBAL_POPUP, PERSISTED_SIDE_PANEL}, + state_in_memory::{STATE_GLOBAL_POPUP, STATE_SIDE_PANEL}, View, }; @@ -32,8 +32,8 @@ impl DesktopSidePanel { .add_sized(Vec2::new(32.0, 32.0), Button::new("A")) .clicked() { - PERSISTED_SIDE_PANEL.set_state(ui.ctx(), Some(GlobalPopupType::AccountManagement)); - PERSISTED_GLOBAL_POPUP.set_state(ui.ctx(), true); + STATE_SIDE_PANEL.set_state(ui.ctx(), Some(GlobalPopupType::AccountManagement)); + STATE_GLOBAL_POPUP.set_state(ui.ctx(), true); } ui.add_space(spacing_amt); ui.add(settings_button(dark_mode)); diff --git a/src/ui/persist_state.rs b/src/ui/state_in_memory.rs similarity index 54% rename from src/ui/persist_state.rs rename to src/ui/state_in_memory.rs index 8a63ac3..7823cb8 100644 --- a/src/ui/persist_state.rs +++ b/src/ui/state_in_memory.rs @@ -1,39 +1,39 @@ -use egui::util::id_type_map::SerializableAny; +use std::any::Any; use super::global_popup::GlobalPopupType; -/// PersistState is a helper struct for interacting with egui memory persisted data +/// StateInMemory is a helper struct for interacting with egui memory persisted data #[derive(Clone)] -pub struct PersistState { +pub struct StateInMemory { id: &'static str, default_state: T, } -impl PersistState { +impl StateInMemory { pub fn get_state(&self, ctx: &egui::Context) -> T { ctx.data_mut(|d| { - d.get_persisted(egui::Id::new(self.id)) + d.get_temp(egui::Id::new(self.id)) .unwrap_or(self.default_state.clone()) }) } pub fn set_state(&self, ctx: &egui::Context, new_val: T) { - ctx.data_mut(|d| d.insert_persisted(egui::Id::new(self.id), new_val)); + ctx.data_mut(|d| d.insert_temp(egui::Id::new(self.id), new_val)); } } -pub static PERSISTED_ACCOUNT_MANAGEMENT: PersistState = PersistState:: { +pub static STATE_ACCOUNT_MANAGEMENT: StateInMemory = StateInMemory:: { id: ACCOUNT_MANAGEMENT_VIEW_STATE_ID, default_state: false, }; -pub static PERSISTED_SIDE_PANEL: PersistState> = - PersistState::> { +pub static STATE_SIDE_PANEL: StateInMemory> = + StateInMemory::> { id: SIDE_PANEL_VIEW_STATE_ID, default_state: None, }; -pub static PERSISTED_GLOBAL_POPUP: PersistState = PersistState:: { +pub static STATE_GLOBAL_POPUP: StateInMemory = StateInMemory:: { id: GLOBAL_POPUP_VIEW_STATE_ID, default_state: false, };