Integrate account switcher to side panel
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
committed by
William Casarin
parent
c0b1a01b5d
commit
22264e70f5
@@ -6,7 +6,10 @@ use egui::{
|
|||||||
|
|
||||||
use crate::account_manager::AccountManager;
|
use crate::account_manager::AccountManager;
|
||||||
|
|
||||||
use super::profile::{preview::SimpleProfilePreview, SimpleProfilePreviewController};
|
use super::{
|
||||||
|
profile::{preview::SimpleProfilePreview, SimpleProfilePreviewController},
|
||||||
|
state_in_memory::{STATE_ACCOUNT_MANAGEMENT, STATE_ACCOUNT_SWITCHER, STATE_SIDE_PANEL},
|
||||||
|
};
|
||||||
|
|
||||||
pub struct AccountSelectionWidget<'a> {
|
pub struct AccountSelectionWidget<'a> {
|
||||||
account_manager: &'a mut AccountManager,
|
account_manager: &'a mut AccountManager,
|
||||||
@@ -157,7 +160,12 @@ fn top_section_widget() -> impl egui::Widget {
|
|||||||
Layout::right_to_left(egui::Align::Center),
|
Layout::right_to_left(egui::Align::Center),
|
||||||
|ui| {
|
|ui| {
|
||||||
if ui.add(manage_accounts_button()).clicked() {
|
if ui.add(manage_accounts_button()).clicked() {
|
||||||
// TODO: route to AccountLoginView
|
STATE_ACCOUNT_SWITCHER.set_state(ui.ctx(), false);
|
||||||
|
STATE_SIDE_PANEL.set_state(
|
||||||
|
ui.ctx(),
|
||||||
|
Some(ui::global_popup::GlobalPopupType::AccountManagement),
|
||||||
|
);
|
||||||
|
STATE_ACCOUNT_MANAGEMENT.set_state(ui.ctx(), true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,21 +3,25 @@ use egui::{Align2, CentralPanel, RichText, Vec2, Window};
|
|||||||
use crate::Damus;
|
use crate::Damus;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
state_in_memory::{STATE_GLOBAL_POPUP, STATE_SIDE_PANEL},
|
profile::SimpleProfilePreviewController,
|
||||||
AccountManagementView, View,
|
state_in_memory::{STATE_ACCOUNT_MANAGEMENT, STATE_ACCOUNT_SWITCHER, STATE_SIDE_PANEL},
|
||||||
|
AccountManagementView, AccountSelectionWidget, View,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum GlobalPopupType {
|
pub enum GlobalPopupType {
|
||||||
AccountManagement,
|
AccountManagement,
|
||||||
|
AccountSwitcher,
|
||||||
}
|
}
|
||||||
|
|
||||||
static ACCOUNT_MANAGEMENT_TITLE: &str = "Manage accounts";
|
static ACCOUNT_MANAGEMENT_TITLE: &str = "Manage accounts";
|
||||||
|
static ACCOUNT_SWITCHER_TITLE: &str = "Account switcher";
|
||||||
|
|
||||||
impl GlobalPopupType {
|
impl GlobalPopupType {
|
||||||
pub fn title(&self) -> &'static str {
|
pub fn title(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::AccountManagement => ACCOUNT_MANAGEMENT_TITLE,
|
Self::AccountManagement => ACCOUNT_MANAGEMENT_TITLE,
|
||||||
|
Self::AccountSwitcher => ACCOUNT_SWITCHER_TITLE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,6 +50,16 @@ fn overlay_window<'a>(
|
|||||||
.default_size(window_size)
|
.default_size(window_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn account_switcher_window(open: &'_ mut bool) -> Window<'_> {
|
||||||
|
egui::Window::new("account switcher")
|
||||||
|
.title_bar(false)
|
||||||
|
.collapsible(false)
|
||||||
|
.anchor(Align2::LEFT_BOTTOM, Vec2::new(0.0, -52.0))
|
||||||
|
.fixed_size(Vec2::new(360.0, 406.0))
|
||||||
|
.open(open)
|
||||||
|
.movable(false)
|
||||||
|
}
|
||||||
|
|
||||||
static MARGIN: Vec2 = Vec2 { x: 100.0, y: 100.0 };
|
static MARGIN: Vec2 = Vec2 { x: 100.0, y: 100.0 };
|
||||||
|
|
||||||
pub struct DesktopGlobalPopup<'a> {
|
pub struct DesktopGlobalPopup<'a> {
|
||||||
@@ -64,29 +78,49 @@ impl<'a> DesktopGlobalPopup<'a> {
|
|||||||
}
|
}
|
||||||
pub fn global_popup(app: &mut Damus, ctx: &egui::Context) {
|
pub fn global_popup(app: &mut Damus, ctx: &egui::Context) {
|
||||||
CentralPanel::default().show(ctx, |ui| {
|
CentralPanel::default().show(ctx, |ui| {
|
||||||
let available_size = ui.available_size();
|
|
||||||
let window_size = available_size - MARGIN;
|
|
||||||
|
|
||||||
if let Some(popup) = STATE_SIDE_PANEL.get_state(ctx) {
|
if let Some(popup) = STATE_SIDE_PANEL.get_state(ctx) {
|
||||||
let mut show_global_popup = STATE_GLOBAL_POPUP.get_state(ctx);
|
match popup {
|
||||||
if show_global_popup {
|
GlobalPopupType::AccountManagement => {
|
||||||
overlay_window(&mut show_global_popup, window_size, popup.title()).show(
|
Self::account_management(app, ctx, ui, popup.title());
|
||||||
ctx,
|
}
|
||||||
|ui| {
|
GlobalPopupType::AccountSwitcher => {
|
||||||
match popup {
|
let mut show_account_switcher = STATE_ACCOUNT_SWITCHER.get_state(ctx);
|
||||||
GlobalPopupType::AccountManagement => {
|
if show_account_switcher {
|
||||||
AccountManagementView::from_app(app).ui(ui)
|
STATE_ACCOUNT_MANAGEMENT.set_state(ctx, false);
|
||||||
}
|
account_switcher_window(&mut show_account_switcher).show(ctx, |ui| {
|
||||||
};
|
AccountSelectionWidget::new(
|
||||||
},
|
&mut app.account_manager,
|
||||||
);
|
SimpleProfilePreviewController::new(
|
||||||
|
&app.ndb,
|
||||||
// user could have closed the window, set the new state in egui memory
|
&mut app.img_cache,
|
||||||
STATE_GLOBAL_POPUP.set_state(ctx, show_global_popup);
|
),
|
||||||
|
)
|
||||||
|
.ui(ui);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn account_management(
|
||||||
|
app: &mut Damus,
|
||||||
|
ctx: &egui::Context,
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
title: &'static str,
|
||||||
|
) {
|
||||||
|
let available_size = ui.available_size();
|
||||||
|
let window_size = available_size - MARGIN;
|
||||||
|
let mut show_account_management = STATE_ACCOUNT_MANAGEMENT.get_state(ctx);
|
||||||
|
if show_account_management {
|
||||||
|
overlay_window(&mut show_account_management, window_size, title).show(ctx, |ui| {
|
||||||
|
AccountManagementView::from_app(app).ui(ui);
|
||||||
|
});
|
||||||
|
// user could have closed the window, set the new state in egui memory
|
||||||
|
STATE_ACCOUNT_MANAGEMENT.set_state(ctx, show_account_management);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod preview {
|
mod preview {
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use enostr::Pubkey;
|
use enostr::Pubkey;
|
||||||
use nostrdb::{Ndb, Transaction};
|
use nostrdb::{Ndb, Transaction};
|
||||||
|
|
||||||
use crate::{account_manager::AccountManager, imgcache::ImageCache, DisplayName};
|
use crate::{
|
||||||
|
account_manager::AccountManager, imgcache::ImageCache,
|
||||||
|
ui::state_in_memory::STATE_ACCOUNT_SWITCHER, DisplayName,
|
||||||
|
};
|
||||||
|
|
||||||
use super::preview::{get_display_name, SimpleProfilePreview};
|
use super::preview::{get_display_name, SimpleProfilePreview};
|
||||||
|
|
||||||
@@ -105,6 +108,7 @@ impl<'a> SimpleProfilePreviewController<'a> {
|
|||||||
|
|
||||||
if add_preview_ui(ui, preview, width, is_selected, i) {
|
if add_preview_ui(ui, preview, width, is_selected, i) {
|
||||||
account_manager.select_account(i);
|
account_manager.select_account(i);
|
||||||
|
STATE_ACCOUNT_SWITCHER.set_state(ui.ctx(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use egui::{Button, Layout, SidePanel, Vec2};
|
|||||||
use crate::ui::global_popup::GlobalPopupType;
|
use crate::ui::global_popup::GlobalPopupType;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
state_in_memory::{STATE_GLOBAL_POPUP, STATE_SIDE_PANEL},
|
state_in_memory::{STATE_ACCOUNT_SWITCHER, STATE_SIDE_PANEL},
|
||||||
View,
|
View,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -32,8 +32,9 @@ impl DesktopSidePanel {
|
|||||||
.add_sized(Vec2::new(32.0, 32.0), Button::new("A"))
|
.add_sized(Vec2::new(32.0, 32.0), Button::new("A"))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
STATE_SIDE_PANEL.set_state(ui.ctx(), Some(GlobalPopupType::AccountManagement));
|
STATE_SIDE_PANEL.set_state(ui.ctx(), Some(GlobalPopupType::AccountSwitcher));
|
||||||
STATE_GLOBAL_POPUP.set_state(ui.ctx(), true);
|
let previous_val = STATE_ACCOUNT_SWITCHER.get_state(ui.ctx());
|
||||||
|
STATE_ACCOUNT_SWITCHER.set_state(ui.ctx(), !previous_val);
|
||||||
}
|
}
|
||||||
ui.add_space(spacing_amt);
|
ui.add_space(spacing_amt);
|
||||||
ui.add(settings_button(dark_mode));
|
ui.add(settings_button(dark_mode));
|
||||||
|
|||||||
@@ -33,11 +33,11 @@ pub static STATE_SIDE_PANEL: StateInMemory<Option<GlobalPopupType>> =
|
|||||||
default_state: None,
|
default_state: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub static STATE_GLOBAL_POPUP: StateInMemory<bool> = StateInMemory::<bool> {
|
pub static STATE_ACCOUNT_SWITCHER: StateInMemory<bool> = StateInMemory::<bool> {
|
||||||
id: GLOBAL_POPUP_VIEW_STATE_ID,
|
id: ACCOUNT_SWITCHER_VIEW_STATE_ID,
|
||||||
default_state: false,
|
default_state: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
static ACCOUNT_MANAGEMENT_VIEW_STATE_ID: &str = "account management view state";
|
static ACCOUNT_MANAGEMENT_VIEW_STATE_ID: &str = "account management view state";
|
||||||
static SIDE_PANEL_VIEW_STATE_ID: &str = "side panel view state";
|
static SIDE_PANEL_VIEW_STATE_ID: &str = "side panel view state";
|
||||||
static GLOBAL_POPUP_VIEW_STATE_ID: &str = "global popup view state";
|
static ACCOUNT_SWITCHER_VIEW_STATE_ID: &str = "account switcher view state";
|
||||||
|
|||||||
Reference in New Issue
Block a user