#[cfg(feature = "accesskit")]
mod accessibility;
mod button;
mod context_menu;
mod disclosure;
mod dock;
mod inspector;
mod kind;
mod list;
mod number_entry;
mod outliner;
mod scrollbar;
mod select;
mod split;
mod style;
mod tabs;
mod text_input;
mod value;
use glam::Vec2;
use crate::style::Declaration;
use crate::text::FontAtlas;
use crate::tree::{
AvailableSpace, Direction, FlexDirection, InspectorOptions, LengthAuto, NavInput, NodeKey,
NodeStyle, TextInput, Ui,
};
use crate::widget::PointerInput;
pub(super) const PAGE: f32 = 400.0;
pub(super) fn frame<R>(
ui: &mut Ui,
pointer: PointerInput,
nav: NavInput,
build: impl FnOnce(&mut Ui) -> R,
) -> R {
frame_with_text(ui, pointer, nav, TextInput::default(), build)
}
pub(super) fn frame_with_text<R>(
ui: &mut Ui,
pointer: PointerInput,
nav: NavInput,
text: TextInput,
build: impl FnOnce(&mut Ui) -> R,
) -> R {
ui.begin_frame_with(pointer, nav);
ui.set_text_input(text);
let mut out = None;
ui.block(
"#page",
&[
Declaration::FlexDirection(FlexDirection::Column),
Declaration::Width(LengthAuto::Px(PAGE)),
Declaration::Height(LengthAuto::Px(PAGE)),
],
|ui| out = Some(build(ui)),
);
ui.layout(
Vec2::ZERO,
AvailableSpace::definite(Vec2::splat(PAGE)),
&FontAtlas::built_in(),
);
out.expect("the page builds its content")
}
pub(super) fn idle() -> PointerInput {
PointerInput::hovering(Vec2::splat(-1.0))
}
pub(super) fn press(pos: Vec2) -> PointerInput {
PointerInput {
pos,
down: true,
released: false,
secondary_pressed: false,
}
}
pub(super) fn release(pos: Vec2) -> PointerInput {
PointerInput {
pos,
down: false,
released: true,
secondary_pressed: false,
}
}
pub(super) const UP: NavInput = NavInput::toward(Direction::Up);
pub(super) const DOWN: NavInput = NavInput::toward(Direction::Down);
pub(super) const LEFT: NavInput = NavInput::toward(Direction::Left);
pub(super) const RIGHT: NavInput = NavInput::toward(Direction::Right);
pub(super) fn rect(ui: &Ui, key: NodeKey) -> (Vec2, Vec2) {
ui.rect(key).expect("laid out last frame")
}
pub(super) fn centre(ui: &Ui, key: NodeKey) -> Vec2 {
let (min, max) = rect(ui, key);
(min + max) * 0.5
}
pub(super) fn style_of(ui: &Ui, key: NodeKey) -> NodeStyle {
ui.nodes
.iter()
.find(|node| node.key == key)
.expect("built this frame")
.style
}
pub(super) fn children_of(ui: &Ui, key: NodeKey) -> Vec<NodeKey> {
ui.child_keys(key)
}
pub(super) fn linear(hex: &str) -> [f32; 4] {
let mut style = NodeStyle::DEFAULT;
let mut ui = Ui::new();
ui.add_stylesheet("colour.css", &format!("#probe {{ background: {hex}; }}"));
frame(&mut ui, idle(), NavInput::default(), |ui| {
let key = ui.block("#probe", &[], |_| {}).key;
style = style_of(ui, key);
});
style.background
}