Struct State

Source
pub struct State<IMG> { /* private fields */ }
Expand description

The state of the image editor’s core. Most importantly, this contains all the layers and images that are being drawn. This state can be modified externally mainly by sending Events via the execute method.

Implementations§

Source§

impl<IMG: Bitmap + Serialize + for<'de> Deserialize<'de>> State<IMG>

Source

pub fn new( size: Size<i32>, load_project_fn: Option<LoadProject>, save_project_fn: Option<SaveProject>, ) -> Self

Create a new default state for the editor, with a starting canvas size

Source

pub fn execute(&mut self, event: Event) -> Result<CanvasEffect>

Execute an Event. This is the main way of changing the editor’s state, and probably the most central method of this library. A CanvasEffect is returned to communicate to the caller what kind of visual updates must be made.

Source

pub fn canvas_mut(&mut self) -> &mut Canvas<IMG>

Get a mutable reference to the active Layer’s Canvas

Source

pub fn canvas(&self) -> &Canvas<IMG>

Get a reference to the active Layer’s Canvas

Source

pub fn layers(&self) -> &Layers<IMG>

Get a reference to the collection of Layers

Source

pub fn selected_tool(&self) -> Tool

Get the currently selected Tool

Source

pub fn main_color(&self) -> Color

Get the main (selected) color. This is the color used by most tools when drawing

Source

pub fn spritesheet(&self) -> Size<u8>

Get the spritesheet dimensions (number of horizontal and vertical frames). For a static image (not an animation) it will be (1, 1).

Source

pub fn palette(&self) -> &[Color]

Get the colors of the palette

Source

pub fn selection(&self) -> Option<Selection>

Get the Selection

Source

pub fn free_image(&self) -> Option<&FreeImage<IMG>>

Get the FreeImage

Source

pub fn update_free_image(&mut self, mouse_canvas: Position<i32>) -> Result<()>

When drawing lines, rectangles, etc. or moving things, there are visible effects (e.g. a preview of the line or of the image being moved) that are not immediately represented in the canvas, but are stored as a FreeImage instead. This method must be called as often as possible whenever the mouse moves, in order to update this preview image.

Trait Implementations§

Source§

impl<IMG: Debug> Debug for State<IMG>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, IMG> Deserialize<'de> for State<IMG>
where IMG: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<IMG> Serialize for State<IMG>
where IMG: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<IMG> Freeze for State<IMG>
where IMG: Freeze,

§

impl<IMG> RefUnwindSafe for State<IMG>
where IMG: RefUnwindSafe,

§

impl<IMG> Send for State<IMG>
where IMG: Send,

§

impl<IMG> Sync for State<IMG>
where IMG: Sync,

§

impl<IMG> Unpin for State<IMG>
where IMG: Unpin,

§

impl<IMG> UnwindSafe for State<IMG>
where IMG: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,