summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-04-17 23:41:12 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-04-17 23:41:12 +0200
commit4bae457c37b499f3cfddbdac9ff37a34cbce61d5 (patch)
tree79af93b2f7fabca1687900b48b165c5c74dcd26f /core
parentc0431aedd3bbef4161456f2fa5f29866e8f17fc5 (diff)
parent4b05f42fd6d18bf572b772dd60d6a4309ea5f343 (diff)
downloadiced-4bae457c37b499f3cfddbdac9ff37a34cbce61d5.tar.gz
iced-4bae457c37b499f3cfddbdac9ff37a34cbce61d5.tar.bz2
iced-4bae457c37b499f3cfddbdac9ff37a34cbce61d5.zip
Merge branch 'master' into advanced-text
Diffstat (limited to 'core')
-rw-r--r--core/Cargo.toml2
-rw-r--r--core/README.md2
-rw-r--r--core/src/lib.rs2
-rw-r--r--core/src/mouse/interaction.rs1
-rw-r--r--core/src/widget.rs10
-rw-r--r--core/src/window.rs3
-rw-r--r--core/src/window/icon.rs80
7 files changed, 92 insertions, 8 deletions
diff --git a/core/Cargo.toml b/core/Cargo.toml
index dac31828..92d9773f 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "iced_core"
-version = "0.8.1"
+version = "0.9.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2021"
description = "The essential concepts of Iced"
diff --git a/core/README.md b/core/README.md
index 64d92e78..519e0608 100644
--- a/core/README.md
+++ b/core/README.md
@@ -18,7 +18,7 @@ This crate is meant to be a starting point for an Iced runtime.
Add `iced_core` as a dependency in your `Cargo.toml`:
```toml
-iced_core = "0.8"
+iced_core = "0.9"
```
__Iced moves fast and the `master` branch can contain breaking changes!__ If
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 5bdcee6a..89dfb828 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -7,7 +7,7 @@
//! ![The foundations of the Iced ecosystem](https://github.com/iced-rs/iced/blob/0525d76ff94e828b7b21634fa94a747022001c83/docs/graphs/foundations.png?raw=true)
//!
//! [Iced]: https://github.com/iced-rs/iced
-//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native
+//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.9/native
//! [`iced_web`]: https://github.com/iced-rs/iced_web
#![doc(
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
diff --git a/core/src/mouse/interaction.rs b/core/src/mouse/interaction.rs
index 57da93fe..072033fd 100644
--- a/core/src/mouse/interaction.rs
+++ b/core/src/mouse/interaction.rs
@@ -12,4 +12,5 @@ pub enum Interaction {
Grabbing,
ResizingHorizontally,
ResizingVertically,
+ NotAllowed,
}
diff --git a/core/src/widget.rs b/core/src/widget.rs
index 70e2c2d9..769f8659 100644
--- a/core/src/widget.rs
+++ b/core/src/widget.rs
@@ -33,12 +33,12 @@ use crate::{Clipboard, Length, Point, Rectangle, Shell};
/// - [`geometry`], a custom widget showcasing how to draw geometry with the
/// `Mesh2D` primitive in [`iced_wgpu`].
///
-/// [examples]: https://github.com/iced-rs/iced/tree/0.8/examples
-/// [`bezier_tool`]: https://github.com/iced-rs/iced/tree/0.8/examples/bezier_tool
-/// [`custom_widget`]: https://github.com/iced-rs/iced/tree/0.8/examples/custom_widget
-/// [`geometry`]: https://github.com/iced-rs/iced/tree/0.8/examples/geometry
+/// [examples]: https://github.com/iced-rs/iced/tree/0.9/examples
+/// [`bezier_tool`]: https://github.com/iced-rs/iced/tree/0.9/examples/bezier_tool
+/// [`custom_widget`]: https://github.com/iced-rs/iced/tree/0.9/examples/custom_widget
+/// [`geometry`]: https://github.com/iced-rs/iced/tree/0.9/examples/geometry
/// [`lyon`]: https://github.com/nical/lyon
-/// [`iced_wgpu`]: https://github.com/iced-rs/iced/tree/0.8/wgpu
+/// [`iced_wgpu`]: https://github.com/iced-rs/iced/tree/0.9/wgpu
pub trait Widget<Message, Renderer>
where
Renderer: crate::Renderer,
diff --git a/core/src/window.rs b/core/src/window.rs
index d829a4b4..81bd7e3d 100644
--- a/core/src/window.rs
+++ b/core/src/window.rs
@@ -1,10 +1,13 @@
//! Build window-based GUI applications.
+pub mod icon;
+
mod event;
mod mode;
mod redraw_request;
mod user_attention;
pub use event::Event;
+pub use icon::Icon;
pub use mode::Mode;
pub use redraw_request::RedrawRequest;
pub use user_attention::UserAttention;
diff --git a/core/src/window/icon.rs b/core/src/window/icon.rs
new file mode 100644
index 00000000..31868ecf
--- /dev/null
+++ b/core/src/window/icon.rs
@@ -0,0 +1,80 @@
+//! Change the icon of a window.
+use crate::Size;
+
+use std::mem;
+
+/// Builds an [`Icon`] from its RGBA pixels in the sRGB color space.
+pub fn from_rgba(
+ rgba: Vec<u8>,
+ width: u32,
+ height: u32,
+) -> Result<Icon, Error> {
+ const PIXEL_SIZE: usize = mem::size_of::<u8>() * 4;
+
+ if rgba.len() % PIXEL_SIZE != 0 {
+ return Err(Error::ByteCountNotDivisibleBy4 {
+ byte_count: rgba.len(),
+ });
+ }
+
+ let pixel_count = rgba.len() / PIXEL_SIZE;
+
+ if pixel_count != (width * height) as usize {
+ return Err(Error::DimensionsVsPixelCount {
+ width,
+ height,
+ width_x_height: (width * height) as usize,
+ pixel_count,
+ });
+ }
+
+ Ok(Icon {
+ rgba,
+ size: Size::new(width, height),
+ })
+}
+
+/// An window icon normally used for the titlebar or taskbar.
+#[derive(Debug, Clone)]
+pub struct Icon {
+ rgba: Vec<u8>,
+ size: Size<u32>,
+}
+
+impl Icon {
+ /// Returns the raw data of the [`Icon`].
+ pub fn into_raw(self) -> (Vec<u8>, Size<u32>) {
+ (self.rgba, self.size)
+ }
+}
+
+#[derive(Debug, thiserror::Error)]
+/// An error produced when using [`Icon::from_rgba`] with invalid arguments.
+pub enum Error {
+ /// Produced when the length of the `rgba` argument isn't divisible by 4, thus `rgba` can't be
+ /// safely interpreted as 32bpp RGBA pixels.
+ #[error(
+ "The provided RGBA data (with length {byte_count}) isn't divisible \
+ by 4. Therefore, it cannot be safely interpreted as 32bpp RGBA pixels"
+ )]
+ ByteCountNotDivisibleBy4 {
+ /// The length of the provided RGBA data.
+ byte_count: usize,
+ },
+ /// Produced when the number of pixels (`rgba.len() / 4`) isn't equal to `width * height`.
+ /// At least one of your arguments is incorrect.
+ #[error(
+ "The number of RGBA pixels ({pixel_count}) does not match the \
+ provided dimensions ({width}x{height})."
+ )]
+ DimensionsVsPixelCount {
+ /// The provided width.
+ width: u32,
+ /// The provided height.
+ height: u32,
+ /// The product of `width` and `height`.
+ width_x_height: usize,
+ /// The amount of pixels of the provided RGBA data.
+ pixel_count: usize,
+ },
+}