kutamun 0.1.5

An index-based spatial navigation library
Documentation

About

This library came about when I was utilizing my Iced Spatial Navigation crate in my original draft of my smart TV Linux distro interface.

I had come to notice, however, that it was going to be complicated to handle images within Iced, thanks to its declarative nature.

I then decided to utilize an imperative GUI library, and needed a version of ISN that would work anywhere.

How to Use

First, in your terminal, type:

cargo add kutamun

Second, for a basic example, do something like this:

use kutamun::{MultiGrid, Grid};

pub struct Test {
  msg: String
}

// This is where your navigation logic goes.
// Think about your implementation carefully
// to prevent it from going all over the place.
fn callback(
    internal_grid: &InternalMultiGrid<Test>,
    dir: Direction,
    old_pos: Vector3<usize>
) -> Vector3<usize> {
    Vector3::default()
}

fn main() {
  let multi: MultiGrid<Test> = MultiGrid::new()
  .with_grid((0, Grid::new())) // the (usize, Grid<T>) pair is for indexing
  .with_selected_grid(0); // This automatically selects the corresponding Grid if it's there

  // Fill out the rest of your logic here
}

Or, for a thread-safe example:

use kutamun::{AtomicMultiGrid, Grid};

pub struct Test {
  msg: String
}

// This is where your navigation logic goes.
// Think about your implementation carefully
// to prevent it from going all over the place.
fn callback(
    internal_grid: &InternalMultiGrid<Test>,
    dir: Direction,
    old_pos: Vector3<usize>
) -> Vector3<usize> {
    Vector3::default()
}

fn main() {
  let multi: AtomicMultiGrid<Test> = AtomicMultiGrid::new()
  .with_grid((0, Grid::new())) // the (usize, Grid<T>) pair is for indexing
  .with_selected_grid(0); // This automatically selects the corresponding Grid if it's there

  // Fill out the rest of your logic here
}

Features

Thanks to its architecture, it allows for lightweight and O(1) layout search. Under the hood, MultiGrid and AtomicMultiGrid hold a handle to InternalMultiGrid, the former wrapping it instead an Rc<RefCell<T>> and the latter in an Arc<Mutex<T>>, meaning you can rest assured that the data is memory-safe at all times. (You can even call get_internal on either to get a weak pointer to the underlying data if you want. 😉)