mirror of
https://github.com/damus-io/notedeck.git
synced 2024-09-18 21:03:31 +00:00
side_panel: return more detailed side panel responses
We should be treating all ui widgets as pure functions that do not mutate anything. This will make testing easier, as well as avoiding shared mutable references. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
31b2b5c950
commit
92ce718e8b
10
src/app.rs
10
src/app.rs
@ -867,16 +867,16 @@ fn timelines_view(ui: &mut egui::Ui, sizes: Size, app: &mut Damus, timelines: us
|
|||||||
.clip(true)
|
.clip(true)
|
||||||
.horizontal(|mut strip| {
|
.horizontal(|mut strip| {
|
||||||
strip.cell(|ui| {
|
strip.cell(|ui| {
|
||||||
if DesktopSidePanel::new(
|
let side_panel = DesktopSidePanel::new(
|
||||||
app.account_manager
|
app.account_manager
|
||||||
.get_selected_account()
|
.get_selected_account()
|
||||||
.map(|a| a.pubkey.bytes()),
|
.map(|a| a.pubkey.bytes()),
|
||||||
SimpleProfilePreviewController::new(&app.ndb, &mut app.img_cache),
|
SimpleProfilePreviewController::new(&app.ndb, &mut app.img_cache),
|
||||||
)
|
)
|
||||||
.show(ui)
|
.show(ui);
|
||||||
.clicked()
|
|
||||||
{
|
if side_panel.response.clicked() {
|
||||||
// clicked pfp
|
info!("clicked {:?}", side_panel.action);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -9,9 +9,28 @@ pub struct DesktopSidePanel<'a> {
|
|||||||
simple_preview_controller: SimpleProfilePreviewController<'a>,
|
simple_preview_controller: SimpleProfilePreviewController<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
|
||||||
|
pub enum SidePanelAction {
|
||||||
|
Panel,
|
||||||
|
Account,
|
||||||
|
Settings,
|
||||||
|
Columns,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SidePanelResponse {
|
||||||
|
pub response: egui::Response,
|
||||||
|
pub action: SidePanelAction,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SidePanelResponse {
|
||||||
|
fn new(action: SidePanelAction, response: egui::Response) -> Self {
|
||||||
|
SidePanelResponse { action, response }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> Widget for DesktopSidePanel<'a> {
|
impl<'a> Widget for DesktopSidePanel<'a> {
|
||||||
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
||||||
self.show(ui)
|
self.show(ui).response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +51,7 @@ impl<'a> DesktopSidePanel<'a> {
|
|||||||
.exact_width(40.0)
|
.exact_width(40.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show(self, ui: &mut egui::Ui) -> egui::Response {
|
pub fn show(self, ui: &mut egui::Ui) -> SidePanelResponse {
|
||||||
let dark_mode = ui.ctx().style().visuals.dark_mode;
|
let dark_mode = ui.ctx().style().visuals.dark_mode;
|
||||||
let spacing_amt = 16.0;
|
let spacing_amt = 16.0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user