### Create Setup UI Component Source: https://docs.iced.rs/src/iced_devtools/lib.rs.html Generates the UI for the setup process, including action buttons and installation command display. ```rust fn setup(goal: &Goal) -> Element<'_, Message, Theme, Renderer> where Renderer: program::Renderer + 'static, { let controls = row![ button(text("Cancel").center().width(Fill)) .width(100) .on_press(Message::CancelSetup) .style(button::danger), space::horizontal(), button( text(match goal { Goal::Installation => "Install", Goal::Update { .. } => "Update", }) .center() .width(Fill) ) .width(100) .on_press(Message::InstallComet) .style(button::success), ]; let command = container( text!( "cargo install --locked \ --git https://github.com/iced-rs/comet.git \ --rev {}", comet::COMPATIBLE_REVISION ) .size(14) .font(Font::MONOSPACE), ) .width(Fill) .padding(5) .style(container::dark); Element::from(match goal { Goal::Installation => column![ ``` -------------------------------- ### Initiate Comet Installation Source: https://docs.iced.rs/src/iced_devtools/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Handles the 'InstallComet' message by setting the mode to 'Setup::Running' and initiating the Comet installation process. It maps the installation events to 'Message::Installing' and 'Event::Message'. ```rust Message::InstallComet => { self.mode = Mode::Setup(Setup::Running { logs: Vec::new() }); comet::install() .map(Message::Installing) .map(Event::Message) } ``` -------------------------------- ### Example: Pick List Usage Source: https://docs.iced.rs/src/iced_widget/helpers.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to create and use a `PickList` widget for selecting an item from a list. It includes setup for state, message handling, and display logic. ```rust # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; } # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>; # use iced::widget::pick_list; struct State { favorite: Option, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum Fruit { Apple, Orange, Strawberry, Tomato, } #[derive(Debug, Clone)] enum Message { FruitSelected(Fruit), } fn view(state: &State) -> Element<'_, Message> { let fruits = [ Fruit::Apple, Fruit::Orange, Fruit::Strawberry, Fruit::Tomato, ]; pick_list( state.favorite, fruits, Fruit::to_string, ) .on_select(Message::FruitSelected) .placeholder("Select your favorite fruit...") .into() } fn update(state: &mut State, message: Message) { match message { Message::FruitSelected(fruit) => { state.favorite = Some(fruit); } } } impl std::fmt::Display for Fruit { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { Self::Apple => "Apple", Self::Orange => "Orange", Self::Strawberry => "Strawberry", Self::Tomato => "Tomato", }) } } ``` -------------------------------- ### Building a UserInterface Source: https://docs.iced.rs/iced_runtime/user_interface/struct.UserInterface.html?search= Demonstrates the naive setup of an application loop to build a UserInterface for a counter example. It initializes necessary components like the counter, cache, renderer, and window, then enters a loop to continuously build the UI. ```rust use iced_runtime::core::shell; use iced_runtime::core::window; use iced_runtime::core::Size; use iced_runtime::user_interface::{self, UserInterface}; use iced_wgpu::Renderer; // Initialization let mut counter = Counter::new(); let mut cache = user_interface::Cache::new(); let mut renderer = Renderer::default(); let mut window = window::Headless; // This should be a proper window, like a `winit` one let mut waker = shell::Waker::noop(); 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(); } ``` -------------------------------- ### Devtools Setup Goal Source: https://docs.iced.rs/src/iced_devtools/lib.rs.html Specifies the goal of the setup process, which can be a new installation or an update to a specific revision. ```rust enum Goal { Installation, Update { revision: Option }, } ``` -------------------------------- ### Running a basic Iced application Source: https://docs.iced.rs/src/iced/lib.rs.html?search=u32+-%3E+bool This example demonstrates how to use the `iced::run` function to start a simple Iced application. It defines an `update` function to handle messages and a `view` function to render the UI. The application state is a `u64` that increments on button press. ```rust use iced::widget::{button, column, Column}; pub fn main() -> iced::Result { iced::run(update, view) } #[derive(Debug, Clone)] enum Message { Increment, } fn update(value: &mut u64, message: Message) { match message { Message::Increment => *value += 1, } } fn view(value: &u64) -> Column { column![ text(value), button("+").on_press(Message::Increment), ] } ``` -------------------------------- ### Pick List Example Source: https://docs.iced.rs/src/iced_widget/helpers.rs.html Demonstrates how to create and use a pick list widget. This snippet shows the setup for state, message handling, and the view function, including defining the selectable options and a placeholder. ```rust # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; } # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>; use iced::widget::pick_list; struct State { favorite: Option, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum Fruit { Apple, Orange, Strawberry, Tomato, } #[derive(Debug, Clone)] enum Message { FruitSelected(Fruit), } fn view(state: &State) -> Element<'_, Message> { let fruits = [ Fruit::Apple, Fruit::Orange, Fruit::Strawberry, Fruit::Tomato, ]; pick_list( state.favorite, fruits, Fruit::to_string, ) .on_select(Message::FruitSelected) .placeholder("Select your favorite fruit...") .into() } fn update(state: &mut State, message: Message) { match message { Message::FruitSelected(fruit) => { state.favorite = Some(fruit); } } } impl std::fmt::Display for Fruit { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { Self::Apple => "Apple", Self::Orange => "Orange", Self::Strawberry => "Strawberry", Self::Tomato => "Tomato", }) } } ``` -------------------------------- ### Get Start Point of Arc Source: https://docs.iced.rs/iced/widget/canvas/path/lyon_path/geom/arc/struct.Arc.html?search= Retrieves the starting point of the curve. No specific setup is required beyond having an Arc instance. ```rust fn from(&self) -> Point2D ``` -------------------------------- ### setup Source: https://docs.iced.rs/iced/advanced/text/type.Fragment.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the setup information sent by the X11 server. ```APIDOC ## setup ### Description Get the setup information sent by the X11 server. ### Method `setup` ### Returns - `&Setup` - A reference to the X11 server setup information. ``` -------------------------------- ### Initialize Winit Window and Iced Application Source: https://docs.iced.rs/src/iced_winit/lib.rs.html Sets up a new window, initializes the Iced compositor, and builds the initial user interface. This is typically done when a new window is opened. ```rust let _ = user_interfaces.insert( id, build_user_interface( &program, user_interface::Cache::default(), &mut window.renderer, logical_size, id, ), ); let _ = ui_caches.insert(id, user_interface::Cache::default()); if make_visible { window.raw.set_visible(true); } events.push(( id, core::Event::Window(window::Event::Opened { position: window.position(), size: window.state.logical_size(), scale_factor: window.raw.scale_factor() as f32, }), )); let _ = on_open.send(id); is_window_opening = false; ``` -------------------------------- ### DevTools Setup Enum Source: https://docs.iced.rs/src/iced_devtools/lib.rs.html?search= Represents the state of a setup or installation process. ```APIDOC ## Enum: Setup ### Description Represents the different stages within a setup or installation process managed by the devtools. ### Variants - **Idle { goal: Goal }**: The setup is idle, waiting to start, with a specified `Goal`. - **Running { logs: Vec }**: The setup process is currently running, and a list of logs is being collected. ``` -------------------------------- ### Example: Building a User Interface in an Application Loop Source: https://docs.iced.rs/src/iced_runtime/user_interface.rs.html?search=u32+-%3E+bool Demonstrates how to integrate `UserInterface::build` into a headless application loop, including initialization of necessary components like cache, renderer, and window. ```rust # mod iced_wgpu { # pub type Renderer = (); # } # # pub struct Counter; # # impl Counter { # pub fn new() -> Self { Counter } # pub fn view(&self) -> iced_core::Element<(), (), Renderer> { unimplemented!() } # pub fn update(&mut self, _: ()) {} # } use iced_runtime::core::shell; use iced_runtime::core::window; use iced_runtime::core::Size; use iced_runtime::user_interface::{self, UserInterface}; use iced_wgpu::Renderer; // Initialization let mut counter = Counter::new(); let mut cache = user_interface::Cache::new(); let mut renderer = Renderer::default(); let mut window = window::Headless; // This should be a proper window, like a `winit` one let mut waker = shell::Waker::noop(); 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(); } ``` -------------------------------- ### Get Setup Information Source: https://docs.iced.rs/iced/widget/rule/type.StyleFn.html?search=u32+-%3E+bool Retrieves the setup information provided by the X11 server. ```APIDOC ## setup ### Description Get the setup information sent by the X11 server. ### Response - **&Setup** - Returns a reference to the server setup information. ``` -------------------------------- ### Application Creation and Running Source: https://docs.iced.rs/src/iced/application.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to create an Application instance and run it. The `run` method handles initialization and integrates with debugging or testing features if enabled. ```APIDOC ## Application Creation and Running ### Description Creates an `Application` with the `application` helper and runs it. The `run` method initializes the application, potentially integrating with debugging or testing tools based on feature flags. ### Method `run()` ### Endpoint N/A (This is a library function, not an API endpoint) ### Parameters None ### Request Example ```rust // Assuming 'MyProgram' implements the 'Program' trait let application = Application::new(MyProgram::new()); application.run()?; ``` ### Response #### Success Response (0) Indicates the application ran successfully without errors. #### Response Example N/A (Success is indicated by the absence of an error) ``` -------------------------------- ### Application Creation and Running Source: https://docs.iced.rs/src/iced/application.rs.html?search=u32+-%3E+bool Demonstrates how to create an Application instance and run it. The `run` method handles initialization and integrates with debugging or testing features if enabled. ```APIDOC ## Application Creation and Running ### Description Creates an `Application` with the `application` helper and runs it. The `run` method initializes the application, potentially integrating with debugging or testing tools based on feature flags. ### Method `run()` ### Endpoint N/A (This is a library function, not an API endpoint) ### Parameters None ### Request Example ```rust // Assuming 'MyProgram' implements the 'Program' trait let application = Application::new(MyProgram::new()); application.run()?; ``` ### Response #### Success Response (0) Indicates successful execution without returning a specific value, but rather running the application shell. #### Response Example N/A ``` -------------------------------- ### Get Layer Start Level Source: https://docs.iced.rs/iced_wgpu/layer/struct.Layer.html Returns the starting level index for elements within the Layer. ```rust fn start(&self) -> usize ``` -------------------------------- ### Get Start Point of Arc Source: https://docs.iced.rs/iced/widget/canvas/path/lyon_path/geom/arc/struct.Arc.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the starting point of the arc. Requires `S` to implement `Scalar`. ```rust pub fn from(&self) -> Point2D ``` -------------------------------- ### Create a PickList widget Source: https://docs.iced.rs/src/iced_widget/pick_list.rs.html This example demonstrates how to create and configure a PickList widget. It shows how to provide the list of options, a function to convert options to strings, and how to handle selection events. The placeholder text and the `on_select` callback are also configured. ```rust # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; } # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>; # use iced::widget::pick_list; struct State { favorite: Option, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum Fruit { Apple, Orange, Strawberry, Tomato, } #[derive(Debug, Clone)] enum Message { FruitSelected(Fruit), } fn view(state: &State) -> Element<'_, Message> { let fruits = [ Fruit::Apple, Fruit::Orange, Fruit::Strawberry, Fruit::Tomato, ]; pick_list( state.favorite, fruits, Fruit::to_string, ) .on_select(Message::FruitSelected) .placeholder("Select your favorite fruit...") .into() } fn update(state: &mut State, message: Message) { match message { Message::FruitSelected(fruit) => { state.favorite = Some(fruit); } } } impl std::fmt::Display for Fruit { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { Self::Apple => "Apple", Self::Orange => "Orange", Self::Strawberry => "Strawberry", Self::Tomato => "Tomato", }) } } ``` -------------------------------- ### Get Arc Start and End Points Source: https://docs.iced.rs/iced/widget/canvas/path/lyon_path/geom/arc/struct.Arc.html?search=std%3A%3Avec Retrieves the starting and ending points of the arc segment. ```rust pub fn from(&self) -> Point2D ``` ```rust pub fn to(&self) -> Point2D ``` -------------------------------- ### Example: Creating a UiKitWindowHandle Source: https://docs.iced.rs/iced/window/raw_window_handle/struct.UiKitWindowHandle.html?search=std%3A%3Avec Shows how to create a new `UiKitWindowHandle` instance using a pointer to a `UIView`. It also demonstrates how to optionally set the `ui_view_controller` field. ```rust let view: &UIView; let mut handle = UiKitWindowHandle::new(NonNull::from(view).cast()); // Optionally set the view controller. handle.ui_view_controller = None; ``` -------------------------------- ### Basic Iced Application Setup Source: https://docs.iced.rs/iced/fn.run.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E This snippet demonstrates how to set up and run a basic Iced application using the `iced::run` function. It includes the necessary `main` function, message enum, update logic, and view composition. ```rust use iced::widget::{button, column, text, Column}; pub fn main() -> iced::Result { iced::run(update, view) } #[derive(Debug, Clone)] enum Message { Increment, } fn update(value: &mut u64, message: Message) { match message { Message::Increment => *value += 1, } } fn view(value: &u64) -> Column { column![ text(value), button("+").on_press(Message::Increment), ] } ``` -------------------------------- ### Get Start Index of Text Input Source: https://docs.iced.rs/src/iced_widget/text_input/cursor.rs.html Calculates the starting index for text input operations, considering the current state (index or selection start). Ensures the index does not exceed the text length. ```rust pub(crate) fn start(&self, value: &Value) -> usize { let start = match self.state { State::Index(index) => index, State::Selection { start, .. } => start, }; start.min(value.len()) } ``` -------------------------------- ### Cancel Setup Process Source: https://docs.iced.rs/src/iced_devtools/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Handles the 'CancelSetup' message by setting the application mode to 'Hidden'. This effectively aborts any ongoing setup or installation process. ```rust Message::CancelSetup => { self.mode = Mode::Hidden; Task::none() } ``` -------------------------------- ### into_boot(self) -> (State, Task) Source: https://docs.iced.rs/iced/widget/canvas/path/lyon_path/geom/euclid/struct.Size2D.html?search=u32+-%3E+bool Turns some type into the initial state of some `Application`. ```APIDOC ## fn into_boot(self) -> (State, Task) ### Description Turns some type into the initial state of some `Application`. ### Parameters #### Path Parameters - **self** (Self) - Required - The type to convert into an initial application state. ``` -------------------------------- ### iced_wgpu::window::compositor::new Source: https://docs.iced.rs/iced_wgpu/window/compositor/fn.new.html?search= Creates a `Compositor` with the given `Settings` and window. ```APIDOC ## new ### Description Creates a `Compositor` with the given `Settings` and window. ### Function Signature ```rust pub async fn new( settings: Settings, display: impl Display, compatible_window: impl Window, shell: Shell, ) -> Result ``` ### Parameters * `settings`: `Settings` - The settings for the compositor. * `display`: `impl Display` - The display to use. * `compatible_window`: `impl Window` - The window to use. * `shell`: `Shell` - The shell for the compositor. ### Returns * `Result` - A `Result` containing the created `Compositor` or an `Error`. ``` -------------------------------- ### DevTools Goal Enum Source: https://docs.iced.rs/src/iced_devtools/lib.rs.html?search= Defines the objective of a setup or installation process. ```APIDOC ## Enum: Goal ### Description Specifies the target objective for a setup or installation process. ### Variants - **Installation**: The goal is to perform a fresh installation. - **Update { revision: Option }**: The goal is to update an existing installation, optionally specifying a target `revision`. ``` -------------------------------- ### iced_wgpu::window::compositor::new Source: https://docs.iced.rs/iced_wgpu/window/compositor/fn.new.html?search=std%3A%3Avec Creates a `Compositor` with the given `Settings` and window. ```APIDOC ## new ### Description Creates a `Compositor` with the given `Settings` and window. ### Signature `pub async fn new( settings: Settings, display: impl Display, compatible_window: impl Window, shell: Shell, ) -> Result` ### Parameters * `settings`: `Settings` - Configuration settings for the compositor. * `display`: `impl Display` - The display to use for the compositor. * `compatible_window`: `impl Window` - The window to associate with the compositor. * `shell`: `Shell` - The shell to use for window management. ### Returns * `Result` - Ok containing the created `Compositor` on success, or an `Error` on failure. ``` -------------------------------- ### Iced Devtools Setup UI Source: https://docs.iced.rs/src/iced_devtools/lib.rs.html?search=u32+-%3E+bool Generates the UI elements for the setup phase of the Iced Devtools, including buttons for installation or update and instructions for the cargo command. ```rust fn setup(goal: &Goal) -> Element<'_, Message, Theme, Renderer> where Renderer: program::Renderer + 'static, { let controls = row![ button(text("Cancel").center().width(Fill)) .width(100) .on_press(Message::CancelSetup) .style(button::danger), space::horizontal(), button( text(match goal { Goal::Installation => "Install", Goal::Update { .. } => "Update", }) .center() .width(Fill) ) .width(100) .on_press(Message::InstallComet) .style(button::success), ]; let command = container( text!( "cargo install --locked \\ --git https://github.com/iced-rs/comet.git \\ --rev {}", comet::COMPATIBLE_REVISION ) .size(14) .font(Font::MONOSPACE), ) .width(Fill) .padding(5) .style(container::dark); Element::from(match goal { Goal::Installation => column![ text("comet is not installed!").size(20), "In order to display performance " ], }) } ``` -------------------------------- ### Get string length in bytes Source: https://docs.iced.rs/iced/widget/canvas/path/lyon_path/geom/arrayvec/struct.ArrayString.html?search= Examples of using the `len()` method to get the byte length of a string slice. Note that this is the byte length, not the character count. ```Rust let len = "foo".len(); assert_eq!(3, len); assert_eq!("ƒoo".len(), 4); // fancy f! assert_eq!("ƒoo".chars().count(), 3); ``` -------------------------------- ### Get Cursor Selection Source: https://docs.iced.rs/iced/widget/text_input/cursor/struct.Cursor.html?search= Determines the start and end indices of the current text selection made by the cursor. The start index is guaranteed to be less than or equal to the end index. ```rust pub fn selection(&self, value: &Value) -> Option<(usize, usize)> ``` -------------------------------- ### run Source: https://docs.iced.rs/src/iced_winit/lib.rs.html?search= Runs an Iced `Program` with the provided settings, setting up the winit window and the Iced runtime. ```APIDOC ## run ### Description Runs a [`Program`] with the provided settings. This function initializes the winit event loop, sets up the backend and renderer, and starts the Iced runtime. ### Function Signature ```rust pub fn run

(program: P) -> Result<(), Error> where P: Program + 'static, P::Theme: theme::Base, ``` ### Parameters - **program** (`P`): An instance of a type that implements the `Program` trait. This is the main entry point for your Iced application logic. ### Returns - `Result<(), Error>`: Returns `Ok(())` if the program runs successfully, or an `Err(Error)` if any issue occurs during initialization or execution. ``` -------------------------------- ### Engine::new Source: https://docs.iced.rs/src/iced_wgpu/engine.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes a new Engine instance with the provided wgpu device, queue, and configuration. ```APIDOC ## Engine::new ### Description Creates a new instance of the Engine, initializing the necessary wgpu pipelines for rendering. ### Parameters - **adapter** (wgpu::Adapter) - Required - The wgpu adapter used for backend information. - **device** (wgpu::Device) - Required - The wgpu device. - **queue** (wgpu::Queue) - Required - The wgpu queue. - **format** (wgpu::TextureFormat) - Required - The texture format for the swapchain. - **antialiasing** (Option) - Required - Optional antialiasing configuration. - **shell** (Shell) - Required - The shell instance. ### Response - **Engine** (Self) - The initialized engine instance. ``` -------------------------------- ### Get X11 Server Setup Information Source: https://docs.iced.rs/iced/overlay/menu/type.StyleFn.html?search=std%3A%3Avec Retrieves the setup information provided by the X11 server upon connection. This contains details about the server's capabilities and configuration. ```rust fn setup(&self) -> &Setup ``` -------------------------------- ### Compositor::new Source: https://docs.iced.rs/src/iced_wgpu/window/compositor.rs.html?search=std%3A%3Avec Creates a new `Compositor` instance with the provided settings, display, window, and shell. This is the primary way to initialize the WGPU compositor for rendering. ```APIDOC ## Compositor::new ### Description Creates a new [`Compositor`] with the given [`Settings`] and window. ### Signature ```rust pub async fn new( settings: Settings, display: impl compositor::Display, compatible_window: impl compositor::Window, shell: Shell, ) -> Result ``` ### Parameters * `settings`: [`Settings`] - Configuration for the compositor. * `display`: `impl compositor::Display` - The display backend. * `compatible_window`: `impl compositor::Window` - The window to associate with the compositor. * `shell`: `Shell` - The shell environment. ### Returns * `Result` - Ok containing the new `Compositor` on success, or an `Error` on failure. ``` -------------------------------- ### GET /setup Source: https://docs.iced.rs/iced/widget/slider/type.StyleFn.html Retrieves the setup information provided by the X11 server upon connection. ```APIDOC ## GET /setup ### Description Get the setup information sent by the X11 server. ### Method GET ### Endpoint /setup ### Response #### Success Response (200) - **&Setup** - Returns the server setup configuration. ``` -------------------------------- ### Basic Radio Button Example Source: https://docs.iced.rs/src/iced_widget/radio.rs.html?search= Demonstrates how to create and use radio buttons for user selection. This example shows the setup for state management and message handling when a radio button is chosen. ```rust # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; } # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>; use iced::widget::{column, radio}; struct State { selection: Option, } #[derive(Debug, Clone, Copy)] enum Message { RadioSelected(Choice), } #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum Choice { A, B, C, All, } fn view(state: &State) -> Element<'_, Message> { let a = radio( "A", Choice::A, state.selection, Message::RadioSelected, ); let b = radio( "B", Choice::B, state.selection, Message::RadioSelected, ); let c = radio( "C", Choice::C, state.selection, Message::RadioSelected, ); let all = radio( "All of the above", Choice::All, state.selection, Message::RadioSelected ); column![a, b, c, all].into() } ``` -------------------------------- ### fn into_boot(self) -> (State, Task) Source: https://docs.iced.rs/iced/advanced/svg/struct.Handle.html?search=std%3A%3Avec Turns the current state into the initial state of an `Application`, along with an associated `Task`. ```APIDOC ## fn into_boot(self) -> (State, Task) ### Description Turns some type into the initial state of some `Application`. ### Method Application initialization ### Parameters None ### Response A tuple containing the initial `State` and a `Task`. ``` -------------------------------- ### SystemTime Example Usage Source: https://docs.iced.rs/iced_core/time/struct.SystemTime.html Demonstrates how to get the current SystemTime and calculate the elapsed time after a sleep. ```APIDOC ### Example ```rust use std::time::{Duration, SystemTime}; use std::thread::sleep; fn main() { let now = SystemTime::now(); // we sleep for 2 seconds sleep(Duration::new(2, 0)); match now.elapsed() { Ok(elapsed) => { // it prints '2' println!("{}", elapsed.as_secs()); } Err(e) => { // the system clock went backwards! println!("Great Scott! {e:?}"); } } } ``` ``` -------------------------------- ### into_boot Method Source: https://docs.iced.rs/iced/advanced/clipboard/enum.Error.html Turns the state into the initial state of an `Application`, along with a `Task` for initial messages. ```rust fn into_boot(self) -> (State, Task) ``` -------------------------------- ### Compositor::new Source: https://docs.iced.rs/src/iced_wgpu/window/compositor.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new `Compositor` instance with the specified settings, display, window, and shell. This is the primary way to initialize the wgpu compositor for rendering. ```APIDOC ## new ### Description Creates a new `Compositor` instance with the specified settings, display, window, and shell. ### Method `async fn new( settings: Settings, display: impl compositor::Display, compatible_window: impl compositor::Window, shell: Shell, ) -> Result` ### Parameters * `settings` (Settings) - The rendering settings for the compositor. * `display` (impl compositor::Display) - The display backend to use. * `compatible_window` (impl compositor::Window) - The window to associate with the compositor. * `shell` (Shell) - The shell environment for the compositor. ``` -------------------------------- ### Scale::clamp Example Source: https://docs.iced.rs/iced_renderer/geometry/path/lyon_path/geom/euclid/default/type.Scale.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Clamps a `Scale` instance between a start and end scale. Requires `T` to implement `Copy`. ```rust pub fn clamp( self, start: Scale, end: Scale, ) -> Scale where T: Copy, ``` -------------------------------- ### Getting the current stream position Source: https://docs.iced.rs/iced_widget/text_input/type.StyleFn.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the current position within the stream, measured in bytes from the start. ```rust fn stream_position(&mut self) -> Result ``` -------------------------------- ### Run Server Source: https://docs.iced.rs/src/iced_beacon/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Starts the Iced Beacon server and returns a stream of events. ```APIDOC ## POST /run ### Description Starts the Iced Beacon server. It listens for incoming TCP connections and processes messages, emitting events. ### Method POST ### Endpoint /run ### Response #### Success Response (200) - **stream** (Stream) - A stream of events from the server. #### Response Example (This endpoint returns a stream, not a single JSON response. Events are streamed as they occur.) Example event: ```json { "type": "Connected", "at": "2023-10-27T10:00:00Z", "connection": { ... }, "name": "MyClient", "version": "1.0.0", "theme": null, "can_time_travel": true } ``` ``` -------------------------------- ### Basic Slider Example Source: https://docs.iced.rs/src/iced_widget/slider.rs.html?search=std%3A%3Avec This example demonstrates how to create a basic slider with a defined range and handle value changes. It shows the typical setup for a slider within an Iced application's view and update logic. ```rust # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; } # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>; # use iced::widget::slider; struct State { value: f32, } #[derive(Debug, Clone)] enum Message { ValueChanged(f32), } fn view(state: &State) -> Element<'_, Message> { slider(0.0..=100.0, state.value, Message::ValueChanged).into() } fn update(state: &mut State, message: Message) { match message { Message::ValueChanged(value) => { state.value = value; } } } ``` -------------------------------- ### window::compositor::new Source: https://docs.iced.rs/iced_tiny_skia/all.html?search=u32+-%3E+bool Initializes a new window compositor instance. ```APIDOC ## [FUNCTION] window::compositor::new ### Description Initializes a new window compositor instance for the iced application. ### Method Function ### Endpoint window::compositor::new ``` -------------------------------- ### Example Usage Source: https://docs.iced.rs/iced/fn.application.html?search= Demonstrates how to use the `application` function to create a simple counter application. ```APIDOC ## Example Usage ### Description This example shows a basic counter application using the `iced::application` function. ### Code ```rust use iced::widget::{button, column, text, Column}; pub fn main() -> iced::Result { iced::application(u64::default, update, view).run() } #[derive(Debug, Clone)] enum Message { Increment, } fn update(value: &mut u64, message: Message) { match message { Message::Increment => *value += 1, } } fn view(value: &u64) -> Column { column![ text(value), button("+").on_press(Message::Increment), ] } ``` ``` -------------------------------- ### Get the current selection Source: https://docs.iced.rs/src/iced_graphics/text/editor.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the current selection state of the editor. This includes the start and end positions of the selection. ```rust pub fn selection(&self) -> editor::Selection { let internal = self.internal(); if let Ok(Some(cursor)) = internal.selection.read().as_deref() { return cursor.clone(); } let cursor = internal.editor.cursor(); let buffer = buffer_from_editor(&internal.editor); let cursor = match internal.editor.selection_bounds() { Some((start, end)) => { let line_height = buffer.metrics().line_height; let selected_lines = end.line - start.line + 1; let visual_lines_offset = visual_lines_offset(start.line, buffer); let regions = buffer .lines ``` -------------------------------- ### SystemTime Example Usage Source: https://docs.iced.rs/iced_core/time/struct.SystemTime.html?search=u32+-%3E+bool Demonstrates how to get the current system time, sleep for a duration, and calculate the elapsed time. ```APIDOC ### Example ```rust use std::time::{Duration, SystemTime}; use std::thread::sleep; fn main() { let now = SystemTime::now(); // we sleep for 2 seconds sleep(Duration::new(2, 0)); match now.elapsed() { Ok(elapsed) => { // it prints '2' println!("{}", elapsed.as_secs()); } Err(e) => { // the system clock went backwards! println!("Great Scott! {:?}", e); } } } ``` ``` -------------------------------- ### UiKitWindowHandle::new Example Source: https://docs.iced.rs/iced/window/raw_window_handle/struct.UiKitWindowHandle.html Shows how to create a new `UiKitWindowHandle` with a given `UIView` pointer. It also demonstrates how to optionally set the `ui_view_controller` field. ```rust let view: &UIView; let mut handle = UiKitWindowHandle::new(NonNull::from(view).cast()); // Optionally set the view controller. handle.ui_view_controller = None; ``` -------------------------------- ### Get Stream Position Source: https://docs.iced.rs/iced/advanced/widget/text/type.StyleFn.html?search=u32+-%3E+bool Returns the current position within the stream, measured from the start. This is part of the `Seek` trait. ```rust fn stream_position(&mut self) -> Result ``` -------------------------------- ### Implement a PickList widget Source: https://docs.iced.rs/src/iced_widget/pick_list.rs.html?search=std%3A%3Avec Demonstrates the basic setup of a PickList, including state management, message handling, and the required Display implementation for the selectable items. ```rust # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; } # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>; # use iced::widget::pick_list; struct State { favorite: Option, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum Fruit { Apple, Orange, Strawberry, Tomato, } #[derive(Debug, Clone)] enum Message { FruitSelected(Fruit), } fn view(state: &State) -> Element<'_, Message> { let fruits = [ Fruit::Apple, Fruit::Orange, Fruit::Strawberry, Fruit::Tomato, ]; pick_list( state.favorite, fruits, Fruit::to_string, ) .on_select(Message::FruitSelected) .placeholder("Select your favorite fruit...") .into() } fn update(state: &mut State, message: Message) { match message { Message::FruitSelected(fruit) => { state.favorite = Some(fruit); } } } impl std::fmt::Display for Fruit { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { Self::Apple => "Apple", Self::Orange => "Orange", Self::Strawberry => "Strawberry", Self::Tomato => "Tomato", }) } } ``` ```rust # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; } # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>; # use iced::widget::pick_list; struct State { favorite: Option, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum Fruit { Apple, Orange, Strawberry, Tomato, } #[derive(Debug, Clone)] enum Message { FruitSelected(Fruit), } fn view(state: &State) -> Element<'_, Message> { let fruits = [ Fruit::Apple, Fruit::Orange, Fruit::Strawberry, Fruit::Tomato, ]; pick_list( state.favorite, fruits, Fruit::to_string, ) .on_select(Message::FruitSelected) .placeholder("Select your favorite fruit...") .into() } fn update(state: &mut State, message: Message) { match message { Message::FruitSelected(fruit) => { state.favorite = Some(fruit); } } } impl std::fmt::Display for Fruit { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { Self::Apple => "Apple", Self::Orange => "Orange", Self::Strawberry => "Strawberry", Self::Tomato => "Tomato", }) } } ``` -------------------------------- ### PickList Creation and Configuration Source: https://docs.iced.rs/iced/widget/pick_list/struct.PickList.html?search=std%3A%3Avec Demonstrates how to create a PickList widget with initial selection, options, and a string conversion function. It also shows how to customize its appearance and behavior using various methods. ```APIDOC ## PickList ### Description A widget for selecting a single value from a list of options. ### Creating a PickList Use the `pick_list` function or the `PickList::new` constructor to create a new PickList. ```rust // Using the convenience function pick_list(selected_option, options, to_string_fn) // Using the struct constructor PickList::new(selected_option, options, to_string_fn) ``` - **`selected`**: `Option` - The currently selected value. - **`options`**: `L` where `L: Borrow<[T]>` - A collection of available options. - **`to_string`**: `impl Fn(&T) -> String + 'a` - A function to convert an option to its string representation. ### Customization Methods These methods can be chained to customize the appearance and behavior of the PickList: - **`placeholder(placeholder: impl Into)`**: Sets the placeholder text displayed when no option is selected. - **`width(width: impl Into)`**: Sets the width of the PickList. - **`menu_height(menu_height: impl Into)`**: Sets the height of the dropdown menu. - **`padding

(padding: P)`**: Sets the padding of the PickList. - **`text_size(size: impl Into)`**: Sets the size of the text. - **`line_height(line_height: impl Into)`**: Sets the line height of the text. - **`shaping(shaping: Shaping)`**: Sets the text shaping strategy. - **`ellipsis(ellipsis: Ellipsis)`**: Sets the text ellipsis strategy. - **`font(font: impl Into<::Font>)`**: Sets the font for the PickList. - **`handle(handle: Handle<::Font>)`**: Sets the handle icon for the PickList. - **`style(style: impl Fn(&Theme, Status) -> Style + 'a)`**: Sets the custom style for the PickList. - **`menu_style(style: impl Fn(&Theme) -> Style + 'a)`**: Sets the custom style for the dropdown menu. - **`class(class: impl Into<::Class<'a>>)`**: Sets the style class (requires `advanced` feature). ### Event Handling - **`on_select(on_select: impl Fn(T) -> Message + 'a)`**: Sets the message to be produced when an option is selected. The closure receives the selected option of type `T`. - **`on_open(on_open: Message)`**: Sets the message to be produced when the PickList menu is opened. - **`on_close(on_close: Message)`**: Sets the message to be produced when the PickList menu is closed. ``` -------------------------------- ### Get Baseline of CubicBezierSegment Source: https://docs.iced.rs/iced/widget/canvas/path/lyon_path/geom/cubic_bezier/struct.CubicBezierSegment.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the `LineSegment` that forms the baseline of the cubic Bézier curve, connecting the start and end points. ```rust pub fn baseline(&self) -> LineSegment ``` -------------------------------- ### Initialize iced_wgpu Renderer Source: https://docs.iced.rs/src/iced_wgpu/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new `Renderer` instance with the provided `wgpu` engine and rendering settings. This is the entry point for setting up the renderer. ```rust pub fn new(engine: Engine, settings: renderer::Settings) -> Self { Self { settings, layers: layer::Stack::new(), scale_factor: None, quad: quad::State::new(), triangle: triangle::State::new(&engine.device, &engine.triangle_pipeline), text: text::State::new(), text_viewport: engine.text_pipeline.create_viewport(&engine.device), #[cfg(any(feature = "svg", feature = "image"))] image: image::State::new(), #[cfg(any(feature = "svg", feature = "image"))] image_cache: std::cell::RefCell::new(engine.create_image_cache()), // TODO: Resize belt smartly (?) // It would be great if the `StagingBelt` API exposed methods // for introspection to detect when a resize may be worth it. staging_belt: wgpu::util::StagingBelt::new( engine.device.clone(), buffer::MAX_WRITE_SIZE as u64, ), engine, } } ``` -------------------------------- ### Get CubicBezierSegment before split point Source: https://docs.iced.rs/iced/widget/canvas/path/lyon_path/geom/cubic_bezier/struct.CubicBezierSegment.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns a new `CubicBezierSegment` representing the portion of the curve from the start up to the specified split point `t`. ```rust pub fn before_split(&self, t: S) -> CubicBezierSegment ``` -------------------------------- ### Extract Subscription Recipes Source: https://docs.iced.rs/iced_futures/subscription/fn.into_recipes.html?search= Use this function to get the different recipes associated with a Subscription. No specific setup is required beyond having a Subscription instance. ```rust pub fn into_recipes( subscription: Subscription, ) -> Vec>> ``` -------------------------------- ### Initialize iced_wgpu Renderer Source: https://docs.iced.rs/src/iced_wgpu/lib.rs.html?search= Creates a new `Renderer` instance with the provided wgpu engine and rendering settings. This is the entry point for setting up the renderer. ```rust pub fn new(engine: Engine, settings: renderer::Settings) -> Self { Self { settings, layers: layer::Stack::new(), scale_factor: None, quad: quad::State::new(), triangle: triangle::State::new(&engine.device, &engine.triangle_pipeline), text: text::State::new(), text_viewport: engine.text_pipeline.create_viewport(&engine.device), #[cfg(any(feature = "svg", feature = "image"))] image: image::State::new(), #[cfg(any(feature = "svg", feature = "image"))] image_cache: std::cell::RefCell::new(engine.create_image_cache()), staging_belt: wgpu::util::StagingBelt::new( engine.device.clone(), buffer::MAX_WRITE_SIZE as u64, ), engine, } } ``` -------------------------------- ### Initialize WGPU Compositor with Settings Source: https://docs.iced.rs/src/iced_wgpu/window/compositor.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes the WGPU compositor, checking for graphics adapter compatibility and applying settings from environment variables if available. ```rust pub fn new( settings: impl Into, display: impl compositor::Display, compatible_window: impl compositor::Window, shell: Shell, ) -> Result { if settings.backend.hardware().is_none() && !settings.backend.matches("wgpu") { return Err(backend::Error::GraphicsAdapterNotFound { backend: "wgpu", reason: backend::Reason::DidNotMatch { preferred_backend: settings.backend, }, }); } let mut settings = Settings::from(settings); if let Some(backends) = wgpu::Backends::from_env() { settings.backends = backends; } if let Some(present_mode) = present_mode_from_env() { settings.present_mode = present_mode; } Ok(new(settings, display, compatible_window, shell).await?) } ``` -------------------------------- ### Length::FillPortion Example Source: https://docs.iced.rs/iced/enum.Length.html?search= Illustrates how FillPortion distributes space proportionally between elements. A higher value gets a larger share of the available space. ```rust Let’s say we have two elements: one with `FillPortion(2)` and one with `FillPortion(3)`. The first will get 2 portions of the available space, while the second one would get 3. `Length::Fill` is equivalent to `Length::FillPortion(1)`. ```