#![allow(
clippy::must_use_candidate,
clippy::missing_const_for_fn,
clippy::needless_pass_by_value
)]
use wasm_bindgen::prelude::*;
use crate::{
DefaultLayoutInterpreter, Direction, LogicalLayout, Rect, Size, SplitDirection,
rendered::WindowTree, traits::LayoutInterpreter,
};
#[wasm_bindgen(start)]
pub fn init() {
console_error_panic_hook::set_once();
}
#[wasm_bindgen]
pub fn interpret_layout(
logical: LogicalLayout,
screen_width: u16,
screen_height: u16,
) -> WindowTree {
let screen = Size::new(screen_width, screen_height);
DefaultLayoutInterpreter::new().interpret(&logical, screen)
}
#[wasm_bindgen]
pub fn rect_contains(rect: Rect, x: u16, y: u16) -> bool {
rect.contains_xy(x, y)
}
#[wasm_bindgen]
pub fn direction_opposite(dir: Direction) -> Direction {
dir.opposite()
}
#[wasm_bindgen]
pub fn direction_is_horizontal(dir: Direction) -> bool {
dir.is_horizontal()
}
#[wasm_bindgen]
pub fn direction_is_vertical(dir: Direction) -> bool {
dir.is_vertical()
}
#[wasm_bindgen]
pub fn split_opposite(dir: SplitDirection) -> SplitDirection {
dir.opposite()
}
#[wasm_bindgen]
pub fn split_is_horizontal(dir: SplitDirection) -> bool {
matches!(dir, SplitDirection::Horizontal)
}
#[wasm_bindgen]
pub fn split_is_vertical(dir: SplitDirection) -> bool {
matches!(dir, SplitDirection::Vertical)
}
#[wasm_bindgen]
pub fn layout_single(buffer_id: u64, viewport_id: u64) -> LogicalLayout {
LogicalLayout::single(buffer_id, viewport_id)
}
#[wasm_bindgen]
pub fn layout_hsplit(children: Vec<LogicalLayout>) -> LogicalLayout {
LogicalLayout::hsplit(children)
}
#[wasm_bindgen]
pub fn layout_vsplit(children: Vec<LogicalLayout>) -> LogicalLayout {
LogicalLayout::vsplit(children)
}
#[wasm_bindgen]
pub fn layout_window_count(layout: &LogicalLayout) -> usize {
layout.window_count()
}
#[wasm_bindgen]
pub fn layout_is_leaf(layout: &LogicalLayout) -> bool {
layout.is_leaf()
}
#[cfg(test)]
#[path = "wasm_tests.rs"]
mod tests;