make optional
This commit is contained in:
@@ -398,7 +398,7 @@ impl<'a> NavTitle<'a> {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(move |p| {
|
.and_then(move |p| {
|
||||||
Some(ui::ProfilePic::from_profile(self.img_cache, p)?.size(pfp_size))
|
Some(ui::ProfilePic::from_profile(self.img_cache, p)?.size(pfp_size).border(2.0))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ impl<'a> NoteView<'a> {
|
|||||||
anim_speed,
|
anim_speed,
|
||||||
);
|
);
|
||||||
|
|
||||||
ui.put(rect, ui::ProfilePic::new(self.img_cache, pic).size(size))
|
ui.put(rect, ui::ProfilePic::new(self.img_cache, pic).size(size).border(2.0))
|
||||||
.on_hover_ui_at_pointer(|ui| {
|
.on_hover_ui_at_pointer(|ui| {
|
||||||
ui.set_max_width(300.0);
|
ui.set_max_width(300.0);
|
||||||
ui.add(ui::ProfilePreview::new(
|
ui.add(ui::ProfilePreview::new(
|
||||||
@@ -246,7 +246,8 @@ impl<'a> NoteView<'a> {
|
|||||||
None => ui
|
None => ui
|
||||||
.add(
|
.add(
|
||||||
ui::ProfilePic::new(self.img_cache, ui::ProfilePic::no_pfp_url())
|
ui::ProfilePic::new(self.img_cache, ui::ProfilePic::no_pfp_url())
|
||||||
.size(pfp_size),
|
.size(pfp_size)
|
||||||
|
.border(2.0),
|
||||||
)
|
)
|
||||||
.interact(sense),
|
.interact(sense),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,13 +113,17 @@ impl<'a> PostView<'a> {
|
|||||||
.get_profile_by_pubkey(txn, self.poster.pubkey.bytes())
|
.get_profile_by_pubkey(txn, self.poster.pubkey.bytes())
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|p| Some(ui::ProfilePic::from_profile(self.img_cache, p)?.size(pfp_size)));
|
.and_then(|p| Some(ui::ProfilePic::from_profile(self.img_cache, p)?
|
||||||
|
.size(pfp_size)
|
||||||
|
.border(2.0)));
|
||||||
|
|
||||||
if let Some(pfp) = poster_pfp {
|
if let Some(pfp) = poster_pfp {
|
||||||
ui.add(pfp);
|
ui.add(pfp);
|
||||||
} else {
|
} else {
|
||||||
ui.add(
|
ui.add(
|
||||||
ui::ProfilePic::new(self.img_cache, ui::ProfilePic::no_pfp_url()).size(pfp_size),
|
ui::ProfilePic::new(self.img_cache, ui::ProfilePic::no_pfp_url())
|
||||||
|
.size(pfp_size)
|
||||||
|
.border(2.0),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ impl<'a> EditProfileView<'a> {
|
|||||||
});
|
});
|
||||||
ui.put(
|
ui.put(
|
||||||
pfp_rect,
|
pfp_rect,
|
||||||
ProfilePic::new(self.img_cache, pfp_url).size(size),
|
ProfilePic::new(self.img_cache, pfp_url).size(size).border(2.0),
|
||||||
);
|
);
|
||||||
|
|
||||||
in_frame(ui, |ui| {
|
in_frame(ui, |ui| {
|
||||||
|
|||||||
@@ -149,7 +149,9 @@ impl<'a> ProfileView<'a> {
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.put(
|
ui.put(
|
||||||
pfp_rect,
|
pfp_rect,
|
||||||
ProfilePic::new(self.img_cache, get_profile_url(Some(&profile))).size(size),
|
ProfilePic::new(self.img_cache, get_profile_url(Some(&profile)))
|
||||||
|
.size(size)
|
||||||
|
.border(2.0),
|
||||||
);
|
);
|
||||||
|
|
||||||
if ui.add(copy_key_widget(&pfp_rect)).clicked() {
|
if ui.add(copy_key_widget(&pfp_rect)).clicked() {
|
||||||
|
|||||||
@@ -10,18 +10,19 @@ pub struct ProfilePic<'cache, 'url> {
|
|||||||
cache: &'cache mut ImageCache,
|
cache: &'cache mut ImageCache,
|
||||||
url: &'url str,
|
url: &'url str,
|
||||||
size: f32,
|
size: f32,
|
||||||
|
border: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl egui::Widget for ProfilePic<'_, '_> {
|
impl egui::Widget for ProfilePic<'_, '_> {
|
||||||
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
||||||
render_pfp(ui, self.cache, self.url, self.size)
|
render_pfp(ui, self.cache, self.url, self.size, self.border)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'cache, 'url> ProfilePic<'cache, 'url> {
|
impl<'cache, 'url> ProfilePic<'cache, 'url> {
|
||||||
pub fn new(cache: &'cache mut ImageCache, url: &'url str) -> Self {
|
pub fn new(cache: &'cache mut ImageCache, url: &'url str) -> Self {
|
||||||
let size = Self::default_size();
|
let size = Self::default_size();
|
||||||
ProfilePic { cache, url, size }
|
ProfilePic { cache, url, size, border: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_profile(
|
pub fn from_profile(
|
||||||
@@ -60,6 +61,12 @@ impl<'cache, 'url> ProfilePic<'cache, 'url> {
|
|||||||
self.size = size;
|
self.size = size;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn border(mut self, width: f32) -> Self {
|
||||||
|
self.border = Some(width);
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_pfp(
|
fn render_pfp(
|
||||||
@@ -67,6 +74,7 @@ fn render_pfp(
|
|||||||
img_cache: &mut ImageCache,
|
img_cache: &mut ImageCache,
|
||||||
url: &str,
|
url: &str,
|
||||||
ui_size: f32,
|
ui_size: f32,
|
||||||
|
border: Option<f32>,
|
||||||
) -> egui::Response {
|
) -> egui::Response {
|
||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
puffin::profile_function!();
|
puffin::profile_function!();
|
||||||
@@ -81,7 +89,7 @@ fn render_pfp(
|
|||||||
}
|
}
|
||||||
|
|
||||||
match img_cache.map()[url].ready() {
|
match img_cache.map()[url].ready() {
|
||||||
None => paint_circle(ui, ui_size),
|
None => paint_circle(ui, ui_size, border),
|
||||||
|
|
||||||
// Failed to fetch profile!
|
// Failed to fetch profile!
|
||||||
Some(Err(_err)) => {
|
Some(Err(_err)) => {
|
||||||
@@ -97,41 +105,46 @@ fn render_pfp(
|
|||||||
}
|
}
|
||||||
|
|
||||||
match img_cache.map().get(url).unwrap().ready() {
|
match img_cache.map().get(url).unwrap().ready() {
|
||||||
None => paint_circle(ui, ui_size),
|
None => paint_circle(ui, ui_size, border),
|
||||||
Some(Err(_e)) => {
|
Some(Err(_e)) => {
|
||||||
//error!("Image load error: {:?}", e);
|
//error!("Image load error: {:?}", e);
|
||||||
paint_circle(ui, ui_size)
|
paint_circle(ui, ui_size, border)
|
||||||
}
|
}
|
||||||
Some(Ok(img)) => pfp_image(ui, img, ui_size),
|
Some(Ok(img)) => pfp_image(ui, img, ui_size, border),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Ok(img)) => pfp_image(ui, img, ui_size),
|
Some(Ok(img)) => pfp_image(ui, img, ui_size, border),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pfp_image(ui: &mut egui::Ui, img: &TextureHandle, size: f32) -> egui::Response {
|
fn pfp_image(ui: &mut egui::Ui, img: &TextureHandle, size: f32, border: Option<f32>)
|
||||||
|
-> egui::Response {
|
||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
puffin::profile_function!();
|
puffin::profile_function!();
|
||||||
|
|
||||||
let (rect, response) = ui.allocate_at_least(vec2(size, size), Sense::hover());
|
let (rect, response) = ui.allocate_at_least(vec2(size, size), Sense::hover());
|
||||||
draw_bg_border(ui, rect.center(), size);
|
if let Some(border_width) = border {
|
||||||
|
draw_bg_border(ui, rect.center(), size, border_width);
|
||||||
|
}
|
||||||
ui.put(rect, egui::Image::new(img).max_width(size));
|
ui.put(rect, egui::Image::new(img).max_width(size));
|
||||||
|
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint_circle(ui: &mut egui::Ui, size: f32) -> egui::Response {
|
fn paint_circle(ui: &mut egui::Ui, size: f32, border: Option<f32>) -> egui::Response {
|
||||||
let (rect, response) = ui.allocate_at_least(vec2(size, size), Sense::hover());
|
let (rect, response) = ui.allocate_at_least(vec2(size, size), Sense::hover());
|
||||||
|
|
||||||
draw_bg_border(ui, rect.center(), size);
|
if let Some(border_width) = border {
|
||||||
|
draw_bg_border(ui, rect.center(), size, border_width);
|
||||||
|
}
|
||||||
ui.painter()
|
ui.painter()
|
||||||
.circle_filled(rect.center(), size / 2.0, ui.visuals().weak_text_color());
|
.circle_filled(rect.center(), size / 2.0, ui.visuals().weak_text_color());
|
||||||
|
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_bg_border(ui: &mut egui::Ui, center: egui::Pos2, size: f32) {
|
fn draw_bg_border(ui: &mut egui::Ui, center: egui::Pos2, size: f32, border_width: f32) {
|
||||||
let border_size = size + 4.0;
|
let border_size = size + (border_width * 2.0);
|
||||||
ui.painter().circle_filled(
|
ui.painter().circle_filled(
|
||||||
center,
|
center,
|
||||||
border_size / 2.0,
|
border_size / 2.0,
|
||||||
@@ -185,7 +198,7 @@ mod preview {
|
|||||||
anim_speed,
|
anim_speed,
|
||||||
);
|
);
|
||||||
|
|
||||||
ui.put(rect, ui::ProfilePic::new(app.img_cache, url).size(size))
|
ui.put(rect, ui::ProfilePic::new(app.img_cache, url).size(size).border(2.0))
|
||||||
.on_hover_ui_at_pointer(|ui| {
|
.on_hover_ui_at_pointer(|ui| {
|
||||||
ui.set_max_width(300.0);
|
ui.set_max_width(300.0);
|
||||||
ui.add(ui::ProfilePreview::new(&profile, app.img_cache));
|
ui.add(ui::ProfilePreview::new(&profile, app.img_cache));
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ impl<'a, 'cache> ProfilePreview<'a, 'cache> {
|
|||||||
|
|
||||||
ui.put(
|
ui.put(
|
||||||
pfp_rect,
|
pfp_rect,
|
||||||
ProfilePic::new(self.cache, get_profile_url(Some(self.profile))).size(size),
|
ProfilePic::new(self.cache, get_profile_url(Some(self.profile)))
|
||||||
|
.size(size)
|
||||||
|
.border(2.0),
|
||||||
);
|
);
|
||||||
ui.add(display_name_widget(
|
ui.add(display_name_widget(
|
||||||
get_display_name(Some(self.profile)),
|
get_display_name(Some(self.profile)),
|
||||||
@@ -89,7 +91,9 @@ impl egui::Widget for SimpleProfilePreview<'_, '_> {
|
|||||||
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
||||||
Frame::none()
|
Frame::none()
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
ui.add(ProfilePic::new(self.cache, get_profile_url(self.profile)).size(48.0));
|
ui.add(ProfilePic::new(self.cache, get_profile_url(self.profile))
|
||||||
|
.size(48.0)
|
||||||
|
.border(1.5));
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.add(display_name_widget(get_display_name(self.profile), true));
|
ui.add(display_name_widget(get_display_name(self.profile), true));
|
||||||
if !self.is_nsec {
|
if !self.is_nsec {
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ impl<'a> DesktopSidePanel<'a> {
|
|||||||
let txn = nostrdb::Transaction::new(self.ndb).expect("should be able to create txn");
|
let txn = nostrdb::Transaction::new(self.ndb).expect("should be able to create txn");
|
||||||
let profile_url = get_account_url(&txn, self.ndb, self.selected_account);
|
let profile_url = get_account_url(&txn, self.ndb, self.selected_account);
|
||||||
|
|
||||||
let widget = ProfilePic::new(self.img_cache, profile_url).size(cur_pfp_size);
|
let widget = ProfilePic::new(self.img_cache, profile_url).size(cur_pfp_size).border(2.0);
|
||||||
|
|
||||||
ui.put(helper.get_animation_rect(), widget);
|
ui.put(helper.get_animation_rect(), widget);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user