narrowize account management view
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
committed by
William Casarin
parent
52604e65c6
commit
206112849d
@@ -14,36 +14,19 @@ use super::profile::ProfilePreviewOp;
|
|||||||
pub struct AccountManagementView {}
|
pub struct AccountManagementView {}
|
||||||
|
|
||||||
impl AccountManagementView {
|
impl AccountManagementView {
|
||||||
pub fn ui(app: &mut Damus, ui: &mut egui::Ui) -> Option<Response> {
|
pub fn ui(app: &mut Damus, ui: &mut egui::Ui) -> Response {
|
||||||
if ui::is_narrow(ui.ctx()) {
|
|
||||||
AccountManagementView::show_mobile(app, ui);
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(AccountManagementView::show(app, ui))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn show(app: &mut Damus, ui: &mut egui::Ui) -> Response {
|
|
||||||
Frame::none()
|
Frame::none()
|
||||||
.outer_margin(24.0)
|
.outer_margin(12.0)
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
Self::top_section_buttons_widget(ui);
|
Self::top_section_buttons_widget(ui);
|
||||||
|
|
||||||
ui.add_space(8.0);
|
ui.add_space(8.0);
|
||||||
scroll_area().show(ui, |ui| {
|
scroll_area().show(ui, |ui| Self::show_accounts(app, ui));
|
||||||
Self::show_accounts(app, ui);
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.response
|
.response
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_accounts(app: &mut Damus, ui: &mut egui::Ui) {
|
fn show_accounts(app: &mut Damus, ui: &mut egui::Ui) {
|
||||||
let maybe_remove =
|
|
||||||
profile_preview_controller::set_profile_previews(app, ui, account_card_ui());
|
|
||||||
|
|
||||||
Self::maybe_remove_accounts(&mut app.accounts, maybe_remove);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn show_accounts_mobile(app: &mut Damus, ui: &mut egui::Ui) {
|
|
||||||
ui.allocate_ui_with_layout(
|
ui.allocate_ui_with_layout(
|
||||||
Vec2::new(ui.available_size_before_wrap().x, 32.0),
|
Vec2::new(ui.available_size_before_wrap().x, 32.0),
|
||||||
Layout::top_down(egui::Align::Min),
|
Layout::top_down(egui::Align::Min),
|
||||||
@@ -56,25 +39,17 @@ impl AccountManagementView {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// remove all account indicies user requested
|
// remove all account indicies user requested
|
||||||
Self::maybe_remove_accounts(&mut app.accounts, maybe_remove);
|
if let Some(indicies_to_remove) = maybe_remove {
|
||||||
|
Self::remove_accounts(&mut app.account_manager, indicies_to_remove);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_remove_accounts(manager: &mut AccountManager, account_indices: Option<Vec<usize>>) {
|
fn remove_accounts(manager: &mut AccountManager, account_indices: Vec<usize>) {
|
||||||
if let Some(to_remove) = account_indices {
|
account_indices
|
||||||
to_remove
|
.iter()
|
||||||
.iter()
|
.for_each(|index| manager.remove_account(*index));
|
||||||
.for_each(|index| manager.remove_account(*index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn show_mobile(app: &mut Damus, ui: &mut egui::Ui) {
|
|
||||||
mobile_title(ui);
|
|
||||||
Self::top_section_buttons_widget(ui);
|
|
||||||
|
|
||||||
ui.add_space(8.0);
|
|
||||||
scroll_area().show(ui, |ui| Self::show_accounts_mobile(app, ui));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn top_section_buttons_widget(ui: &mut egui::Ui) -> egui::Response {
|
fn top_section_buttons_widget(ui: &mut egui::Ui) -> egui::Response {
|
||||||
@@ -88,19 +63,6 @@ impl AccountManagementView {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// UNCOMMENT FOR LOGOUTALL BUTTON
|
|
||||||
// ui.allocate_ui_with_layout(
|
|
||||||
// Vec2::new(ui.available_size_before_wrap().x, 32.0),
|
|
||||||
// Layout::right_to_left(egui::Align::Center),
|
|
||||||
// |ui| {
|
|
||||||
// if ui.add(logout_all_button()).clicked() {
|
|
||||||
// for index in (0..self.accounts.num_accounts()).rev() {
|
|
||||||
// self.accounts.remove_account(index);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
})
|
})
|
||||||
.response
|
.response
|
||||||
}
|
}
|
||||||
@@ -145,17 +107,6 @@ fn account_card_ui() -> fn(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mobile_title(ui: &mut egui::Ui) -> egui::Response {
|
|
||||||
ui.vertical_centered(|ui| {
|
|
||||||
ui.label(
|
|
||||||
RichText::new("Account Management")
|
|
||||||
.text_style(NotedeckTextStyle::Heading2.text_style())
|
|
||||||
.strong(),
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.response
|
|
||||||
}
|
|
||||||
|
|
||||||
fn scroll_area() -> ScrollArea {
|
fn scroll_area() -> ScrollArea {
|
||||||
egui::ScrollArea::vertical()
|
egui::ScrollArea::vertical()
|
||||||
.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysHidden)
|
.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysHidden)
|
||||||
@@ -205,12 +156,7 @@ fn selected_widget() -> impl egui::Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn logout_all_button() -> egui::Button<'static> {
|
|
||||||
// egui::Button::new("Logout all")
|
|
||||||
// }
|
|
||||||
|
|
||||||
// PREVIEWS
|
// PREVIEWS
|
||||||
|
|
||||||
mod preview {
|
mod preview {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -231,11 +177,7 @@ mod preview {
|
|||||||
impl View for AccountManagementPreview {
|
impl View for AccountManagementPreview {
|
||||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||||
ui.add_space(24.0);
|
ui.add_space(24.0);
|
||||||
if ui::is_narrow(ui.ctx()) {
|
AccountManagementView::ui(&mut self.app, ui);
|
||||||
AccountManagementView::show_mobile(&mut self.app, ui);
|
|
||||||
} else {
|
|
||||||
AccountManagementView::show(&mut self.app, ui);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user