use crate::{
input::{Event, EventStatus},
render::{Position, RenderContext, Size},
};
mod event_context;
pub use copyrs::clipboard;
pub use copyrs::{Clipboard, ClipboardBinaryKind, ClipboardContent, ClipboardTextKind, Result};
pub use event_context::*;
pub trait LayoutInfo {
fn bounds(&self) -> Size;
}
impl LayoutInfo for Size {
fn bounds(&self) -> Size {
*self
}
}
pub trait RenderInfo {
fn bounds(&self) -> Size;
fn position(&self) -> Position;
}
pub struct SimpleRenderInfo {
pub bounds: Size,
pub position: Position,
}
impl RenderInfo for SimpleRenderInfo {
fn bounds(&self) -> Size {
self.bounds
}
fn position(&self) -> Position {
self.position
}
}
impl SimpleRenderInfo {
pub fn new(bounds: Size, position: Position) -> Self {
Self { bounds, position }
}
}
pub trait Widget<Message> {
type LayoutInfo: LayoutInfo;
type RenderInfo: RenderInfo;
fn render(
&self,
position: Position,
layout_info: &Self::LayoutInfo,
context: &mut dyn RenderContext,
) -> std::io::Result<Self::RenderInfo>;
fn layout(&self, available_size: Size) -> Self::LayoutInfo;
fn on_event(
&mut self,
event: &Event,
render_info: &Self::RenderInfo,
event_context: &mut dyn EventContext<Message>,
) -> EventStatus {
let _ = event;
let _ = render_info;
let _ = event_context;
EventStatus::Ignored
}
}