Skip to content

Commit 36667bc

Browse files
fernandolguevarajb55
authored andcommitted
feat(app_images): add module to manage static app image assets
1 parent 48f17f9 commit 36667bc

File tree

19 files changed

+358
-160
lines changed

19 files changed

+358
-160
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/notedeck_chrome/src/chrome.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use notedeck::{
1212
use notedeck_columns::{timeline::kind::ListKind, timeline::TimelineKind, Damus};
1313

1414
use notedeck_dave::{Dave, DaveAvatar};
15-
use notedeck_ui::{AnimationHelper, ProfilePic};
15+
use notedeck_ui::{app_images, AnimationHelper, ProfilePic};
1616

1717
static ICON_WIDTH: f32 = 40.0;
1818
pub static ICON_EXPANSION_MULTIPLE: f32 = 1.2;
@@ -438,8 +438,7 @@ fn milestone_name() -> impl Widget {
438438
fn expand_side_panel_button() -> impl Widget {
439439
|ui: &mut egui::Ui| -> egui::Response {
440440
let img_size = 40.0;
441-
let img_data = egui::include_image!("../../../assets/damus_rounded_80.png");
442-
let img = egui::Image::new(img_data)
441+
let img = app_images::damus_image()
443442
.max_width(img_size)
444443
.sense(egui::Sense::click());
445444

@@ -450,17 +449,16 @@ fn expand_side_panel_button() -> impl Widget {
450449
fn expanding_button(
451450
name: &'static str,
452451
img_size: f32,
453-
light_img: &egui::ImageSource,
454-
dark_img: &egui::ImageSource,
452+
light_img: egui::Image,
453+
dark_img: egui::Image,
455454
ui: &mut egui::Ui,
456455
) -> egui::Response {
457456
let max_size = ICON_WIDTH * ICON_EXPANSION_MULTIPLE; // max size of the widget
458-
let img_data = if ui.visuals().dark_mode {
457+
let img = if ui.visuals().dark_mode {
459458
dark_img
460459
} else {
461460
light_img
462461
};
463-
let img = egui::Image::new(img_data.clone()).max_width(img_size);
464462

465463
let helper = AnimationHelper::new(ui, name, egui::vec2(max_size, max_size));
466464

@@ -479,8 +477,8 @@ fn support_button(ui: &mut egui::Ui) -> egui::Response {
479477
expanding_button(
480478
"help-button",
481479
16.0,
482-
&egui::include_image!("../../../assets/icons/help_icon_inverted_4x.png"),
483-
&egui::include_image!("../../../assets/icons/help_icon_dark_4x.png"),
480+
app_images::help_light_image(),
481+
app_images::help_dark_image(),
484482
ui,
485483
)
486484
}
@@ -489,8 +487,8 @@ fn settings_button(ui: &mut egui::Ui) -> egui::Response {
489487
expanding_button(
490488
"settings-button",
491489
32.0,
492-
&egui::include_image!("../../../assets/icons/settings_light_4x.png"),
493-
&egui::include_image!("../../../assets/icons/settings_dark_4x.png"),
490+
app_images::settings_light_image(),
491+
app_images::settings_dark_image(),
494492
ui,
495493
)
496494
}
@@ -499,8 +497,8 @@ fn notifications_button(ui: &mut egui::Ui) -> egui::Response {
499497
expanding_button(
500498
"notifications-button",
501499
24.0,
502-
&egui::include_image!("../../../assets/icons/notifications_dark_4x.png"),
503-
&egui::include_image!("../../../assets/icons/notifications_dark_4x.png"),
500+
app_images::notifications_button_image(),
501+
app_images::notifications_button_image(),
504502
ui,
505503
)
506504
}
@@ -509,15 +507,20 @@ fn home_button(ui: &mut egui::Ui) -> egui::Response {
509507
expanding_button(
510508
"home-button",
511509
24.0,
512-
&egui::include_image!("../../../assets/icons/home-toolbar.png"),
513-
&egui::include_image!("../../../assets/icons/home-toolbar.png"),
510+
app_images::home_button_image(),
511+
app_images::home_button_image(),
514512
ui,
515513
)
516514
}
517515

518516
fn columns_button(ui: &mut egui::Ui) -> egui::Response {
519-
let btn = egui::include_image!("../../../assets/icons/columns_80.png");
520-
expanding_button("columns-button", 40.0, &btn, &btn, ui)
517+
expanding_button(
518+
"columns-button",
519+
40.0,
520+
app_images::columns_image(),
521+
app_images::columns_image(),
522+
ui,
523+
)
521524
}
522525

523526
fn dave_sidebar_rect(ui: &mut egui::Ui) -> Rect {
@@ -574,9 +577,8 @@ fn wallet_button() -> impl Widget {
574577
let img_size = 24.0;
575578

576579
let max_size = img_size * ICON_EXPANSION_MULTIPLE;
577-
let img_data = egui::include_image!("../../../assets/icons/wallet-icon.svg");
578580

579-
let mut img = egui::Image::new(img_data).max_width(img_size);
581+
let mut img = app_images::wallet_image().max_width(img_size);
580582

581583
if !ui.visuals().dark_mode {
582584
img = img.tint(egui::Color32::BLACK);

crates/notedeck_chrome/src/setup.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{fonts, theme};
33
use eframe::NativeOptions;
44
use egui::ThemePreference;
55
use notedeck::{AppSizeHandler, DataPath};
6+
use notedeck_ui::app_images;
67
use tracing::info;
78

89
pub fn setup_chrome(ctx: &egui::Context, args: &notedeck::Args, theme: ThemePreference) {
@@ -53,9 +54,7 @@ pub fn generate_native_options(paths: DataPath) -> NativeOptions {
5354
.with_fullsize_content_view(true)
5455
.with_titlebar_shown(false)
5556
.with_title_shown(false)
56-
.with_icon(std::sync::Arc::new(
57-
eframe::icon_data::from_png_bytes(app_icon()).expect("icon"),
58-
));
57+
.with_icon(std::sync::Arc::new(app_images::app_icon()));
5958

6059
if let Some(window_size) = AppSizeHandler::new(&paths).get_app_size() {
6160
builder.with_inner_size(window_size)
@@ -68,9 +67,8 @@ pub fn generate_native_options(paths: DataPath) -> NativeOptions {
6867
// for 3d widgets
6968
depth_buffer: 24,
7069
window_builder: Some(window_builder),
71-
viewport: egui::ViewportBuilder::default().with_icon(std::sync::Arc::new(
72-
eframe::icon_data::from_png_bytes(app_icon()).expect("icon"),
73-
)),
70+
viewport: egui::ViewportBuilder::default()
71+
.with_icon(std::sync::Arc::new(app_images::app_icon())),
7472
..Default::default()
7573
}
7674
}
@@ -89,17 +87,13 @@ fn generate_native_options_with_builder_modifiers(
8987
}
9088
}
9189

92-
pub fn app_icon() -> &'static [u8; 271986] {
93-
std::include_bytes!("../../../assets/damus-app-icon.png")
94-
}
95-
9690
pub fn generate_mobile_emulator_native_options() -> eframe::NativeOptions {
9791
generate_native_options_with_builder_modifiers(|builder| {
9892
builder
9993
.with_fullsize_content_view(true)
10094
.with_titlebar_shown(false)
10195
.with_title_shown(false)
10296
.with_inner_size([405.0, 915.0])
103-
.with_icon(eframe::icon_data::from_png_bytes(app_icon()).expect("icon"))
97+
.with_icon(app_images::app_icon())
10498
})
10599
}

crates/notedeck_columns/src/ui/account_login_view.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use crate::login_manager::AcquireKeyState;
22
use crate::ui::{Preview, PreviewConfig};
33
use egui::{
4-
Align, Button, Color32, Frame, Image, InnerResponse, Margin, RichText, TextBuffer, Vec2,
4+
Align, Button, Color32, Frame, InnerResponse, Layout, Margin, RichText, TextBuffer, TextEdit,
5+
Vec2,
56
};
6-
use egui::{Layout, TextEdit};
77
use egui_winit::clipboard::Clipboard;
88
use enostr::Keypair;
99
use notedeck::{fonts::get_font_size, AppAction, NotedeckTextStyle};
10-
use notedeck_ui::context_menu::{input_context, PasteBehavior};
10+
use notedeck_ui::{
11+
app_images,
12+
context_menu::{input_context, PasteBehavior},
13+
};
1114

1215
pub struct AccountLoginView<'a> {
1316
manager: &'a mut AcquireKeyState,
@@ -138,15 +141,15 @@ fn login_textedit(manager: &mut AcquireKeyState) -> TextEdit {
138141

139142
fn eye_button(ui: &mut egui::Ui, is_visible: bool) -> egui::Response {
140143
let is_dark_mode = ui.visuals().dark_mode;
141-
let icon = Image::new(if is_visible && is_dark_mode {
142-
egui::include_image!("../../../../assets/icons/eye-dark.png")
144+
let icon = if is_visible && is_dark_mode {
145+
app_images::eye_dark_image()
143146
} else if is_visible {
144-
egui::include_image!("../../../../assets/icons/eye-light.png")
147+
app_images::eye_light_image()
145148
} else if is_dark_mode {
146-
egui::include_image!("../../../../assets/icons/eye-slash-dark.png")
149+
app_images::eye_slash_dark_image()
147150
} else {
148-
egui::include_image!("../../../../assets/icons/eye-slash-light.png")
149-
});
151+
app_images::eye_slash_light_image()
152+
};
150153
ui.add(Button::image(icon).frame(false))
151154
}
152155

crates/notedeck_columns/src/ui/accounts.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use egui::{
2-
Align, Button, Frame, Image, InnerResponse, Layout, RichText, ScrollArea, Ui, UiBuilder, Vec2,
2+
Align, Button, Frame, InnerResponse, Layout, RichText, ScrollArea, Ui, UiBuilder, Vec2,
33
};
44
use nostrdb::{Ndb, Transaction};
55
use notedeck::{Accounts, Images};
66
use notedeck_ui::colors::PINK;
77

8+
use notedeck_ui::app_images;
89
use notedeck_ui::profile::preview::SimpleProfilePreview;
910

1011
pub struct AccountsView<'a> {
@@ -175,10 +176,8 @@ fn scroll_area() -> ScrollArea {
175176
}
176177

177178
fn add_account_button() -> Button<'static> {
178-
let img_data = egui::include_image!("../../../../assets/icons/add_account_icon_4x.png");
179-
let img = Image::new(img_data).fit_to_exact_size(Vec2::new(48.0, 48.0));
180179
Button::image_and_text(
181-
img,
180+
app_images::add_account_image().fit_to_exact_size(Vec2::new(48.0, 48.0)),
182181
RichText::new(" Add account")
183182
.size(16.0)
184183
// TODO: this color should not be hard coded. Find some way to add it to the visuals

crates/notedeck_columns/src/ui/add_column.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use core::f32;
22
use std::collections::HashMap;
33

44
use egui::{
5-
pos2, vec2, Align, Color32, FontId, Id, ImageSource, Margin, Pos2, Rect, RichText, Separator,
6-
Ui, Vec2, Widget,
5+
pos2, vec2, Align, Color32, FontId, Id, Image, Margin, Pos2, Rect, RichText, Separator, Ui,
6+
Vec2, Widget,
77
};
88
use enostr::Pubkey;
99
use nostrdb::{Ndb, Transaction};
@@ -17,7 +17,7 @@ use crate::{
1717
};
1818

1919
use notedeck::{AppContext, Images, NotedeckTextStyle, UserAccount};
20-
use notedeck_ui::anim::ICON_EXPANSION_MULTIPLE;
20+
use notedeck_ui::{anim::ICON_EXPANSION_MULTIPLE, app_images};
2121
use tokenator::{ParseError, TokenParser, TokenSerializable, TokenWriter};
2222

2323
use crate::ui::widgets::styled_button;
@@ -226,7 +226,7 @@ impl<'a> AddColumnView<'a> {
226226
let algo_option = ColumnOptionData {
227227
title: "Contact List",
228228
description: "Source the last note for each user in your contact list",
229-
icon: egui::include_image!("../../../../assets/icons/home_icon_dark_4x.png"),
229+
icon: app_images::home_image(),
230230
option: AddColumnOption::Algo(AlgoOption::LastPerPubkey(Decision::Decided(
231231
ListKind::contact_list(deck_author),
232232
))),
@@ -244,7 +244,7 @@ impl<'a> AddColumnView<'a> {
244244
let algo_option = ColumnOptionData {
245245
title: "Last Note per User",
246246
description: "Show the last note for each user from a list",
247-
icon: egui::include_image!("../../../../assets/icons/algo.png"),
247+
icon: app_images::algo_image(),
248248
option: AddColumnOption::Algo(AlgoOption::LastPerPubkey(Decision::Undecided)),
249249
};
250250

@@ -434,7 +434,7 @@ impl<'a> AddColumnView<'a> {
434434
);
435435

436436
let icon_cur_y = animation_rect.top() + cur_height_padding + (total_content_height / 2.0);
437-
let icon_img = egui::Image::new(data.icon).fit_to_exact_size(cur_icon_size);
437+
let icon_img = data.icon.fit_to_exact_size(cur_icon_size);
438438
let icon_rect = Rect::from_center_size(pos2(cur_icon_x_pos, icon_cur_y), cur_icon_size);
439439

440440
icon_img.paint_at(ui, icon_rect);
@@ -449,7 +449,7 @@ impl<'a> AddColumnView<'a> {
449449
vec.push(ColumnOptionData {
450450
title: "Universe",
451451
description: "See the whole nostr universe",
452-
icon: egui::include_image!("../../../../assets/icons/universe_icon_dark_4x.png"),
452+
icon: app_images::universe_image(),
453453
option: AddColumnOption::Universe,
454454
});
455455

@@ -463,32 +463,32 @@ impl<'a> AddColumnView<'a> {
463463
vec.push(ColumnOptionData {
464464
title: "Contacts",
465465
description: "See notes from your contacts",
466-
icon: egui::include_image!("../../../../assets/icons/home_icon_dark_4x.png"),
466+
icon: app_images::home_image(),
467467
option: AddColumnOption::Contacts(source),
468468
});
469469
}
470470
vec.push(ColumnOptionData {
471471
title: "Notifications",
472472
description: "Stay up to date with notifications and mentions",
473-
icon: egui::include_image!("../../../../assets/icons/notifications_icon_dark_4x.png"),
473+
icon: app_images::notifications_image(),
474474
option: AddColumnOption::UndecidedNotification,
475475
});
476476
vec.push(ColumnOptionData {
477477
title: "Hashtags",
478478
description: "Stay up to date with a certain hashtag",
479-
icon: egui::include_image!("../../../../assets/icons/hashtag_icon_4x.png"),
479+
icon: app_images::hashtag_image(),
480480
option: AddColumnOption::UndecidedHashtag,
481481
});
482482
vec.push(ColumnOptionData {
483483
title: "Individual",
484484
description: "Stay up to date with someone's notes & replies",
485-
icon: egui::include_image!("../../../../assets/icons/profile_icon_4x.png"),
485+
icon: app_images::profile_image(),
486486
option: AddColumnOption::UndecidedIndividual,
487487
});
488488
vec.push(ColumnOptionData {
489489
title: "Algo",
490490
description: "Algorithmic feeds to aid in note discovery",
491-
icon: egui::include_image!("../../../../assets/icons/algo.png"),
491+
icon: app_images::algo_image(),
492492
option: AddColumnOption::Algo(AlgoOption::LastPerPubkey(Decision::Undecided)),
493493
});
494494

@@ -508,17 +508,15 @@ impl<'a> AddColumnView<'a> {
508508
vec.push(ColumnOptionData {
509509
title: "Your Notifications",
510510
description: "Stay up to date with your notifications and mentions",
511-
icon: egui::include_image!(
512-
"../../../../assets/icons/notifications_icon_dark_4x.png"
513-
),
511+
icon: app_images::notifications_image(),
514512
option: AddColumnOption::Notification(source),
515513
});
516514
}
517515

518516
vec.push(ColumnOptionData {
519517
title: "Someone else's Notifications",
520518
description: "Stay up to date with someone else's notifications and mentions",
521-
icon: egui::include_image!("../../../../assets/icons/notifications_icon_dark_4x.png"),
519+
icon: app_images::notifications_image(),
522520
option: AddColumnOption::ExternalNotification,
523521
});
524522

@@ -538,15 +536,15 @@ impl<'a> AddColumnView<'a> {
538536
vec.push(ColumnOptionData {
539537
title: "Your Notes",
540538
description: "Keep track of your notes & replies",
541-
icon: egui::include_image!("../../../../assets/icons/profile_icon_4x.png"),
539+
icon: app_images::profile_image(),
542540
option: AddColumnOption::Individual(source),
543541
});
544542
}
545543

546544
vec.push(ColumnOptionData {
547545
title: "Someone else's Notes",
548546
description: "Stay up to date with someone else's notes & replies",
549-
icon: egui::include_image!("../../../../assets/icons/profile_icon_4x.png"),
547+
icon: app_images::profile_image(),
550548
option: AddColumnOption::ExternalIndividual,
551549
});
552550

@@ -586,7 +584,7 @@ pub(crate) fn sized_button(text: &str) -> impl Widget + '_ {
586584
struct ColumnOptionData {
587585
title: &'static str,
588586
description: &'static str,
589-
icon: ImageSource<'static>,
587+
icon: Image<'static>,
590588
option: AddColumnOption,
591589
}
592590

0 commit comments

Comments
 (0)