From 65928bcdbb98a4926a6fad69121940c99907f869 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 5 Jun 2025 18:20:49 -0700 Subject: [PATCH] chrome: extract method to function We don't need anything from Chrome in this function, so we can just extract it to a top-level function --- crates/notedeck_chrome/src/chrome.rs | 42 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/notedeck_chrome/src/chrome.rs b/crates/notedeck_chrome/src/chrome.rs index 7ea268ea..d1c1439b 100644 --- a/crates/notedeck_chrome/src/chrome.rs +++ b/crates/notedeck_chrome/src/chrome.rs @@ -2,12 +2,12 @@ //#[cfg(target_arch = "wasm32")] //use wasm_bindgen::prelude::*; use crate::app::NotedeckApp; -use egui::{vec2, Button, Label, Layout, RichText, ThemePreference, Widget}; +use egui::{Button, Label, Layout, RichText, ThemePreference, Widget, vec2}; use egui_extras::{Size, StripBuilder}; use nostrdb::{ProfileRecord, Transaction}; use notedeck::{ - profile::get_profile_url, App, AppAction, AppContext, NotedeckTextStyle, UserAccount, - WalletType, + App, AppAction, AppContext, NotedeckTextStyle, UserAccount, WalletType, + profile::get_profile_url, }; use notedeck_columns::Damus; use notedeck_dave::{Dave, DaveAvatar}; @@ -215,7 +215,7 @@ impl Chrome { ) -> Option { ui.add_space(8.0); - let pfp_resp = self.pfp_button(ctx, ui); + let pfp_resp = pfp_button(ctx, ui); let settings_resp = settings_button(ui); let theme_action = match ui.ctx().theme() { @@ -282,23 +282,6 @@ impl Chrome { } } - fn pfp_button(&mut self, ctx: &mut AppContext, ui: &mut egui::Ui) -> egui::Response { - let max_size = ICON_WIDTH * ICON_EXPANSION_MULTIPLE; // max size of the widget - let helper = AnimationHelper::new(ui, "pfp-button", egui::vec2(max_size, max_size)); - - let min_pfp_size = ICON_WIDTH; - let cur_pfp_size = helper.scale_1d_pos(min_pfp_size); - - let txn = Transaction::new(ctx.ndb).expect("should be able to create txn"); - let profile_url = get_account_url(&txn, ctx.ndb, ctx.accounts.get_selected_account()); - - let mut widget = ProfilePic::new(ctx.img_cache, profile_url).size(cur_pfp_size); - - ui.put(helper.get_animation_rect(), &mut widget); - - helper.take_animation_response() - } - fn topdown_sidebar(&mut self, ui: &mut egui::Ui) { // macos needs a bit of space to make room for window // minimize/close buttons @@ -550,3 +533,20 @@ fn chrome_handle_app_action( } } } + +fn pfp_button(ctx: &mut AppContext, ui: &mut egui::Ui) -> egui::Response { + let max_size = ICON_WIDTH * ICON_EXPANSION_MULTIPLE; // max size of the widget + let helper = AnimationHelper::new(ui, "pfp-button", egui::vec2(max_size, max_size)); + + let min_pfp_size = ICON_WIDTH; + let cur_pfp_size = helper.scale_1d_pos(min_pfp_size); + + let txn = Transaction::new(ctx.ndb).expect("should be able to create txn"); + let profile_url = get_account_url(&txn, ctx.ndb, ctx.accounts.get_selected_account()); + + let mut widget = ProfilePic::new(ctx.img_cache, profile_url).size(cur_pfp_size); + + ui.put(helper.get_animation_rect(), &mut widget); + + helper.take_animation_response() +}