#![no_std]
extern crate alloc;
#[cfg(test)]
extern crate std;
pub mod interact;
pub mod layout;
pub mod popover;
pub mod resize;
pub mod scroll;
pub mod split;
pub mod text_input;
pub trait Context: blit::Context {
const SLOP: Self::Scalar;
const MOUSE_SLOP: Self::Scalar;
}
pub trait Clipboard {
fn copy(&mut self, text: &str);
fn request_paste(&mut self);
fn paste(&self) -> Option<&str>;
}
#[cfg(test)]
mod test {
use std::time::Duration;
use blit::{
FrameInfo, Point, Size, Tree, Ui,
input::{Input, Modifiers, MouseButton, TouchPhase},
};
pub struct TestContext;
impl blit::Context for TestContext {
type Scalar = f32;
}
impl crate::Context for TestContext {
const SLOP: f32 = 6.0;
const MOUSE_SLOP: f32 = 2.0;
}
pub fn step<O>(tree: &mut Tree<TestContext>, input: Input<f32>, build: impl FnOnce(Ui<'_, TestContext>) -> O) -> O {
let output = tree.build(
&mut TestContext,
FrameInfo::new(Size::uniform(200.0)),
Duration::ZERO,
input,
build,
);
tree.layout(&mut TestContext);
output
}
pub fn pointer(id: Option<u64>, phase: TouchPhase, x: f32, y: f32) -> Input<f32> {
let position = Point::new(x, y);
match (id, phase) {
(Some(id), phase) => Input::Touch { id, position, phase },
(None, TouchPhase::Down) => Input::MouseDown {
position,
button: MouseButton::Primary,
modifiers: Modifiers::NONE,
},
(None, TouchPhase::Move) => Input::MouseMove {
position,
modifiers: Modifiers::NONE,
},
(None, TouchPhase::Up) => Input::MouseUp {
position,
button: MouseButton::Primary,
modifiers: Modifiers::NONE,
leave: false,
},
(None, TouchPhase::Cancel) => Input::Cancel,
}
}
}