[−][src]Struct launchy::CanvasLayout
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 Canvas
es 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]
&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>,
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]
&mut self,
x: u32,
y: u32
) -> Result<(), MidiError>
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]
&mut self,
x: u32,
y: u32,
rotation: Rotation
) -> Result<(), MidiError>
Like add_by_guess
, but with a parameter for the rotation of the Launchpad.
Trait Implementations
impl<'_> Canvas for CanvasLayout<'_>
[src]
fn lowest_visible_brightness(&self) -> f32
[src]
fn bounding_box_width(&self) -> u32
[src]
fn bounding_box_height(&self) -> u32
[src]
fn is_valid(&self, x: u32, y: u32) -> bool
[src]
fn get_new_unchecked_ref(&self, x: u32, y: u32) -> &Color
[src]
fn get_new_unchecked_mut(&mut self, x: u32, y: u32) -> &mut Color
[src]
fn get_old_unchecked_ref(&self, x: u32, y: u32) -> &Color
[src]
fn flush(&mut self) -> Result<(), MidiError>
[src]
fn get(&self, pad: Pad) -> Option<Color>
[src]
fn get_old_unchecked(&self, x: u32, y: u32) -> Color
[src]
fn get_new_unchecked(&self, x: u32, y: u32) -> Color
[src]
fn set_unchecked(&mut self, x: u32, y: u32, color: Color)
[src]
fn get_ref(&self, pad: Pad) -> Option<&Color>
[src]
fn get_mut(&mut self, pad: Pad) -> Option<&mut Color>
[src]
fn get_new(&self, pad: Pad) -> Option<Color>
[src]
fn at_new(&self, pad: Pad) -> Color
[src]
#[must_use]fn set(&mut self, pad: Pad, color: Color) -> Option<()>
[src]
fn iter(&self) -> CanvasIterator
[src]
fn toggle(&mut self, pad: Pad, color: Color) -> Option<()>
[src]
fn clear(&mut self) where
Self: Sized,
[src]
Self: Sized,
fn into_padded(self) -> PaddingCanvas<Self> where
Self: Sized,
[src]
Self: Sized,
impl<'a> DrawTarget<Rgb888> for CanvasLayout<'a>
[src]
type Error = ()
Error type to return when a drawing operation fails. Read more
fn draw_pixel(&mut self, pixel: Pixel<Rgb888>) -> Result<(), ()>
[src]
fn size(&self) -> Size
[src]
fn draw_iter<T>(&mut self, item: T) -> Result<(), Self::Error> where
T: IntoIterator<Item = Pixel<C>>,
[src]
T: IntoIterator<Item = Pixel<C>>,
fn clear(&mut self, color: C) -> Result<(), Self::Error>
[src]
fn draw_line(
&mut self,
item: &Styled<Line, PrimitiveStyle<C>>
) -> Result<(), Self::Error>
[src]
&mut self,
item: &Styled<Line, PrimitiveStyle<C>>
) -> Result<(), Self::Error>
fn draw_triangle(
&mut self,
item: &Styled<Triangle, PrimitiveStyle<C>>
) -> Result<(), Self::Error>
[src]
&mut self,
item: &Styled<Triangle, PrimitiveStyle<C>>
) -> Result<(), Self::Error>
fn draw_rectangle(
&mut self,
item: &Styled<Rectangle, PrimitiveStyle<C>>
) -> Result<(), Self::Error>
[src]
&mut self,
item: &Styled<Rectangle, PrimitiveStyle<C>>
) -> Result<(), Self::Error>
fn draw_circle(
&mut self,
item: &Styled<Circle, PrimitiveStyle<C>>
) -> Result<(), Self::Error>
[src]
&mut self,
item: &Styled<Circle, PrimitiveStyle<C>>
) -> Result<(), Self::Error>
fn draw_image<'b, I>(
&mut self,
item: &'a Image<'b, I, C>
) -> Result<(), Self::Error> where
C: PixelColor + From<<C as PixelColor>::Raw>,
I: ImageDimensions,
&'b I: IntoPixelIter<C>,
[src]
&mut self,
item: &'a Image<'b, I, C>
) -> Result<(), Self::Error> where
C: PixelColor + From<<C as PixelColor>::Raw>,
I: ImageDimensions,
&'b I: IntoPixelIter<C>,
impl<'a> Index<Pad> for CanvasLayout<'a>
[src]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,