refactor: widget state

This commit is contained in:
2024-10-11 16:42:05 +01:00
parent 67d6381123
commit 9a8bb54e08
17 changed files with 447 additions and 153 deletions

View File

@ -1,5 +1,5 @@
use egui::{Color32, Image, Rect, Response, Rounding, Sense, Ui, Vec2, Widget};
use crate::services::profile::ProfileService;
use egui::{Color32, Image, Rect, Response, Rounding, Sense, Ui, Vec2, Widget};
pub struct Avatar<'a> {
image: Option<Image<'a>>,
@ -10,6 +10,10 @@ impl<'a> Avatar<'a> {
Self { image: Some(img) }
}
pub fn new_optional(img: Option<Image<'a>>) -> Self {
Self { image: img }
}
pub fn public_key(svc: &'a ProfileService, pk: &[u8; 32]) -> Self {
if let Some(meta) = svc.get_profile(pk) {
if let Some(img) = &meta.picture {
@ -45,8 +49,10 @@ impl<'a> Widget for Avatar<'a> {
img.rounding(Rounding::same(ui.available_height())).ui(ui)
}
None => {
let (response, painter) = ui.allocate_painter(Vec2::new(32., 32.), Sense::hover());
painter.rect_filled(Rect::EVERYTHING, Rounding::same(32.), Color32::from_rgb(200, 200, 200));
let h = ui.available_height();
let rnd = Rounding::same(h);
let (response, painter) = ui.allocate_painter(Vec2::new(h,h), Sense::click());
painter.rect_filled(Rect::EVERYTHING, rnd, Color32::from_rgb(200, 200, 200));
response
}
}