Fix stream list

This commit is contained in:
kieran 2024-10-09 21:54:56 +01:00
parent 6dd62737d2
commit abfcbc8954
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
3 changed files with 5111 additions and 9 deletions

5095
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,8 @@
use crate::services::Services; use crate::services::Services;
use crate::widgets::avatar::Avatar; use crate::widgets::avatar::Avatar;
use eframe::epaint::Vec2; use eframe::epaint::Vec2;
use egui::{Color32, Image, Rect, Response, RichText, Rounding, Sense, Ui, Widget}; use egui::{Color32, Image, Label, Rect, Response, RichText, Rounding, Sense, TextWrapMode, Ui, Widget};
use log::info;
use nostr_sdk::{Alphabet, Event, PublicKey, SingleLetterTag, TagKind}; use nostr_sdk::{Alphabet, Event, PublicKey, SingleLetterTag, TagKind};
pub struct StreamEvent<'a> { pub struct StreamEvent<'a> {
@ -30,22 +31,27 @@ impl Widget for StreamEvent<'_> {
Some(t) => PublicKey::from_hex(t.as_vec().get(1).unwrap()).unwrap(), Some(t) => PublicKey::from_hex(t.as_vec().get(1).unwrap()).unwrap(),
None => self.event.author() None => self.event.author()
}; };
match self.picture { let w = ui.available_width();
Some(picture) => picture.rounding(Rounding::same(12.)).ui(ui), let h = (w / 16.0) * 9.0;
let img_size = Vec2::new(w, h);
let img = match self.picture {
Some(picture) => picture.fit_to_exact_size(img_size).rounding(Rounding::same(12.)).sense(Sense::click()).ui(ui),
None => { None => {
let w = ui.available_width(); let (response, painter) = ui.allocate_painter(img_size, Sense::click());
let h = (w / 16.0) * 9.0;
let (response, painter) = ui.allocate_painter(Vec2::new(w, h), Sense::hover());
painter.rect_filled(Rect::EVERYTHING, Rounding::same(12.), Color32::from_rgb(200, 200, 200)); painter.rect_filled(Rect::EVERYTHING, Rounding::same(12.), Color32::from_rgb(200, 200, 200));
response response
} }
}; };
if img.clicked() {
info!("Navigating to {}", self.event.id);
}
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.add(Avatar::public_key(self.services, &host).size(40.)); ui.add(Avatar::public_key(self.services, &host).size(40.));
ui.label(RichText::new(self.event.get_tag_content(TagKind::Title).unwrap_or("Unknown")) let title = RichText::new(self.event.get_tag_content(TagKind::Title).unwrap_or("Unknown"))
.size(16.) .size(16.)
.color(Color32::WHITE) .color(Color32::WHITE);
); ui.add(Label::new(title).wrap_mode(TextWrapMode::Truncate));
}) })
}).response }).response
} }

View File

@ -1,6 +1,7 @@
use crate::services::Services; use crate::services::Services;
use crate::widgets::stream::StreamEvent; use crate::widgets::stream::StreamEvent;
use egui::{Frame, Margin, Response, Ui, Widget}; use egui::{Frame, Margin, Response, Ui, Widget};
use egui_extras::Column;
use nostr_sdk::Event; use nostr_sdk::Event;
pub struct StreamList<'a> { pub struct StreamList<'a> {