feat(ui): enhance BlurHash and navigation functionality
Some checks failed
build / checks-matrix (push) Has been cancelled
build / checks-build (push) Has been cancelled
build / codecov (push) Has been cancelled
docs / docs (push) Has been cancelled

- Modify BlurHash struct to accept iced::Length for dimension
- Add Back and Home navigation messages
- Implement scrollable container and button interactions
This commit is contained in:
uttarayan21
2025-11-19 02:16:47 +05:30
parent a1c36e4fb2
commit 442a7e49b2
2 changed files with 83 additions and 54 deletions

View File

@@ -1,6 +1,6 @@
use std::sync::{Arc, LazyLock, atomic::AtomicBool};
use iced::{Element, advanced::Widget, widget::Image};
use iced::{Element, Length, advanced::Widget, widget::Image};
use crate::shared_string::SharedString;
@@ -8,16 +8,16 @@ use crate::shared_string::SharedString;
pub struct BlurHash {
hash: SharedString,
handle: Arc<iced::advanced::image::Handle>,
width: u32,
height: u32,
width: iced::Length,
height: iced::Length,
punch: f32,
}
impl BlurHash {
pub fn recompute(&mut self) {
let pixels = blurhash::decode(&self.hash, self.width, self.height, self.punch)
.unwrap_or_else(|_| vec![0; (self.width * self.height * 4) as usize]);
let handle = iced::advanced::image::Handle::from_rgba(self.width, self.height, pixels);
pub fn recompute(&mut self, width: u32, height: u32, punch: f32) {
let pixels = blurhash::decode(&self.hash, width, height, punch)
.unwrap_or_else(|_| vec![0; (width * height * 4) as usize]);
let handle = iced::advanced::image::Handle::from_rgba(width, height, pixels);
self.handle = Arc::new(handle);
}
@@ -29,27 +29,24 @@ impl BlurHash {
BlurHash {
hash,
handle,
width: 32,
height: 32,
width: 32.into(),
height: 32.into(),
punch: 1.0,
}
}
pub fn width(mut self, height: u32) -> Self {
self.width = height;
self.recompute();
pub fn width(mut self, width: impl Into<Length>) -> Self {
self.width = width.into();
self
}
pub fn height(mut self, height: u32) -> Self {
self.height = height;
self.recompute();
pub fn height(mut self, height: impl Into<Length>) -> Self {
self.height = height.into();
self
}
pub fn punch(mut self, punch: f32) -> Self {
self.punch = punch;
self.recompute();
self
}
}
@@ -60,8 +57,8 @@ where
{
fn size(&self) -> iced::Size<iced::Length> {
iced::Size {
width: iced::Length::Fixed(self.width as f32),
height: iced::Length::Fixed(self.height as f32),
width: self.width,
height: self.height,
}
}
@@ -71,17 +68,21 @@ where
renderer: &Renderer,
limits: &iced::advanced::layout::Limits,
) -> iced::advanced::layout::Node {
iced::widget::image::layout(
let layout = iced::widget::image::layout(
renderer,
limits,
&self.handle,
self.width.into(),
self.height.into(),
self.width,
self.height,
None,
iced::ContentFit::default(),
iced::Rotation::default(),
false,
)
);
let height = layout.bounds().height;
let width = layout.bounds().width;
self.recompute(width as u32, height as u32, self.punch);
layout
}
fn draw(