Merge branch 'master' into beacon

This commit is contained in:
Héctor Ramón Jiménez 2024-05-09 12:32:25 +02:00
commit aaf396256e
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
284 changed files with 18747 additions and 15450 deletions

View file

@ -112,6 +112,12 @@ impl<T> Command<T> {
}
}
impl<Message> From<()> for Command<Message> {
fn from(_value: ()) -> Self {
Self::none()
}
}
impl<T> fmt::Debug for Command<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Command(command) = self;

View file

@ -8,13 +8,6 @@
#![doc(
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
)]
#![forbid(unsafe_code, rust_2018_idioms)]
#![deny(
missing_debug_implementations,
missing_docs,
unused_results,
rustdoc::broken_intra_doc_links
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub mod clipboard;
pub mod command;

View file

@ -43,7 +43,7 @@ where
caches,
queued_events: Vec::new(),
queued_messages: Vec::new(),
mouse_interaction: mouse::Interaction::Idle,
mouse_interaction: mouse::Interaction::None,
}
}

View file

@ -2,7 +2,7 @@
use crate::Command;
use iced_core::text;
use iced_core::{Element, Renderer};
use iced_core::Element;
mod state;
@ -11,7 +11,7 @@ pub use state::State;
/// The core of a user interface application following The Elm Architecture.
pub trait Program: Sized {
/// The graphics backend to use to draw the [`Program`].
type Renderer: Renderer + text::Renderer;
type Renderer: text::Renderer;
/// The theme used to draw the [`Program`].
type Theme;

View file

@ -47,7 +47,7 @@ where
cache,
queued_events: Vec::new(),
queued_messages: Vec::new(),
mouse_interaction: mouse::Interaction::Idle,
mouse_interaction: mouse::Interaction::None,
}
}

View file

@ -45,7 +45,7 @@ where
///
/// ```no_run
/// # mod iced_wgpu {
/// # pub use iced_runtime::core::renderer::Null as Renderer;
/// # pub type Renderer = ();
/// # }
/// #
/// # pub struct Counter;
@ -62,7 +62,7 @@ where
/// // Initialization
/// let mut counter = Counter::new();
/// let mut cache = user_interface::Cache::new();
/// let mut renderer = Renderer::new();
/// let mut renderer = Renderer::default();
/// let mut window_size = Size::new(1024.0, 768.0);
///
/// // Application loop
@ -121,7 +121,7 @@ where
///
/// ```no_run
/// # mod iced_wgpu {
/// # pub use iced_runtime::core::renderer::Null as Renderer;
/// # pub type Renderer = ();
/// # }
/// #
/// # pub struct Counter;
@ -139,7 +139,7 @@ where
///
/// let mut counter = Counter::new();
/// let mut cache = user_interface::Cache::new();
/// let mut renderer = Renderer::new();
/// let mut renderer = Renderer::default();
/// let mut window_size = Size::new(1024.0, 768.0);
/// let mut cursor = mouse::Cursor::default();
/// let mut clipboard = clipboard::Null;
@ -374,7 +374,7 @@ where
///
/// ```no_run
/// # mod iced_wgpu {
/// # pub use iced_runtime::core::renderer::Null as Renderer;
/// # pub type Renderer = ();
/// # pub type Theme = ();
/// # }
/// #
@ -394,7 +394,7 @@ where
///
/// let mut counter = Counter::new();
/// let mut cache = user_interface::Cache::new();
/// let mut renderer = Renderer::new();
/// let mut renderer = Renderer::default();
/// let mut window_size = Size::new(1024.0, 768.0);
/// let mut cursor = mouse::Cursor::default();
/// let mut clipboard = clipboard::Null;

View file

@ -197,7 +197,7 @@ pub fn change_icon<Message>(id: Id, icon: Icon) -> Command<Message> {
/// Note that if the window closes before this call is processed the callback will not be run.
pub fn run_with_handle<Message>(
id: Id,
f: impl FnOnce(&WindowHandle<'_>) -> Message + 'static,
f: impl FnOnce(WindowHandle<'_>) -> Message + 'static,
) -> Command<Message> {
Command::single(command::Action::Window(Action::RunWithHandle(
id,

View file

@ -106,7 +106,7 @@ pub enum Action<T> {
/// said, it's usually in the same ballpark as on Windows.
ChangeIcon(Id, Icon),
/// Runs the closure with the native window handle of the window with the given [`Id`].
RunWithHandle(Id, Box<dyn FnOnce(&WindowHandle<'_>) -> T + 'static>),
RunWithHandle(Id, Box<dyn FnOnce(WindowHandle<'_>) -> T + 'static>),
/// Screenshot the viewport of the window.
Screenshot(Id, Box<dyn FnOnce(Screenshot) -> T + 'static>),
}

View file

@ -1,8 +1,8 @@
//! Take screenshots of a window.
use crate::core::{Rectangle, Size};
use bytes::Bytes;
use std::fmt::{Debug, Formatter};
use std::sync::Arc;
/// Data of a screenshot, captured with `window::screenshot()`.
///
@ -10,7 +10,7 @@ use std::sync::Arc;
#[derive(Clone)]
pub struct Screenshot {
/// The bytes of the [`Screenshot`].
pub bytes: Arc<Vec<u8>>,
pub bytes: Bytes,
/// The size of the [`Screenshot`].
pub size: Size<u32>,
}
@ -28,9 +28,9 @@ impl Debug for Screenshot {
impl Screenshot {
/// Creates a new [`Screenshot`].
pub fn new(bytes: Vec<u8>, size: Size<u32>) -> Self {
pub fn new(bytes: impl Into<Bytes>, size: Size<u32>) -> Self {
Self {
bytes: Arc::new(bytes),
bytes: bytes.into(),
size,
}
}
@ -68,7 +68,7 @@ impl Screenshot {
);
Ok(Self {
bytes: Arc::new(chopped),
bytes: Bytes::from(chopped),
size: Size::new(region.width, region.height),
})
}
@ -80,6 +80,12 @@ impl AsRef<[u8]> for Screenshot {
}
}
impl From<Screenshot> for Bytes {
fn from(screenshot: Screenshot) -> Self {
screenshot.bytes
}
}
#[derive(Debug, thiserror::Error)]
/// Errors that can occur when cropping a [`Screenshot`].
pub enum CropError {