diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/component/src/main.rs | 2 | ||||
| -rw-r--r-- | examples/download_progress/src/download.rs | 17 | ||||
| -rw-r--r-- | examples/integration/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/integration/src/controls.rs | 9 | ||||
| -rw-r--r-- | examples/integration/src/main.rs | 14 | ||||
| -rw-r--r-- | examples/lazy/src/main.rs | 9 | ||||
| -rw-r--r-- | examples/modal/src/main.rs | 14 | ||||
| -rw-r--r-- | examples/qr_code/src/main.rs | 12 | ||||
| -rw-r--r-- | examples/scrollable/src/main.rs | 36 | ||||
| -rw-r--r-- | examples/styling/src/main.rs | 11 | ||||
| -rw-r--r-- | examples/toast/src/main.rs | 6 | ||||
| -rw-r--r-- | examples/todos/src/main.rs | 29 | ||||
| -rw-r--r-- | examples/tour/src/main.rs | 84 | ||||
| -rw-r--r-- | examples/websocket/src/echo.rs | 100 | ||||
| -rw-r--r-- | examples/websocket/src/main.rs | 9 | 
15 files changed, 201 insertions, 153 deletions
| diff --git a/examples/component/src/main.rs b/examples/component/src/main.rs index 09e5e4a2..010321a9 100644 --- a/examples/component/src/main.rs +++ b/examples/component/src/main.rs @@ -134,8 +134,8 @@ mod numeric_input {                          .map(u32::to_string)                          .as_deref()                          .unwrap_or(""), -                    Event::InputChanged,                  ) +                .on_input(Event::InputChanged)                  .padding(10),                  button("+", Event::IncrementPressed),              ] diff --git a/examples/download_progress/src/download.rs b/examples/download_progress/src/download.rs index 5ff951b3..3b11cb76 100644 --- a/examples/download_progress/src/download.rs +++ b/examples/download_progress/src/download.rs @@ -18,10 +18,7 @@ pub struct Download<I> {      url: String,  } -async fn download<I: Copy>( -    id: I, -    state: State, -) -> (Option<(I, Progress)>, State) { +async fn download<I: Copy>(id: I, state: State) -> ((I, Progress), State) {      match state {          State::Ready(url) => {              let response = reqwest::get(&url).await; @@ -30,7 +27,7 @@ async fn download<I: Copy>(                  Ok(response) => {                      if let Some(total) = response.content_length() {                          ( -                            Some((id, Progress::Started)), +                            (id, Progress::Started),                              State::Downloading {                                  response,                                  total, @@ -38,10 +35,10 @@ async fn download<I: Copy>(                              },                          )                      } else { -                        (Some((id, Progress::Errored)), State::Finished) +                        ((id, Progress::Errored), State::Finished)                      }                  } -                Err(_) => (Some((id, Progress::Errored)), State::Finished), +                Err(_) => ((id, Progress::Errored), State::Finished),              }          }          State::Downloading { @@ -55,7 +52,7 @@ async fn download<I: Copy>(                  let percentage = (downloaded as f32 / total as f32) * 100.0;                  ( -                    Some((id, Progress::Advanced(percentage))), +                    (id, Progress::Advanced(percentage)),                      State::Downloading {                          response,                          total, @@ -63,8 +60,8 @@ async fn download<I: Copy>(                      },                  )              } -            Ok(None) => (Some((id, Progress::Finished)), State::Finished), -            Err(_) => (Some((id, Progress::Errored)), State::Finished), +            Ok(None) => ((id, Progress::Finished), State::Finished), +            Err(_) => ((id, Progress::Errored), State::Finished),          },          State::Finished => {              // We do not let the stream die, as it would start a diff --git a/examples/integration/Cargo.toml b/examples/integration/Cargo.toml index f6863cd3..2ab5d75f 100644 --- a/examples/integration/Cargo.toml +++ b/examples/integration/Cargo.toml @@ -10,7 +10,7 @@ iced_winit = { path = "../../winit" }  iced_wgpu = { path = "../../wgpu" }  iced_widget = { path = "../../widget" }  iced_renderer = { path = "../../renderer", features = ["wgpu", "tiny-skia"] } -env_logger = "0.8" +env_logger = "0.10"  [target.'cfg(target_arch = "wasm32")'.dependencies]  console_error_panic_hook = "0.1.7" diff --git a/examples/integration/src/controls.rs b/examples/integration/src/controls.rs index 5849f730..14e53ede 100644 --- a/examples/integration/src/controls.rs +++ b/examples/integration/src/controls.rs @@ -102,11 +102,10 @@ impl Program for Controls {                                      .size(14)                                      .style(Color::WHITE),                              ) -                            .push(text_input( -                                "Placeholder", -                                text, -                                Message::TextChanged, -                            )), +                            .push( +                                text_input("Placeholder", text) +                                    .on_input(Message::TextChanged), +                            ),                      ),              )              .into() diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index 949a726a..98d2bc59 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -30,6 +30,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {      #[cfg(target_arch = "wasm32")]      let canvas_element = {          console_log::init_with_level(log::Level::Debug)?; +          std::panic::set_hook(Box::new(console_error_panic_hook::hook));          web_sys::window() @@ -49,7 +50,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {          .build(&event_loop)?;      #[cfg(not(target_arch = "wasm32"))] -    let window = winit::window::Window::new(&event_loop).unwrap(); +    let window = winit::window::Window::new(&event_loop)?;      let physical_size = window.inner_size();      let mut viewport = Viewport::with_physical_size( @@ -61,7 +62,6 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {      let mut clipboard = Clipboard::connect(&window);      // Initialize wgpu -      #[cfg(target_arch = "wasm32")]      let default_backend = wgpu::Backends::GL;      #[cfg(not(target_arch = "wasm32"))] @@ -95,12 +95,16 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {              #[cfg(not(target_arch = "wasm32"))]              let needed_limits = wgpu::Limits::default(); +            let capabilities = surface.get_capabilities(&adapter); +              ( -                surface -                    .get_capabilities(&adapter) +                capabilities                      .formats -                    .first() +                    .iter() +                    .filter(|format| format.describe().srgb)                      .copied() +                    .next() +                    .or_else(|| capabilities.formats.first().copied())                      .expect("Get preferred format"),                  adapter                      .request_device( diff --git a/examples/lazy/src/main.rs b/examples/lazy/src/main.rs index e1cdaefe..c6baa6a1 100644 --- a/examples/lazy/src/main.rs +++ b/examples/lazy/src/main.rs @@ -213,12 +213,9 @@ impl Sandbox for App {          column![              scrollable(options).height(Length::Fill),              row![ -                text_input( -                    "Add a new option", -                    &self.input, -                    Message::InputChanged, -                ) -                .on_submit(Message::AddItem(self.input.clone())), +                text_input("Add a new option", &self.input) +                    .on_input(Message::InputChanged) +                    .on_submit(Message::AddItem(self.input.clone())),                  button(text(format!("Toggle Order ({})", self.order)))                      .on_press(Message::ToggleOrder)              ] diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs index 214ec97e..f48afb69 100644 --- a/examples/modal/src/main.rs +++ b/examples/modal/src/main.rs @@ -133,18 +133,16 @@ impl Application for App {                      column![                          column![                              text("Email").size(12), -                            text_input( -                                "abc@123.com", -                                &self.email, -                                Message::Email -                            ) -                            .on_submit(Message::Submit) -                            .padding(5), +                            text_input("abc@123.com", &self.email,) +                                .on_input(Message::Email) +                                .on_submit(Message::Submit) +                                .padding(5),                          ]                          .spacing(5),                          column![                              text("Password").size(12), -                            text_input("", &self.password, Message::Password) +                            text_input("", &self.password) +                                .on_input(Message::Password)                                  .on_submit(Message::Submit)                                  .password()                                  .padding(5), diff --git a/examples/qr_code/src/main.rs b/examples/qr_code/src/main.rs index d8041745..867ebfa4 100644 --- a/examples/qr_code/src/main.rs +++ b/examples/qr_code/src/main.rs @@ -49,13 +49,11 @@ impl Sandbox for QRGenerator {              .size(70)              .style(Color::from([0.5, 0.5, 0.5])); -        let input = text_input( -            "Type the data of your QR code here...", -            &self.data, -            Message::DataChanged, -        ) -        .size(30) -        .padding(15); +        let input = +            text_input("Type the data of your QR code here...", &self.data) +                .on_input(Message::DataChanged) +                .size(30) +                .padding(15);          let mut content = column![title, input]              .width(700) diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index a3ade54f..2e99b1ac 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -338,22 +338,36 @@ impl scrollable::StyleSheet for ScrollbarCustomStyle {          style.active(&theme::Scrollable::Default)      } -    fn hovered(&self, style: &Self::Style) -> Scrollbar { -        style.hovered(&theme::Scrollable::Default) +    fn hovered( +        &self, +        style: &Self::Style, +        is_mouse_over_scrollbar: bool, +    ) -> Scrollbar { +        style.hovered(&theme::Scrollable::Default, is_mouse_over_scrollbar)      } -    fn hovered_horizontal(&self, style: &Self::Style) -> Scrollbar { -        Scrollbar { -            background: style.active(&theme::Scrollable::default()).background, -            border_radius: 0.0, -            border_width: 0.0, -            border_color: Default::default(), -            scroller: Scroller { -                color: Color::from_rgb8(250, 85, 134), +    fn hovered_horizontal( +        &self, +        style: &Self::Style, +        is_mouse_over_scrollbar: bool, +    ) -> Scrollbar { +        if is_mouse_over_scrollbar { +            Scrollbar { +                background: style +                    .active(&theme::Scrollable::default()) +                    .background,                  border_radius: 0.0,                  border_width: 0.0,                  border_color: Default::default(), -            }, +                scroller: Scroller { +                    color: Color::from_rgb8(250, 85, 134), +                    border_radius: 0.0, +                    border_width: 0.0, +                    border_color: Default::default(), +                }, +            } +        } else { +            self.active(style)          }      }  } diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 448c9792..e2015bac 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -90,13 +90,10 @@ impl Sandbox for Styling {                      },                  ); -        let text_input = text_input( -            "Type something...", -            &self.input_value, -            Message::InputChanged, -        ) -        .padding(10) -        .size(20); +        let text_input = text_input("Type something...", &self.input_value) +            .on_input(Message::InputChanged) +            .padding(10) +            .size(20);          let button = button("Submit")              .padding(10) diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs index 78fb9de1..9d859258 100644 --- a/examples/toast/src/main.rs +++ b/examples/toast/src/main.rs @@ -119,13 +119,15 @@ impl Application for App {              column![                  subtitle(                      "Title", -                    text_input("", &self.editing.title, Message::Title) +                    text_input("", &self.editing.title) +                        .on_input(Message::Title)                          .on_submit(Message::Add)                          .into()                  ),                  subtitle(                      "Message", -                    text_input("", &self.editing.body, Message::Body) +                    text_input("", &self.editing.body) +                        .on_input(Message::Body)                          .on_submit(Message::Add)                          .into()                  ), diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index ed3684d3..8bc7be09 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -210,15 +210,12 @@ impl Application for Todos {                      .style(Color::from([0.5, 0.5, 0.5]))                      .horizontal_alignment(alignment::Horizontal::Center); -                let input = text_input( -                    "What needs to be done?", -                    input_value, -                    Message::InputChanged, -                ) -                .id(INPUT_ID.clone()) -                .padding(15) -                .size(30) -                .on_submit(Message::CreateTask); +                let input = text_input("What needs to be done?", input_value) +                    .id(INPUT_ID.clone()) +                    .on_input(Message::InputChanged) +                    .on_submit(Message::CreateTask) +                    .padding(15) +                    .size(30);                  let controls = view_controls(tasks, *filter);                  let filtered_tasks = @@ -381,14 +378,12 @@ impl Task {                  .into()              }              TaskState::Editing => { -                let text_input = text_input( -                    "Describe your task...", -                    &self.description, -                    TaskMessage::DescriptionEdited, -                ) -                .id(Self::text_input_id(i)) -                .on_submit(TaskMessage::FinishEdition) -                .padding(10); +                let text_input = +                    text_input("Describe your task...", &self.description) +                        .id(Self::text_input_id(i)) +                        .on_input(TaskMessage::DescriptionEdited) +                        .on_submit(TaskMessage::FinishEdition) +                        .padding(10);                  row