[][src]Struct iced_native::UserInterface

pub struct UserInterface<'a, Message, Renderer> { /* fields omitted */ }

A set of interactive graphical elements with a specific Layout.

It can be updated and drawn.

Iced tries to avoid dictating how to write your event loop. You are in charge of using this type in your system in any way you want.

Example

The integration example uses a UserInterface to integrate Iced in an existing graphical application.

Implementations

impl<'a, Message, Renderer> UserInterface<'a, Message, Renderer> where
    Renderer: Renderer
[src]

pub fn build<E: Into<Element<'a, Message, Renderer>>>(
    root: E,
    bounds: Size,
    cache: Cache,
    renderer: &mut Renderer
) -> Self
[src]

Builds a user interface for an Element.

It is able to avoid expensive computations when using a Cache obtained from a previous instance of a UserInterface.

Example

Imagine we want to build a UserInterface for the counter example that we previously wrote. Here is naive way to set up our application loop:

use iced_native::{UserInterface, Cache, Size};
use iced_wgpu::Renderer;

// Initialization
let mut counter = Counter::new();
let mut cache = Cache::new();
let mut renderer = Renderer::new();
let mut window_size = Size::new(1024.0, 768.0);

// Application loop
loop {
    // Process system events here...

    // Build the user interface
    let user_interface = UserInterface::build(
        counter.view(),
        window_size,
        cache,
        &mut renderer,
    );

    // Update and draw the user interface here...
    // ...

    // Obtain the cache for the next iteration
    cache = user_interface.into_cache();
}

pub fn update(
    &mut self,
    events: &[Event],
    cursor_position: Point,
    clipboard: Option<&dyn Clipboard>,
    renderer: &Renderer,
    messages: &mut Vec<Message>
) -> Vec<Status>
[src]

Updates the UserInterface by processing each provided Event.

It returns messages that may have been produced as a result of user interactions. You should feed these to your update logic.

Example

Let's allow our counter to change state by completing the previous example:

use iced_native::{UserInterface, Cache, Size, Point};
use iced_wgpu::Renderer;

let mut counter = Counter::new();
let mut cache = Cache::new();
let mut renderer = Renderer::new();
let mut window_size = Size::new(1024.0, 768.0);
let mut cursor_position = Point::default();

// Initialize our event storage
let mut events = Vec::new();
let mut messages = Vec::new();

loop {
    // Obtain system events...

    let mut user_interface = UserInterface::build(
        counter.view(),
        window_size,
        cache,
        &mut renderer,
    );

    // Update the user interface
    let event_statuses = user_interface.update(
        &events,
        cursor_position,
        None,
        &renderer,
        &mut messages
    );

    cache = user_interface.into_cache();

    // Process the produced messages
    for message in messages.drain(..) {
        counter.update(message);
    }
}

pub fn draw(
    &mut self,
    renderer: &mut Renderer,
    cursor_position: Point
) -> Renderer::Output
[src]

Draws the UserInterface with the provided Renderer.

It returns the some Renderer::Output. You should update the icon of the mouse cursor accordingly in your system.

Example

We can finally draw our counter by completing the last example:

use iced_native::{UserInterface, Cache, Size, Point};
use iced_wgpu::Renderer;

let mut counter = Counter::new();
let mut cache = Cache::new();
let mut renderer = Renderer::new();
let mut window_size = Size::new(1024.0, 768.0);
let mut cursor_position = Point::default();
let mut events = Vec::new();
let mut messages = Vec::new();

loop {
    // Obtain system events...

    let mut user_interface = UserInterface::build(
        counter.view(),
        window_size,
        cache,
        &mut renderer,
    );

    // Update the user interface
    let event_statuses = user_interface.update(
        &events,
        cursor_position,
        None,
        &renderer,
        &mut messages
    );

    // Draw the user interface
    let mouse_cursor = user_interface.draw(&mut renderer, cursor_position);

    cache = user_interface.into_cache();

    for message in messages.drain(..) {
        counter.update(message);
    }

    // Update mouse cursor icon...
    // Flush rendering operations...
}

pub fn relayout(self, bounds: Size, renderer: &mut Renderer) -> Self[src]

Relayouts and returns a new UserInterface using the provided bounds.

pub fn into_cache(self) -> Cache[src]

Extract the Cache of the UserInterface, consuming it in the process.

Auto Trait Implementations

impl<'a, Message, Renderer> !RefUnwindSafe for UserInterface<'a, Message, Renderer>

impl<'a, Message, Renderer> !Send for UserInterface<'a, Message, Renderer>

impl<'a, Message, Renderer> !Sync for UserInterface<'a, Message, Renderer>

impl<'a, Message, Renderer> Unpin for UserInterface<'a, Message, Renderer>

impl<'a, Message, Renderer> !UnwindSafe for UserInterface<'a, Message, Renderer>

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,