Write documentation for new iced_native API

This commit is contained in:
Héctor Ramón Jiménez 2020-05-28 02:04:31 +02:00
parent b9d42a45a8
commit 508128436c
4 changed files with 39 additions and 3 deletions

View File

@ -1,5 +1,7 @@
#![allow(missing_docs)]
use std::{collections::VecDeque, time}; use std::{collections::VecDeque, time};
/// A bunch of time measurements for debugging purposes.
#[derive(Debug)] #[derive(Debug)]
pub struct Debug { pub struct Debug {
is_enabled: bool, is_enabled: bool,
@ -30,6 +32,9 @@ pub struct Debug {
} }
impl Debug { impl Debug {
/// Creates a new [`Debug`].
///
/// [`Debug`]: struct.Debug.html
pub fn new() -> Self { pub fn new() -> Self {
let now = time::Instant::now(); let now = time::Instant::now();

View File

@ -34,7 +34,7 @@
//! [`window::Backend`]: window/trait.Backend.html //! [`window::Backend`]: window/trait.Backend.html
//! [`UserInterface`]: struct.UserInterface.html //! [`UserInterface`]: struct.UserInterface.html
//! [renderer]: renderer/index.html //! [renderer]: renderer/index.html
//#![deny(missing_docs)] #![deny(missing_docs)]
#![deny(missing_debug_implementations)] #![deny(missing_debug_implementations)]
#![deny(unused_results)] #![deny(unused_results)]
#![forbid(unsafe_code)] #![forbid(unsafe_code)]

View File

@ -14,7 +14,7 @@ pub trait Program: Sized {
/// The type of __messages__ your [`Program`] will produce. /// The type of __messages__ your [`Program`] will produce.
/// ///
/// [`Application`]: trait.Program.html /// [`Program`]: trait.Program.html
type Message: std::fmt::Debug + Send; type Message: std::fmt::Debug + Send;
/// Handles a __message__ and updates the state of the [`Program`]. /// Handles a __message__ and updates the state of the [`Program`].
@ -34,6 +34,6 @@ pub trait Program: Sized {
/// ///
/// These widgets can produce __messages__ based on user interaction. /// These widgets can produce __messages__ based on user interaction.
/// ///
/// [`Program`]: trait.Application.html /// [`Program`]: trait.Program.html
fn view(&mut self) -> Element<'_, Self::Message, Self::Renderer>; fn view(&mut self) -> Element<'_, Self::Message, Self::Renderer>;
} }

View File

@ -3,6 +3,10 @@ use crate::{
UserInterface, UserInterface,
}; };
/// The execution state of a [`Program`]. It leverages caching, event
/// processing, and rendering primitive storage.
///
/// [`Program`]: trait.Program.html
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct State<P> pub struct State<P>
where where
@ -19,6 +23,11 @@ impl<P> State<P>
where where
P: Program + 'static, P: Program + 'static,
{ {
/// Creates a new [`State`] with the provided [`Program`], initializing its
/// primitive with the given logical bounds and renderer.
///
/// [`State`]: struct.State.html
/// [`Program`]: trait.Program.html
pub fn new( pub fn new(
mut program: P, mut program: P,
bounds: Size, bounds: Size,
@ -48,22 +57,44 @@ where
} }
} }
/// Returns a reference to the [`Program`] of the [`State`].
///
/// [`Program`]: trait.Program.html
/// [`State`]: struct.State.html
pub fn program(&self) -> &P { pub fn program(&self) -> &P {
&self.program &self.program
} }
/// Returns a reference to the current rendering primitive of the [`State`].
///
/// [`State`]: struct.State.html
pub fn primitive(&self) -> &<P::Renderer as Renderer>::Output { pub fn primitive(&self) -> &<P::Renderer as Renderer>::Output {
&self.primitive &self.primitive
} }
/// Queues an event in the [`State`] for processing during an [`update`].
///
/// [`State`]: struct.State.html
/// [`update`]: #method.update
pub fn queue_event(&mut self, event: Event) { pub fn queue_event(&mut self, event: Event) {
self.queued_events.push(event); self.queued_events.push(event);
} }
/// Queues a message in the [`State`] for processing during an [`update`].
///
/// [`State`]: struct.State.html
/// [`update`]: #method.update
pub fn queue_message(&mut self, message: P::Message) { pub fn queue_message(&mut self, message: P::Message) {
self.queued_messages.push(message); self.queued_messages.push(message);
} }
/// Processes all the queued events and messages, rebuilding and redrawing
/// the widgets of the linked [`Program`] if necessary.
///
/// Returns the [`Command`] obtained from [`Program`] after updating it,
/// only if an update was necessary.
///
/// [`Program`]: trait.Program.html
pub fn update( pub fn update(
&mut self, &mut self,
clipboard: Option<&dyn Clipboard>, clipboard: Option<&dyn Clipboard>,