[−][src]Struct iced_native::UserInterface
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]
Renderer: Renderer,
pub fn build<E: Into<Element<'a, Message, Renderer>>>(
root: E,
bounds: Size,
cache: Cache,
renderer: &mut Renderer
) -> Self
[src]
root: E,
bounds: Size,
cache: Cache,
renderer: &mut Renderer
) -> Self
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
) -> Vec<Message>
[src]
&mut self,
events: &[Event],
cursor_position: Point,
clipboard: Option<&dyn Clipboard>,
renderer: &Renderer
) -> Vec<Message>
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(); loop { // Process system events... let mut user_interface = UserInterface::build( counter.view(), window_size, cache, &mut renderer, ); // Update the user interface let messages = user_interface.update( &events, cursor_position, None, &renderer, ); cache = user_interface.into_cache(); // Process the produced messages for message in messages { counter.update(message); } }
pub fn draw(
&mut self,
renderer: &mut Renderer,
cursor_position: Point
) -> Renderer::Output
[src]
&mut self,
renderer: &mut Renderer,
cursor_position: Point
) -> Renderer::Output
Draws the UserInterface
with the provided Renderer
.
It returns the current state of the MouseCursor
. 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(); loop { // Process system events... let mut user_interface = UserInterface::build( counter.view(), window_size, cache, &mut renderer, ); let messages = user_interface.update( &events, cursor_position, None, &renderer, ); // Draw the user interface let mouse_cursor = user_interface.draw(&mut renderer, cursor_position); cache = user_interface.into_cache(); for message in messages { counter.update(message); } // Update mouse cursor icon... // Flush rendering operations... }
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<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
D: AdaptFrom<S, Swp, Dwp, T>,
Dwp: WhitePoint,
Swp: WhitePoint,
T: Component + Float,
[src]
D: AdaptFrom<S, Swp, Dwp, T>,
Dwp: WhitePoint,
Swp: WhitePoint,
T: Component + Float,
fn adapt_into_using<M>(self, method: M) -> D where
M: TransformMatrix<Swp, Dwp, T>,
[src]
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into(self) -> D
[src]
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, U> ConvertInto<U> for T where
U: ConvertFrom<T>,
[src]
U: ConvertFrom<T>,
fn convert_into(self) -> U
[src]
fn convert_unclamped_into(self) -> U
[src]
fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
[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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,