[][src]Struct launchy::CanvasLayout

pub struct CanvasLayout<'a> { /* fields omitted */ }

Imagine this - you have multiple launchpads, you line them up, and now you use the Launchpads as if they were a single device?! You can do that, with CanvasLayout.

Create a layout, add Canvases to it at the position where they appear on your table, and you're ready to rock!

Example:

let mut canvas_layout = CanvasLayout::new(|msg| println!("Got a message: {:?}", msg));
 
// Assuming you have a Launchpad MK2 and a Launchpad S lying next to it:
canvas_layout.add_by_guess::<launchy::mk2::Canvas>(0, 0);
canvas_layout.add_by_guess::<launchy::s::Canvas>(9, 0);
 
// Light the entire canvas layout red - i.e. both Launchpads will be red
for button in canvas_layout.iter() {
	button.set(&mut canvas_layout, launchy::Color::RED);
}

Implementations

impl<'a> CanvasLayout<'a>[src]

pub fn new(callback: impl Fn(CanvasMessage) + Send + Sync + 'static) -> Self[src]

Create a new CanvasLayout that sends messages to the provided callback. The callback must implement Fn because it may be called from multiple devices concurrently.

pub fn new_polling() -> (Self, CanvasLayoutPoller)[src]

Create a new CanvasLayout, plus an input handler object that you can use to poll messages.

pub fn light_threshold(&self) -> f32[src]

pub fn set_light_threshold(&mut self, value: f32)[src]

pub fn add<C: 'a + Canvas, F, E>(
    &mut self,
    x_offset: u32,
    y_offset: u32,
    rotation: Rotation,
    creator: F
) -> Result<(), E> where
    F: FnOnce(Box<dyn Fn(CanvasMessage) + Send + Sync + 'static>) -> Result<C, E>, 
[src]

Add a new device to this canvas layout, at the specified x and y coordinate.

The usage of this method is a bit awkward out of necessity. You need to provide a closure which, when called with a message callback, is expected to return a Canvas that is set up to deliver messsages to the provided message callback.

The Result which the closure returns will be propagated.

Example:

canvas_layout.add(0, 0, |callback| launchy::mk2::Canvas::guess(callback))?;
 
// or even nested layouts:
canvas_layout.add(0, 0, |callback| {
	let mut inner_canvas_layout = CanvasLayout::new(callback);
	inner_canvas_layout.add(0, 0, |inner_callback| launchy::mk2::Canvas::guess(inner_callback))
})?;

If you want an easier way to add simple devices, see add_by_guess.

pub fn add_by_guess<E: 'a + DeviceCanvasTrait>(
    &mut self,
    x: u32,
    y: u32
) -> Result<(), MidiError>
[src]

Add a new device to this canvas, at the specified x and y coordinates. The MIDI connections used for communication with the underlying hardware are determined by guessing based on the device name.

Specifiy the type of device using a generic Canvas type parameter.

Example

// Assuming a Launchpad MK2 and a Launchpad S next to it:
canvas_layout.add_by_guess::<launchy::mk2::Canvas>(0, 0);
canvas_layout.add_by_guess::<launchy::s::Canvas>(9, 0);

pub fn add_by_guess_rotated<E: 'a + DeviceCanvasTrait>(
    &mut self,
    x: u32,
    y: u32,
    rotation: Rotation
) -> Result<(), MidiError>
[src]

Like add_by_guess, but with a parameter for the rotation of the Launchpad.

Trait Implementations

impl<'_> Canvas for CanvasLayout<'_>[src]

impl<'a> DrawTarget<Rgb888> for CanvasLayout<'a>[src]

type Error = ()

Error type to return when a drawing operation fails. Read more

impl<'a> Index<Pad> for CanvasLayout<'a>[src]

type Output = Color

The returned type after indexing.

impl<'a> IndexMut<Pad> for CanvasLayout<'a>[src]

Auto Trait Implementations

impl<'a> !RefUnwindSafe for CanvasLayout<'a>

impl<'a> !Send for CanvasLayout<'a>

impl<'a> !Sync for CanvasLayout<'a>

impl<'a> Unpin for CanvasLayout<'a>

impl<'a> !UnwindSafe for CanvasLayout<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.