mod primitive;
mod widget;
use std::sync::{Arc, Mutex};
use iced::mouse;
pub use primitive::{SizeRequestSlot, WidgetBounds};
pub use widget::{FrameWidget, frame};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum ContentFit {
#[default]
Fill,
Contain,
Cover,
FitWidth,
FitHeight,
None,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum Alignment {
TopLeft,
TopCenter,
TopRight,
CenterLeft,
#[default]
Center,
CenterRight,
BottomLeft,
BottomCenter,
BottomRight,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum FilterMode {
#[default]
Linear,
Nearest,
}
impl FilterMode {
pub(crate) fn to_wgpu(self) -> wgpu::FilterMode {
match self {
Self::Linear => wgpu::FilterMode::Linear,
Self::Nearest => wgpu::FilterMode::Nearest,
}
}
}
impl std::fmt::Display for ContentFit {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Fill => f.write_str("Fill"),
Self::Contain => f.write_str("Contain"),
Self::Cover => f.write_str("Cover"),
Self::FitWidth => f.write_str("FitWidth"),
Self::FitHeight => f.write_str("FitHeight"),
Self::None => f.write_str("None"),
}
}
}
impl std::fmt::Display for Alignment {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::TopLeft => f.write_str("TopLeft"),
Self::TopCenter => f.write_str("TopCenter"),
Self::TopRight => f.write_str("TopRight"),
Self::CenterLeft => f.write_str("CenterLeft"),
Self::Center => f.write_str("Center"),
Self::CenterRight => f.write_str("CenterRight"),
Self::BottomLeft => f.write_str("BottomLeft"),
Self::BottomCenter => f.write_str("BottomCenter"),
Self::BottomRight => f.write_str("BottomRight"),
}
}
}
impl std::fmt::Display for FilterMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Linear => f.write_str("Linear"),
Self::Nearest => f.write_str("Nearest"),
}
}
}
#[derive(Debug)]
pub struct Frame {
pub data: Vec<u8>,
pub width: u32,
pub height: u32,
pub format: wgpu::TextureFormat,
}
impl Frame {
pub fn new(data: Vec<u8>, width: u32, height: u32) -> Self {
Self {
data,
width,
height,
format: wgpu::TextureFormat::Rgba8Unorm,
}
}
pub fn with_format(mut self, format: wgpu::TextureFormat) -> Self {
self.format = format;
self
}
}
pub trait FrameSource: Clone + 'static {
fn frame_slot(&self) -> Arc<Mutex<Option<Frame>>>;
fn size_request_slot(&self) -> SizeRequestSlot;
fn cursor(&self) -> mouse::Interaction;
fn handle_event(
&self,
event: &iced::Event,
bounds: iced::Rectangle,
cursor: mouse::Cursor,
focused: bool,
) -> bool;
}