Skip to content

Commit

Permalink
remove context from DesktopSidePanel
Browse files Browse the repository at this point in the history
we can just get this from the egui::Ui when rendering

Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 committed May 18, 2024
1 parent 6a1d256 commit 36d2dd0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/ui/global_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod preview {

impl View for GlobalPopupPreview {
fn ui(&mut self, ui: &mut egui::Ui) {
let mut panel = DesktopSidePanel::new(ui.ctx());
let mut panel = DesktopSidePanel::new();
DesktopSidePanel::panel().show(ui.ctx(), |ui| panel.ui(ui));
DesktopGlobalPopup::new(&mut self.app).ui(ui);
}
Expand Down
25 changes: 12 additions & 13 deletions src/ui/side_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@ use super::{
View,
};

pub struct DesktopSidePanel<'a> {
ctx: &'a egui::Context,
}
#[derive(Default)]
pub struct DesktopSidePanel {}

static ID: &str = "left panel";

impl<'a> View for DesktopSidePanel<'a> {
impl View for DesktopSidePanel {
fn ui(&mut self, ui: &mut egui::Ui) {
DesktopSidePanel::inner(self.ctx, ui);
DesktopSidePanel::inner(ui);
}
}

impl<'a> DesktopSidePanel<'a> {
pub fn new(ctx: &'a egui::Context) -> Self {
DesktopSidePanel { ctx }
impl DesktopSidePanel {
pub fn new() -> Self {
DesktopSidePanel::default()
}

pub fn inner(ctx: &egui::Context, ui: &mut egui::Ui) {
pub fn inner(ui: &mut egui::Ui) {
let dark_mode = ui.ctx().style().visuals.dark_mode;
let spacing_amt = 16.0;
ui.with_layout(Layout::bottom_up(egui::Align::Center), |ui| {
Expand All @@ -33,8 +32,8 @@ impl<'a> DesktopSidePanel<'a> {
.add_sized(Vec2::new(32.0, 32.0), Button::new("A"))
.clicked()
{
PERSISTED_SIDE_PANEL.set_state(ctx, Some(GlobalPopupType::AccountManagement));
PERSISTED_GLOBAL_POPUP.set_state(ctx, true);
PERSISTED_SIDE_PANEL.set_state(ui.ctx(), Some(GlobalPopupType::AccountManagement));
PERSISTED_GLOBAL_POPUP.set_state(ui.ctx(), true);
}
ui.add_space(spacing_amt);
ui.add(settings_button(dark_mode));
Expand Down Expand Up @@ -78,12 +77,12 @@ mod preview {

impl View for DesktopSidePanelPreview {
fn ui(&mut self, ui: &mut egui::Ui) {
let mut panel = DesktopSidePanel::new(ui.ctx());
let mut panel = DesktopSidePanel::new();
DesktopSidePanel::panel().show(ui.ctx(), |ui| panel.ui(ui));
}
}

impl Preview for DesktopSidePanel<'_> {
impl Preview for DesktopSidePanel {
type Prev = DesktopSidePanelPreview;

fn preview() -> Self::Prev {
Expand Down

0 comments on commit 36d2dd0

Please sign in to comment.