implement blurring

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-04-18 22:38:04 -05:00
parent 7d2112b472
commit b2abe495ca
10 changed files with 877 additions and 240 deletions

View File

@@ -34,7 +34,7 @@ fn execute_note_action(
accounts: &mut Accounts,
global_wallet: &mut GlobalWallet,
zaps: &mut Zaps,
_images: &mut Images,
images: &mut Images,
ui: &mut egui::Ui,
) -> Option<TimelineOpenResult> {
match action {
@@ -42,13 +42,11 @@ fn execute_note_action(
router.route_to(Route::reply(note_id));
None
}
NoteAction::Profile(pubkey) => {
let kind = TimelineKind::Profile(pubkey);
router.route_to(Route::Timeline(kind.clone()));
timeline_cache.open(ndb, note_cache, txn, pool, &kind)
}
NoteAction::Note(note_id) => 'ex: {
let Ok(thread_selection) = ThreadSelection::from_note_id(ndb, note_cache, txn, note_id)
else {
@@ -62,18 +60,15 @@ fn execute_note_action(
timeline_cache.open(ndb, note_cache, txn, pool, &kind)
}
NoteAction::Hashtag(htag) => {
let kind = TimelineKind::Hashtag(htag.clone());
router.route_to(Route::Timeline(kind.clone()));
timeline_cache.open(ndb, note_cache, txn, pool, &kind)
}
NoteAction::Quote(note_id) => {
router.route_to(Route::quote(note_id));
None
}
NoteAction::Zap(zap_action) => 's: {
let Some(cur_acc) = accounts.get_selected_account_mut() else {
break 's None;
@@ -106,7 +101,6 @@ fn execute_note_action(
None
}
NoteAction::Context(context) => {
match ndb.get_note_by_key(txn, context.note_key) {
Err(err) => tracing::error!("{err}"),
@@ -116,6 +110,10 @@ fn execute_note_action(
}
None
}
NoteAction::Media(media_action) => {
media_action.process(images);
None
}
}
}

View File

@@ -8,17 +8,16 @@ use crate::Result;
use egui::{
text::{CCursorRange, LayoutJob},
text_edit::TextEditOutput,
vec2,
widgets::text_edit::TextEdit,
Frame, Layout, Margin, Pos2, ScrollArea, Sense, TextBuffer,
};
use enostr::{FilledKeypair, FullKeypair, NoteId, Pubkey, RelayPool};
use nostrdb::{Ndb, Transaction};
use notedeck::{Images, MediaCacheType};
use notedeck_ui::blur::PixelDimensions;
use notedeck_ui::images::{get_render_state, RenderState};
use notedeck_ui::jobs::JobsCache;
use notedeck_ui::{
gif::{handle_repaint, retrieve_latest_texture},
images::render_images,
note::render_note_preview,
NoteOptions, ProfilePic,
};
@@ -441,6 +440,14 @@ impl<'a, 'd> PostView<'a, 'd> {
};
let url = &media.url;
let cur_state = get_render_state(
ui.ctx(),
self.note_context.img_cache,
cache_type,
url,
notedeck_ui::images::ImageType::Content,
);
render_post_view_media(
ui,
&mut self.draft.upload_errors,
@@ -448,10 +455,9 @@ impl<'a, 'd> PostView<'a, 'd> {
i,
width,
height,
self.note_context.img_cache,
cache_type,
cur_state,
url,
);
)
}
to_remove.reverse();
for i in to_remove {
@@ -539,34 +545,34 @@ fn render_post_view_media(
cur_index: usize,
width: u32,
height: u32,
images: &mut Images,
cache_type: MediaCacheType,
render_state: RenderState,
url: &str,
) {
render_images(
ui,
images,
url,
notedeck_ui::images::ImageType::Content,
cache_type,
|ui| {
match render_state.texture_state {
notedeck::TextureState::Pending => {
ui.spinner();
},
|_, e| {
}
notedeck::TextureState::Error(e) => {
upload_errors.push(e.to_string());
error!("{e}");
},
|ui, url, renderable_media, gifs| {
let media_size = vec2(width as f32, height as f32);
let max_size = vec2(300.0, 300.0);
let size = if media_size.x > max_size.x || media_size.y > max_size.y {
max_size
}
notedeck::TextureState::Loaded(renderable_media) => {
let max_size = 300;
let size = if width > max_size || height > max_size {
PixelDimensions { x: 300, y: 300 }
} else {
media_size
};
PixelDimensions {
x: width,
y: height,
}
}
.to_points(ui.pixels_per_point())
.to_vec();
let texture_handle =
handle_repaint(ui, retrieve_latest_texture(url, gifs, renderable_media));
let texture_handle = handle_repaint(
ui,
retrieve_latest_texture(url, render_state.gifs, renderable_media),
);
let img_resp = ui.add(
egui::Image::new(texture_handle)
.max_size(size)
@@ -583,8 +589,8 @@ fn render_post_view_media(
to_remove.push(cur_index);
}
ui.advance_cursor_after_rect(img_resp.rect);
},
);
}
}
}
fn post_button(interactive: bool) -> impl egui::Widget {