mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-17 00:44:18 +01:00
Merge new Accounts button to chrome sidebar by kernel #994
kernelkind (3):
use saturating sub
add new Accounts button to chrome sidebar
add ChromePanelAction::Profile & use for pfp
This commit is contained in:
BIN
assets/icons/accounts.png
Normal file
BIN
assets/icons/accounts.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
@@ -58,6 +58,7 @@ pub enum ChromePanelAction {
|
||||
Wallet,
|
||||
Toolbar(ToolbarAction),
|
||||
SaveTheme(ThemePreference),
|
||||
Profile(notedeck::enostr::Pubkey),
|
||||
}
|
||||
|
||||
impl ChromePanelAction {
|
||||
@@ -160,6 +161,9 @@ impl ChromePanelAction {
|
||||
notedeck_columns::Route::Wallet(WalletType::Auto),
|
||||
);
|
||||
}
|
||||
Self::Profile(pk) => {
|
||||
columns_route_to_profile(pk, chrome, ctx, ui);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -571,6 +575,16 @@ fn columns_button(ui: &mut egui::Ui) -> egui::Response {
|
||||
)
|
||||
}
|
||||
|
||||
fn accounts_button(ui: &mut egui::Ui) -> egui::Response {
|
||||
expanding_button(
|
||||
"accounts-button",
|
||||
24.0,
|
||||
app_images::accounts_image().tint(ui.visuals().text_color()),
|
||||
app_images::accounts_image(),
|
||||
ui,
|
||||
)
|
||||
}
|
||||
|
||||
fn dave_sidebar_rect(ui: &mut egui::Ui) -> Rect {
|
||||
let size = vec2(60.0, 60.0);
|
||||
let available = ui.available_rect_before_wrap();
|
||||
@@ -693,6 +707,59 @@ fn chrome_handle_app_action(
|
||||
}
|
||||
}
|
||||
|
||||
fn columns_route_to_profile(
|
||||
pk: ¬edeck::enostr::Pubkey,
|
||||
chrome: &mut Chrome,
|
||||
ctx: &mut AppContext,
|
||||
ui: &mut egui::Ui,
|
||||
) {
|
||||
chrome.switch_to_columns();
|
||||
let Some(columns) = chrome.get_columns_app() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let cols = columns
|
||||
.decks_cache
|
||||
.active_columns_mut(ctx.i18n, ctx.accounts)
|
||||
.unwrap();
|
||||
|
||||
let router = cols.get_first_router();
|
||||
if router.routes().iter().any(|r| {
|
||||
matches!(
|
||||
r,
|
||||
notedeck_columns::Route::Timeline(TimelineKind::Profile(_))
|
||||
)
|
||||
}) {
|
||||
router.go_back();
|
||||
return;
|
||||
}
|
||||
|
||||
let txn = Transaction::new(ctx.ndb).unwrap();
|
||||
let m_action = notedeck_columns::actionbar::execute_and_process_note_action(
|
||||
notedeck::NoteAction::Profile(*pk),
|
||||
ctx.ndb,
|
||||
cols,
|
||||
0,
|
||||
&mut columns.timeline_cache,
|
||||
&mut columns.threads,
|
||||
ctx.note_cache,
|
||||
ctx.pool,
|
||||
&txn,
|
||||
ctx.unknown_ids,
|
||||
ctx.accounts,
|
||||
ctx.global_wallet,
|
||||
ctx.zaps,
|
||||
ctx.img_cache,
|
||||
ui,
|
||||
);
|
||||
|
||||
if let Some(action) = m_action {
|
||||
let col = cols.column_mut(0);
|
||||
|
||||
action.process(&mut col.router, &mut col.sheet_router);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
@@ -720,6 +787,7 @@ fn bottomup_sidebar(
|
||||
ui.add_space(8.0);
|
||||
|
||||
let pfp_resp = pfp_button(ctx, ui).on_hover_cursor(egui::CursorIcon::PointingHand);
|
||||
let accounts_resp = accounts_button(ui).on_hover_cursor(egui::CursorIcon::PointingHand);
|
||||
let settings_resp = settings_button(ui).on_hover_cursor(egui::CursorIcon::PointingHand);
|
||||
|
||||
let theme_action = match ui.ctx().theme() {
|
||||
@@ -791,6 +859,9 @@ fn bottomup_sidebar(
|
||||
}
|
||||
|
||||
if pfp_resp.clicked() {
|
||||
let pk = ctx.accounts.get_selected_account().key.pubkey;
|
||||
Some(ChromePanelAction::Profile(pk))
|
||||
} else if accounts_resp.clicked() {
|
||||
Some(ChromePanelAction::Account)
|
||||
} else if settings_resp.clicked() {
|
||||
Some(ChromePanelAction::Settings)
|
||||
|
||||
@@ -474,12 +474,10 @@ impl TimelineSub {
|
||||
let before = self.state.clone();
|
||||
's: {
|
||||
match &mut self.state {
|
||||
SubState::NoSub { dependers } => {
|
||||
*dependers -= 1;
|
||||
}
|
||||
SubState::NoSub { dependers } => *dependers = dependers.saturating_sub(1),
|
||||
SubState::LocalOnly { local, dependers } => {
|
||||
if *dependers > 1 {
|
||||
*dependers -= 1;
|
||||
*dependers = dependers.saturating_sub(1);
|
||||
break 's;
|
||||
}
|
||||
|
||||
@@ -492,7 +490,7 @@ impl TimelineSub {
|
||||
}
|
||||
SubState::RemoteOnly { remote, dependers } => {
|
||||
if *dependers > 1 {
|
||||
*dependers -= 1;
|
||||
*dependers = dependers.saturating_sub(1);
|
||||
break 's;
|
||||
}
|
||||
|
||||
@@ -502,7 +500,7 @@ impl TimelineSub {
|
||||
}
|
||||
SubState::Unified { unified, dependers } => {
|
||||
if *dependers > 1 {
|
||||
*dependers -= 1;
|
||||
*dependers = dependers.saturating_sub(1);
|
||||
break 's;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,10 @@ pub fn add_account_image() -> Image<'static> {
|
||||
))
|
||||
}
|
||||
|
||||
pub fn accounts_image() -> Image<'static> {
|
||||
Image::new(include_image!("../../../assets/icons/accounts.png"))
|
||||
}
|
||||
|
||||
pub fn add_column_dark_image() -> Image<'static> {
|
||||
Image::new(include_image!(
|
||||
"../../../assets/icons/add_column_dark_4x.png"
|
||||
|
||||
Reference in New Issue
Block a user