@@ -96,9 +96,11 @@ impl<'a> ProfileView<'a> {
|
|||||||
|
|
||||||
fn profile_body(&mut self, ui: &mut egui::Ui, profile: ProfileRecord<'_>) {
|
fn profile_body(&mut self, ui: &mut egui::Ui, profile: ProfileRecord<'_>) {
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.add_sized([ui.available_size().x, 120.0], |ui: &mut egui::Ui| {
|
banner(
|
||||||
banner(ui, &profile)
|
ui,
|
||||||
});
|
profile.record().profile().and_then(|p| p.banner()),
|
||||||
|
120.0,
|
||||||
|
);
|
||||||
|
|
||||||
let padding = 12.0;
|
let padding = 12.0;
|
||||||
crate::ui::padding(padding, ui, |ui| {
|
crate::ui::padding(padding, ui, |ui| {
|
||||||
@@ -343,7 +345,11 @@ fn display_name_widget(name: NostrName<'_>, add_placeholder_space: bool) -> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_profile_url<'a>(profile: Option<&ProfileRecord<'a>>) -> &'a str {
|
pub fn get_profile_url<'a>(profile: Option<&ProfileRecord<'a>>) -> &'a str {
|
||||||
if let Some(url) = profile.and_then(|pr| pr.record().profile().and_then(|p| p.picture())) {
|
unwrap_profile_url(profile.and_then(|pr| pr.record().profile().and_then(|p| p.picture())))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unwrap_profile_url(maybe_url: Option<&str>) -> &str {
|
||||||
|
if let Some(url) = maybe_url {
|
||||||
url
|
url
|
||||||
} else {
|
} else {
|
||||||
ProfilePic::no_pfp_url()
|
ProfilePic::no_pfp_url()
|
||||||
@@ -366,16 +372,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn banner_texture(
|
fn banner_texture(ui: &mut egui::Ui, banner_url: &str) -> Option<egui::load::SizedTexture> {
|
||||||
ui: &mut egui::Ui,
|
|
||||||
profile: &ProfileRecord<'_>,
|
|
||||||
) -> Option<egui::load::SizedTexture> {
|
|
||||||
// TODO: cache banner
|
// TODO: cache banner
|
||||||
let banner = profile.record().profile().and_then(|p| p.banner());
|
if !banner_url.is_empty() {
|
||||||
|
|
||||||
if let Some(banner) = banner {
|
|
||||||
let texture_load_res =
|
let texture_load_res =
|
||||||
egui::Image::new(banner).load_for_size(ui.ctx(), ui.available_size());
|
egui::Image::new(banner_url).load_for_size(ui.ctx(), ui.available_size());
|
||||||
if let Ok(texture_poll) = texture_load_res {
|
if let Ok(texture_poll) = texture_load_res {
|
||||||
match texture_poll {
|
match texture_poll {
|
||||||
TexturePoll::Pending { .. } => {}
|
TexturePoll::Pending { .. } => {}
|
||||||
@@ -387,16 +388,18 @@ fn banner_texture(
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn banner(ui: &mut egui::Ui, profile: &ProfileRecord<'_>) -> egui::Response {
|
fn banner(ui: &mut egui::Ui, banner_url: Option<&str>, height: f32) -> egui::Response {
|
||||||
if let Some(texture) = banner_texture(ui, profile) {
|
ui.add_sized([ui.available_size().x, height], |ui: &mut egui::Ui| {
|
||||||
images::aspect_fill(
|
banner_url
|
||||||
ui,
|
.and_then(|url| banner_texture(ui, url))
|
||||||
Sense::hover(),
|
.map(|texture| {
|
||||||
texture.id,
|
images::aspect_fill(
|
||||||
texture.size.x / texture.size.y,
|
ui,
|
||||||
)
|
Sense::hover(),
|
||||||
} else {
|
texture.id,
|
||||||
// TODO: default banner texture
|
texture.size.x / texture.size.y,
|
||||||
ui.label("")
|
)
|
||||||
}
|
})
|
||||||
|
.unwrap_or_else(|| ui.label(""))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,9 +53,11 @@ impl<'a, 'cache> ProfilePreview<'a, 'cache> {
|
|||||||
impl egui::Widget for ProfilePreview<'_, '_> {
|
impl egui::Widget for ProfilePreview<'_, '_> {
|
||||||
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.add_sized([ui.available_size().x, 80.0], |ui: &mut egui::Ui| {
|
banner(
|
||||||
banner(ui, self.profile)
|
ui,
|
||||||
});
|
self.profile.record().profile().and_then(|p| p.banner()),
|
||||||
|
80.0,
|
||||||
|
);
|
||||||
|
|
||||||
self.body(ui);
|
self.body(ui);
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user