use rae::{
hit_resize_handle, CommandItem, CommandPalette, CursorKind, HitMap, HitRegion, KeyModifier,
Rect, ScrollAnchor, ScrollState, Shortcut, SnippetSet, TextSnippet, Vec2,
};
fn main() {
let mut scroll = ScrollState::new().with_anchor(ScrollAnchor::Bottom);
scroll.set_bounds(128, 16);
scroll.scroll_to_end();
scroll.set_bounds(133, 16);
scroll.ensure_visible(120);
println!("scroll visible rows: {:?}", scroll.visible_range());
println!("scroll at end: {}", scroll.is_at_end());
let panel = Rect::new(24.0, 64.0, 520.0, 360.0);
let mut hits = HitMap::new();
hits.push(HitRegion::new("panel", panel).with_cursor(CursorKind::Grab));
hits.push(
HitRegion::new("primary-action", Rect::new(404.0, 82.0, 112.0, 36.0))
.with_z_index(10)
.with_cursor(CursorKind::Pointer),
);
let pointer = Vec2::new(420.0, 96.0);
if let Some(region) = hits.hit_test(pointer) {
println!("hit: {} cursor:{:?}", region.id, region.cursor);
}
let resize = hit_resize_handle(panel, Vec2::new(544.0, 424.0), 8.0);
println!(
"resize: {:?} cursor:{:?}",
resize,
resize.map(|handle| handle.cursor())
);
let mut palette = CommandPalette::new([
CommandItem::new("open", "Open File")
.with_keywords(["document", "load"])
.with_shortcut(Shortcut::new("O").with_modifiers([KeyModifier::Ctrl])),
CommandItem::new("toggle.theme", "Toggle Theme")
.with_keywords(["palette", "color"])
.with_shortcut(
Shortcut::new("T").with_modifiers([KeyModifier::Ctrl, KeyModifier::Shift]),
),
CommandItem::new("copy.safe", "Copy Safe Text").with_keywords(["clipboard", "sanitize"]),
]);
palette.set_query("pal");
for item in palette.filtered_items() {
let shortcut = item.shortcut.as_ref().map(|shortcut| shortcut.label());
println!("command: {} shortcut:{:?}", item.title, shortcut);
}
let snippets = SnippetSet::new([
TextSnippet::new("hdr", "# Section").with_keywords(["markdown", "heading"]),
TextSnippet::new("code", "```rust\nfn main() {}\n```").with_description("Rust code fence"),
]);
println!("snippet hdr: {:?}", snippets.expand("hdr"));
println!(
"snippet matches: {:?}",
snippets
.matches("rust")
.iter()
.map(|snippet| snippet.trigger.as_str())
.collect::<Vec<_>>()
);
}