Merge branch 'iced-rs:master' into master
This commit is contained in:
commit
4f41927155
104 changed files with 1105 additions and 726 deletions
53
CHANGELOG.md
53
CHANGELOG.md
|
|
@ -6,6 +6,56 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [0.8.0] - 2023-02-18
|
||||||
|
### Added
|
||||||
|
- Generic pixel units. [#1711](https://github.com/iced-rs/iced/pull/1711)
|
||||||
|
- `custom` method to `widget::Operation` trait. [#1649](https://github.com/iced-rs/iced/pull/1649)
|
||||||
|
- `Group` overlay. [#1655](https://github.com/iced-rs/iced/pull/1655)
|
||||||
|
- Standalone `draw` helper for `image`. [#1682](https://github.com/iced-rs/iced/pull/1682)
|
||||||
|
- Dynamic `pick_list::Handle`. [#1675](https://github.com/iced-rs/iced/pull/1675)
|
||||||
|
- `Id` support for `Container`. [#1695](https://github.com/iced-rs/iced/pull/1695)
|
||||||
|
- Custom `Checkbox` icon support. [#1707](https://github.com/iced-rs/iced/pull/1707)
|
||||||
|
- `window` action to change always on top setting. [#1587](https://github.com/iced-rs/iced/pull/1587)
|
||||||
|
- `window` action to fetch its unique identifier. [#1589](https://github.com/iced-rs/iced/pull/1589)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Annotated `Command` and `Subscription` with `#[must_use]`. [#1676](https://github.com/iced-rs/iced/pull/1676)
|
||||||
|
- Replaced `Fn` with `FnOnce` in `canvas::Cache::draw`. [#1694](https://github.com/iced-rs/iced/pull/1694)
|
||||||
|
- Used `[default]` on enum in `game_of_life` example. [#1660](https://github.com/iced-rs/iced/pull/1660)
|
||||||
|
- Made `QRCode` hide when data is empty in `qr_code` example. [#1665](https://github.com/iced-rs/iced/pull/1665)
|
||||||
|
- Replaced `Cow` with `Bytes` in `image` to accept any kind of data that implements `AsRef<[u8]>`. [#1551](https://github.com/iced-rs/iced/pull/1551)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Blank window on application startup. [#1698](https://github.com/iced-rs/iced/pull/1698)
|
||||||
|
- Off-by-one pixel error on `pick_list` width. [#1679](https://github.com/iced-rs/iced/pull/1679)
|
||||||
|
- Missing `text_input` implementation in `operation::Map`. [#1678](https://github.com/iced-rs/iced/pull/1678)
|
||||||
|
- Widget-driven animations for `Component`. [#1685](https://github.com/iced-rs/iced/pull/1685)
|
||||||
|
- Layout translation in `overlay::Group`. [#1686](https://github.com/iced-rs/iced/pull/1686)
|
||||||
|
- Missing `is_over` implementation for overlays of `iced_lazy` widgets. [#1699](https://github.com/iced-rs/iced/pull/1699)
|
||||||
|
- Panic when overlay event processing removes overlay. [#1700](https://github.com/iced-rs/iced/pull/1700)
|
||||||
|
- Panic when using operations with components in certain cases. [#1701](https://github.com/iced-rs/iced/pull/1701)
|
||||||
|
- `TextInput` width when using padding. [#1706](https://github.com/iced-rs/iced/pull/1706)
|
||||||
|
- `iced_glow` crash on some hardware. [#1703](https://github.com/iced-rs/iced/pull/1703)
|
||||||
|
- Height of `overlay::Menu`. [#1714](https://github.com/iced-rs/iced/pull/1714)
|
||||||
|
- Size of images in `README`. [#1659](https://github.com/iced-rs/iced/pull/1659)
|
||||||
|
- New `clippy` lints. [#1681](https://github.com/iced-rs/iced/pull/1681)
|
||||||
|
|
||||||
|
Many thanks to...
|
||||||
|
|
||||||
|
- @13r0ck
|
||||||
|
- @bungoboingo
|
||||||
|
- @casperstorm
|
||||||
|
- @frey
|
||||||
|
- @greatest-ape
|
||||||
|
- @ids1024
|
||||||
|
- @Jedsek
|
||||||
|
- @nicksenger
|
||||||
|
- @Night-Hunter-NF
|
||||||
|
- @sdroege
|
||||||
|
- @Sn-Kinos
|
||||||
|
- @sushigiri
|
||||||
|
- @tarkah
|
||||||
|
|
||||||
## [0.7.0] - 2023-01-14
|
## [0.7.0] - 2023-01-14
|
||||||
### Added
|
### Added
|
||||||
- Widget-driven animations. [#1647](https://github.com/iced-rs/iced/pull/1647)
|
- Widget-driven animations. [#1647](https://github.com/iced-rs/iced/pull/1647)
|
||||||
|
|
@ -364,7 +414,8 @@ Many thanks to...
|
||||||
### Added
|
### Added
|
||||||
- First release! :tada:
|
- First release! :tada:
|
||||||
|
|
||||||
[Unreleased]: https://github.com/iced-rs/iced/compare/0.7.0...HEAD
|
[Unreleased]: https://github.com/iced-rs/iced/compare/0.8.0...HEAD
|
||||||
|
[0.8.0]: https://github.com/iced-rs/iced/compare/0.7.0...0.8.0
|
||||||
[0.7.0]: https://github.com/iced-rs/iced/compare/0.6.0...0.7.0
|
[0.7.0]: https://github.com/iced-rs/iced/compare/0.6.0...0.7.0
|
||||||
[0.6.0]: https://github.com/iced-rs/iced/compare/0.5.0...0.6.0
|
[0.6.0]: https://github.com/iced-rs/iced/compare/0.5.0...0.6.0
|
||||||
[0.5.0]: https://github.com/iced-rs/iced/compare/0.4.2...0.5.0
|
[0.5.0]: https://github.com/iced-rs/iced/compare/0.4.2...0.5.0
|
||||||
|
|
|
||||||
20
Cargo.toml
20
Cargo.toml
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced"
|
name = "iced"
|
||||||
version = "0.7.0"
|
version = "0.8.0"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A cross-platform GUI library inspired by Elm"
|
description = "A cross-platform GUI library inspired by Elm"
|
||||||
|
|
@ -66,13 +66,13 @@ members = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced_core = { version = "0.7", path = "core" }
|
iced_core = { version = "0.8", path = "core" }
|
||||||
iced_futures = { version = "0.5", path = "futures" }
|
iced_futures = { version = "0.6", path = "futures" }
|
||||||
iced_native = { version = "0.8", path = "native" }
|
iced_native = { version = "0.9", path = "native" }
|
||||||
iced_graphics = { version = "0.6", path = "graphics" }
|
iced_graphics = { version = "0.7", path = "graphics" }
|
||||||
iced_winit = { version = "0.7", path = "winit", features = ["application"] }
|
iced_winit = { version = "0.8", path = "winit", features = ["application"] }
|
||||||
iced_glutin = { version = "0.6", path = "glutin", optional = true }
|
iced_glutin = { version = "0.7", path = "glutin", optional = true }
|
||||||
iced_glow = { version = "0.6", path = "glow", optional = true }
|
iced_glow = { version = "0.7", path = "glow", optional = true }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
||||||
[dependencies.image_rs]
|
[dependencies.image_rs]
|
||||||
|
|
@ -81,10 +81,10 @@ package = "image"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
iced_wgpu = { version = "0.8", path = "wgpu", optional = true }
|
iced_wgpu = { version = "0.9", path = "wgpu", optional = true }
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
iced_wgpu = { version = "0.8", path = "wgpu", features = ["webgl"], optional = true }
|
iced_wgpu = { version = "0.9", path = "wgpu", features = ["webgl"], optional = true }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ A cross-platform GUI library for Rust focused on simplicity and type-safety.
|
||||||
Inspired by [Elm].
|
Inspired by [Elm].
|
||||||
|
|
||||||
<a href="https://gfycat.com/littlesanehalicore">
|
<a href="https://gfycat.com/littlesanehalicore">
|
||||||
<img src="https://thumbs.gfycat.com/LittleSaneHalicore-small.gif" height="350px">
|
<img src="https://thumbs.gfycat.com/LittleSaneHalicore-small.gif" width="275px">
|
||||||
</a>
|
</a>
|
||||||
<a href="https://gfycat.com/politeadorableiberianmole">
|
<a href="https://gfycat.com/politeadorableiberianmole">
|
||||||
<img src="https://thumbs.gfycat.com/PoliteAdorableIberianmole-small.gif" height="350px">
|
<img src="https://thumbs.gfycat.com/PoliteAdorableIberianmole-small.gif" width="273px">
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -68,7 +68,7 @@ __Iced is currently experimental software.__ [Take a look at the roadmap],
|
||||||
Add `iced` as a dependency in your `Cargo.toml`:
|
Add `iced` as a dependency in your `Cargo.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
iced = "0.7"
|
iced = "0.8"
|
||||||
```
|
```
|
||||||
|
|
||||||
If your project is using a Rust edition older than 2021, then you will need to
|
If your project is using a Rust edition older than 2021, then you will need to
|
||||||
|
|
@ -215,7 +215,7 @@ cargo run --features iced/glow --package game_of_life
|
||||||
and then use it in your project with
|
and then use it in your project with
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
iced = { version = "0.7", default-features = false, features = ["glow"] }
|
iced = { version = "0.8", default-features = false, features = ["glow"] }
|
||||||
```
|
```
|
||||||
|
|
||||||
__NOTE:__ Chances are you have hardware that supports at least OpenGL 2.1 or OpenGL ES 2.0,
|
__NOTE:__ Chances are you have hardware that supports at least OpenGL 2.1 or OpenGL ES 2.0,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced_core"
|
name = "iced_core"
|
||||||
version = "0.7.0"
|
version = "0.8.0"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "The essential concepts of Iced"
|
description = "The essential concepts of Iced"
|
||||||
|
|
|
||||||
|
|
@ -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`:
|
Add `iced_core` as a dependency in your `Cargo.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
iced_core = "0.7"
|
iced_core = "0.8"
|
||||||
```
|
```
|
||||||
|
|
||||||
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/// The strategy used to fill space in a specific dimension.
|
/// The strategy used to fill space in a specific dimension.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum Length {
|
pub enum Length {
|
||||||
/// Fill all the remaining space
|
/// Fill all the remaining space
|
||||||
Fill,
|
Fill,
|
||||||
|
|
@ -17,7 +17,7 @@ pub enum Length {
|
||||||
Shrink,
|
Shrink,
|
||||||
|
|
||||||
/// Fill a fixed amount of space
|
/// Fill a fixed amount of space
|
||||||
Units(u16),
|
Fixed(f32),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Length {
|
impl Length {
|
||||||
|
|
@ -31,13 +31,19 @@ impl Length {
|
||||||
Length::Fill => 1,
|
Length::Fill => 1,
|
||||||
Length::FillPortion(factor) => *factor,
|
Length::FillPortion(factor) => *factor,
|
||||||
Length::Shrink => 0,
|
Length::Shrink => 0,
|
||||||
Length::Units(_) => 0,
|
Length::Fixed(_) => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<f32> for Length {
|
||||||
|
fn from(amount: f32) -> Self {
|
||||||
|
Length::Fixed(amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<u16> for Length {
|
impl From<u16> for Length {
|
||||||
fn from(units: u16) -> Self {
|
fn from(units: u16) -> Self {
|
||||||
Length::Units(units)
|
Length::Fixed(f32::from(units))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
//! 
|
//! 
|
||||||
//!
|
//!
|
||||||
//! [Iced]: https://github.com/iced-rs/iced
|
//! [Iced]: https://github.com/iced-rs/iced
|
||||||
//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.7/native
|
//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native
|
||||||
//! [`iced_web`]: https://github.com/iced-rs/iced_web
|
//! [`iced_web`]: https://github.com/iced-rs/iced_web
|
||||||
#![doc(
|
#![doc(
|
||||||
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
||||||
|
|
@ -35,6 +35,7 @@ mod content_fit;
|
||||||
mod font;
|
mod font;
|
||||||
mod length;
|
mod length;
|
||||||
mod padding;
|
mod padding;
|
||||||
|
mod pixels;
|
||||||
mod point;
|
mod point;
|
||||||
mod rectangle;
|
mod rectangle;
|
||||||
mod size;
|
mod size;
|
||||||
|
|
@ -47,6 +48,7 @@ pub use content_fit::ContentFit;
|
||||||
pub use font::Font;
|
pub use font::Font;
|
||||||
pub use length::Length;
|
pub use length::Length;
|
||||||
pub use padding::Padding;
|
pub use padding::Padding;
|
||||||
|
pub use pixels::Pixels;
|
||||||
pub use point::Point;
|
pub use point::Point;
|
||||||
pub use rectangle::Rectangle;
|
pub use rectangle::Rectangle;
|
||||||
pub use size::Size;
|
pub use size::Size;
|
||||||
|
|
|
||||||
|
|
@ -33,29 +33,29 @@ use crate::Size;
|
||||||
/// let widget = Widget::new().padding([10, 20]); // top/bottom, left/right
|
/// let widget = Widget::new().padding([10, 20]); // top/bottom, left/right
|
||||||
/// let widget = Widget::new().padding([5, 10, 15, 20]); // top, right, bottom, left
|
/// let widget = Widget::new().padding([5, 10, 15, 20]); // top, right, bottom, left
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Hash, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct Padding {
|
pub struct Padding {
|
||||||
/// Top padding
|
/// Top padding
|
||||||
pub top: u16,
|
pub top: f32,
|
||||||
/// Right padding
|
/// Right padding
|
||||||
pub right: u16,
|
pub right: f32,
|
||||||
/// Bottom padding
|
/// Bottom padding
|
||||||
pub bottom: u16,
|
pub bottom: f32,
|
||||||
/// Left padding
|
/// Left padding
|
||||||
pub left: u16,
|
pub left: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Padding {
|
impl Padding {
|
||||||
/// Padding of zero
|
/// Padding of zero
|
||||||
pub const ZERO: Padding = Padding {
|
pub const ZERO: Padding = Padding {
|
||||||
top: 0,
|
top: 0.0,
|
||||||
right: 0,
|
right: 0.0,
|
||||||
bottom: 0,
|
bottom: 0.0,
|
||||||
left: 0,
|
left: 0.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Create a Padding that is equal on all sides
|
/// Create a Padding that is equal on all sides
|
||||||
pub const fn new(padding: u16) -> Padding {
|
pub const fn new(padding: f32) -> Padding {
|
||||||
Padding {
|
Padding {
|
||||||
top: padding,
|
top: padding,
|
||||||
right: padding,
|
right: padding,
|
||||||
|
|
@ -65,12 +65,12 @@ impl Padding {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the total amount of vertical [`Padding`].
|
/// Returns the total amount of vertical [`Padding`].
|
||||||
pub fn vertical(self) -> u16 {
|
pub fn vertical(self) -> f32 {
|
||||||
self.top + self.bottom
|
self.top + self.bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the total amount of horizontal [`Padding`].
|
/// Returns the total amount of horizontal [`Padding`].
|
||||||
pub fn horizontal(self) -> u16 {
|
pub fn horizontal(self) -> f32 {
|
||||||
self.left + self.right
|
self.left + self.right
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,16 +79,49 @@ impl Padding {
|
||||||
let available = (outer - inner).max(Size::ZERO);
|
let available = (outer - inner).max(Size::ZERO);
|
||||||
|
|
||||||
Padding {
|
Padding {
|
||||||
top: self.top.min((available.height as u16) / 2),
|
top: self.top.min(available.height / 2.0),
|
||||||
right: self.right.min((available.width as u16) / 2),
|
right: self.right.min(available.width / 2.0),
|
||||||
bottom: self.bottom.min((available.height as u16) / 2),
|
bottom: self.bottom.min(available.height / 2.0),
|
||||||
left: self.left.min((available.width as u16) / 2),
|
left: self.left.min(available.width / 2.0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u16> for Padding {
|
impl From<u16> for Padding {
|
||||||
fn from(p: u16) -> Self {
|
fn from(p: u16) -> Self {
|
||||||
|
Padding {
|
||||||
|
top: f32::from(p),
|
||||||
|
right: f32::from(p),
|
||||||
|
bottom: f32::from(p),
|
||||||
|
left: f32::from(p),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<[u16; 2]> for Padding {
|
||||||
|
fn from(p: [u16; 2]) -> Self {
|
||||||
|
Padding {
|
||||||
|
top: f32::from(p[0]),
|
||||||
|
right: f32::from(p[1]),
|
||||||
|
bottom: f32::from(p[0]),
|
||||||
|
left: f32::from(p[1]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<[u16; 4]> for Padding {
|
||||||
|
fn from(p: [u16; 4]) -> Self {
|
||||||
|
Padding {
|
||||||
|
top: f32::from(p[0]),
|
||||||
|
right: f32::from(p[1]),
|
||||||
|
bottom: f32::from(p[2]),
|
||||||
|
left: f32::from(p[3]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<f32> for Padding {
|
||||||
|
fn from(p: f32) -> Self {
|
||||||
Padding {
|
Padding {
|
||||||
top: p,
|
top: p,
|
||||||
right: p,
|
right: p,
|
||||||
|
|
@ -98,8 +131,8 @@ impl From<u16> for Padding {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<[u16; 2]> for Padding {
|
impl From<[f32; 2]> for Padding {
|
||||||
fn from(p: [u16; 2]) -> Self {
|
fn from(p: [f32; 2]) -> Self {
|
||||||
Padding {
|
Padding {
|
||||||
top: p[0],
|
top: p[0],
|
||||||
right: p[1],
|
right: p[1],
|
||||||
|
|
@ -109,8 +142,8 @@ impl From<[u16; 2]> for Padding {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<[u16; 4]> for Padding {
|
impl From<[f32; 4]> for Padding {
|
||||||
fn from(p: [u16; 4]) -> Self {
|
fn from(p: [f32; 4]) -> Self {
|
||||||
Padding {
|
Padding {
|
||||||
top: p[0],
|
top: p[0],
|
||||||
right: p[1],
|
right: p[1],
|
||||||
|
|
|
||||||
22
core/src/pixels.rs
Normal file
22
core/src/pixels.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/// An amount of logical pixels.
|
||||||
|
///
|
||||||
|
/// Normally used to represent an amount of space, or the size of something.
|
||||||
|
///
|
||||||
|
/// This type is normally asked as an argument in a generic way
|
||||||
|
/// (e.g. `impl Into<Pixels>`) and, since `Pixels` implements `From` both for
|
||||||
|
/// `f32` and `u16`, you should be able to provide both integers and float
|
||||||
|
/// literals as needed.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||||
|
pub struct Pixels(pub f32);
|
||||||
|
|
||||||
|
impl From<f32> for Pixels {
|
||||||
|
fn from(amount: f32) -> Self {
|
||||||
|
Self(amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u16> for Pixels {
|
||||||
|
fn from(amount: u16) -> Self {
|
||||||
|
Self(f32::from(amount))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -29,8 +29,8 @@ impl Size {
|
||||||
/// Increments the [`Size`] to account for the given padding.
|
/// Increments the [`Size`] to account for the given padding.
|
||||||
pub fn pad(&self, padding: Padding) -> Self {
|
pub fn pad(&self, padding: Padding) -> Self {
|
||||||
Size {
|
Size {
|
||||||
width: self.width + padding.horizontal() as f32,
|
width: self.width + padding.horizontal(),
|
||||||
height: self.height + padding.vertical() as f32,
|
height: self.height + padding.vertical(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
9
examples/checkbox/Cargo.toml
Normal file
9
examples/checkbox/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "checkbox"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Casper Rogild Storm<casper@rogildstorm.com>"]
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
iced = { path = "../.." }
|
||||||
12
examples/checkbox/README.md
Normal file
12
examples/checkbox/README.md
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
## Checkbox
|
||||||
|
|
||||||
|
A box that can be checked.
|
||||||
|
|
||||||
|
The __[`main`]__ file contains all the code of the example.
|
||||||
|
|
||||||
|
You can run it with `cargo run`:
|
||||||
|
```
|
||||||
|
cargo run --package pick_list
|
||||||
|
```
|
||||||
|
|
||||||
|
[`main`]: src/main.rs
|
||||||
BIN
examples/checkbox/fonts/icons.ttf
Normal file
BIN
examples/checkbox/fonts/icons.ttf
Normal file
Binary file not shown.
63
examples/checkbox/src/main.rs
Normal file
63
examples/checkbox/src/main.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
use iced::widget::{checkbox, column, container};
|
||||||
|
use iced::{Element, Font, Length, Sandbox, Settings};
|
||||||
|
|
||||||
|
const ICON_FONT: Font = Font::External {
|
||||||
|
name: "Icons",
|
||||||
|
bytes: include_bytes!("../fonts/icons.ttf"),
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn main() -> iced::Result {
|
||||||
|
Example::run(Settings::default())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct Example {
|
||||||
|
default_checkbox: bool,
|
||||||
|
custom_checkbox: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
enum Message {
|
||||||
|
DefaultChecked(bool),
|
||||||
|
CustomChecked(bool),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sandbox for Example {
|
||||||
|
type Message = Message;
|
||||||
|
|
||||||
|
fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn title(&self) -> String {
|
||||||
|
String::from("Checkbox - Iced")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, message: Message) {
|
||||||
|
match message {
|
||||||
|
Message::DefaultChecked(value) => self.default_checkbox = value,
|
||||||
|
Message::CustomChecked(value) => self.custom_checkbox = value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&self) -> Element<Message> {
|
||||||
|
let default_checkbox =
|
||||||
|
checkbox("Default", self.default_checkbox, Message::DefaultChecked);
|
||||||
|
let custom_checkbox =
|
||||||
|
checkbox("Custom", self.custom_checkbox, Message::CustomChecked)
|
||||||
|
.icon(checkbox::Icon {
|
||||||
|
font: ICON_FONT,
|
||||||
|
code_point: '\u{e901}',
|
||||||
|
size: None,
|
||||||
|
});
|
||||||
|
|
||||||
|
let content = column![default_checkbox, custom_checkbox].spacing(22);
|
||||||
|
|
||||||
|
container(content)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.height(Length::Fill)
|
||||||
|
.center_x()
|
||||||
|
.center_y()
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -301,11 +301,11 @@ impl<C: ColorSpace + Copy> ColorPicker<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
row![
|
row![
|
||||||
text(C::LABEL).width(Length::Units(50)),
|
text(C::LABEL).width(50),
|
||||||
slider(cr1, c1, move |v| C::new(v, c2, c3)),
|
slider(cr1, c1, move |v| C::new(v, c2, c3)),
|
||||||
slider(cr2, c2, move |v| C::new(c1, v, c3)),
|
slider(cr2, c2, move |v| C::new(c1, v, c3)),
|
||||||
slider(cr3, c3, move |v| C::new(c1, c2, v)),
|
slider(cr3, c3, move |v| C::new(c1, c2, v)),
|
||||||
text(color.to_string()).width(Length::Units(185)).size(14),
|
text(color.to_string()).width(185).size(14),
|
||||||
]
|
]
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ mod numeric_input {
|
||||||
.horizontal_alignment(alignment::Horizontal::Center)
|
.horizontal_alignment(alignment::Horizontal::Center)
|
||||||
.vertical_alignment(alignment::Vertical::Center),
|
.vertical_alignment(alignment::Vertical::Center),
|
||||||
)
|
)
|
||||||
.width(Length::Units(50))
|
.width(50)
|
||||||
.on_press(on_press)
|
.on_press(on_press)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ impl Application for Events {
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.horizontal_alignment(alignment::Horizontal::Center),
|
.horizontal_alignment(alignment::Horizontal::Center),
|
||||||
)
|
)
|
||||||
.width(Length::Units(100))
|
.width(100)
|
||||||
.padding(10)
|
.padding(10)
|
||||||
.on_press(Message::Exit);
|
.on_press(Message::Exit);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ impl Program for Controls {
|
||||||
let background_color = self.background_color;
|
let background_color = self.background_color;
|
||||||
|
|
||||||
let sliders = Row::new()
|
let sliders = Row::new()
|
||||||
.width(Length::Units(500))
|
.width(500)
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
.push(
|
.push(
|
||||||
Slider::new(0.0..=1.0, background_color.r, move |r| {
|
Slider::new(0.0..=1.0, background_color.r, move |r| {
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ impl Program for Controls {
|
||||||
let text = &self.text;
|
let text = &self.text;
|
||||||
|
|
||||||
let sliders = Row::new()
|
let sliders = Row::new()
|
||||||
.width(Length::Units(500))
|
.width(500)
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
.push(
|
.push(
|
||||||
slider(0.0..=1.0, background_color.r, move |r| {
|
slider(0.0..=1.0, background_color.r, move |r| {
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ impl Application for App {
|
||||||
]
|
]
|
||||||
.spacing(20),
|
.spacing(20),
|
||||||
)
|
)
|
||||||
.width(Length::Units(300))
|
.width(300)
|
||||||
.padding(10)
|
.padding(10)
|
||||||
.style(theme::Container::Box);
|
.style(theme::Container::Box);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,10 @@ impl Sandbox for Example {
|
||||||
.placeholder("Choose a language...");
|
.placeholder("Choose a language...");
|
||||||
|
|
||||||
let content = column![
|
let content = column![
|
||||||
vertical_space(Length::Units(600)),
|
vertical_space(600),
|
||||||
"Which is your favorite language?",
|
"Which is your favorite language?",
|
||||||
pick_list,
|
pick_list,
|
||||||
vertical_space(Length::Units(600)),
|
vertical_space(600),
|
||||||
]
|
]
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ impl Pokemon {
|
||||||
{
|
{
|
||||||
let bytes = reqwest::get(&url).await?.bytes().await?;
|
let bytes = reqwest::get(&url).await?.bytes().await?;
|
||||||
|
|
||||||
Ok(image::Handle::from_memory(bytes.as_ref().to_vec()))
|
Ok(image::Handle::from_memory(bytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,7 @@ impl Sandbox for QRGenerator {
|
||||||
type Message = Message;
|
type Message = Message;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
QRGenerator {
|
QRGenerator::default()
|
||||||
qr_code: qr_code::State::new("").ok(),
|
|
||||||
..Self::default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn title(&self) -> String {
|
fn title(&self) -> String {
|
||||||
|
|
@ -36,7 +33,12 @@ impl Sandbox for QRGenerator {
|
||||||
Message::DataChanged(mut data) => {
|
Message::DataChanged(mut data) => {
|
||||||
data.truncate(100);
|
data.truncate(100);
|
||||||
|
|
||||||
self.qr_code = qr_code::State::new(&data).ok();
|
self.qr_code = if data.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
qr_code::State::new(&data).ok()
|
||||||
|
};
|
||||||
|
|
||||||
self.data = data;
|
self.data = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +58,7 @@ impl Sandbox for QRGenerator {
|
||||||
.padding(15);
|
.padding(15);
|
||||||
|
|
||||||
let mut content = column![title, input]
|
let mut content = column![title, input]
|
||||||
.width(Length::Units(700))
|
.width(700)
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
.align_items(Alignment::Center);
|
.align_items(Alignment::Center);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -187,9 +187,9 @@ impl Application for ScrollableDemo {
|
||||||
column![
|
column![
|
||||||
scroll_to_end_button(),
|
scroll_to_end_button(),
|
||||||
text("Beginning!"),
|
text("Beginning!"),
|
||||||
vertical_space(Length::Units(1200)),
|
vertical_space(1200),
|
||||||
text("Middle!"),
|
text("Middle!"),
|
||||||
vertical_space(Length::Units(1200)),
|
vertical_space(1200),
|
||||||
text("End!"),
|
text("End!"),
|
||||||
scroll_to_beginning_button(),
|
scroll_to_beginning_button(),
|
||||||
]
|
]
|
||||||
|
|
@ -211,13 +211,13 @@ impl Application for ScrollableDemo {
|
||||||
row![
|
row![
|
||||||
scroll_to_end_button(),
|
scroll_to_end_button(),
|
||||||
text("Beginning!"),
|
text("Beginning!"),
|
||||||
horizontal_space(Length::Units(1200)),
|
horizontal_space(1200),
|
||||||
text("Middle!"),
|
text("Middle!"),
|
||||||
horizontal_space(Length::Units(1200)),
|
horizontal_space(1200),
|
||||||
text("End!"),
|
text("End!"),
|
||||||
scroll_to_beginning_button(),
|
scroll_to_beginning_button(),
|
||||||
]
|
]
|
||||||
.height(Length::Units(450))
|
.height(450)
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.padding([0, 40, 0, 40])
|
.padding([0, 40, 0, 40])
|
||||||
.spacing(40),
|
.spacing(40),
|
||||||
|
|
@ -237,26 +237,26 @@ impl Application for ScrollableDemo {
|
||||||
row![
|
row![
|
||||||
column![
|
column![
|
||||||
text("Let's do some scrolling!"),
|
text("Let's do some scrolling!"),
|
||||||
vertical_space(Length::Units(2400))
|
vertical_space(2400)
|
||||||
],
|
],
|
||||||
scroll_to_end_button(),
|
scroll_to_end_button(),
|
||||||
text("Horizontal - Beginning!"),
|
text("Horizontal - Beginning!"),
|
||||||
horizontal_space(Length::Units(1200)),
|
horizontal_space(1200),
|
||||||
//vertical content
|
//vertical content
|
||||||
column![
|
column![
|
||||||
text("Horizontal - Middle!"),
|
text("Horizontal - Middle!"),
|
||||||
scroll_to_end_button(),
|
scroll_to_end_button(),
|
||||||
text("Vertical - Beginning!"),
|
text("Vertical - Beginning!"),
|
||||||
vertical_space(Length::Units(1200)),
|
vertical_space(1200),
|
||||||
text("Vertical - Middle!"),
|
text("Vertical - Middle!"),
|
||||||
vertical_space(Length::Units(1200)),
|
vertical_space(1200),
|
||||||
text("Vertical - End!"),
|
text("Vertical - End!"),
|
||||||
scroll_to_beginning_button(),
|
scroll_to_beginning_button(),
|
||||||
vertical_space(Length::Units(40)),
|
vertical_space(40),
|
||||||
]
|
]
|
||||||
.align_items(Alignment::Fill)
|
.align_items(Alignment::Fill)
|
||||||
.spacing(40),
|
.spacing(40),
|
||||||
horizontal_space(Length::Units(1200)),
|
horizontal_space(1200),
|
||||||
text("Horizontal - End!"),
|
text("Horizontal - End!"),
|
||||||
scroll_to_beginning_button(),
|
scroll_to_beginning_button(),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,11 @@ impl Sandbox for Slider {
|
||||||
|
|
||||||
let h_slider =
|
let h_slider =
|
||||||
container(slider(0..=100, value, Message::SliderChanged))
|
container(slider(0..=100, value, Message::SliderChanged))
|
||||||
.width(Length::Units(250));
|
.width(250);
|
||||||
|
|
||||||
let v_slider =
|
let v_slider =
|
||||||
container(vertical_slider(0..=100, value, Message::SliderChanged))
|
container(vertical_slider(0..=100, value, Message::SliderChanged))
|
||||||
.height(Length::Units(200));
|
.height(200);
|
||||||
|
|
||||||
let text = text(format!("{value}"));
|
let text = text(format!("{value}"));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ impl Application for Stopwatch {
|
||||||
text(label).horizontal_alignment(alignment::Horizontal::Center),
|
text(label).horizontal_alignment(alignment::Horizontal::Center),
|
||||||
)
|
)
|
||||||
.padding(10)
|
.padding(10)
|
||||||
.width(Length::Units(80))
|
.width(80)
|
||||||
};
|
};
|
||||||
|
|
||||||
let toggle_button = {
|
let toggle_button = {
|
||||||
|
|
|
||||||
|
|
@ -108,14 +108,10 @@ impl Sandbox for Styling {
|
||||||
let progress_bar = progress_bar(0.0..=100.0, self.slider_value);
|
let progress_bar = progress_bar(0.0..=100.0, self.slider_value);
|
||||||
|
|
||||||
let scrollable = scrollable(
|
let scrollable = scrollable(
|
||||||
column![
|
column!["Scroll me!", vertical_space(800), "You did it!"]
|
||||||
"Scroll me!",
|
.width(Length::Fill),
|
||||||
vertical_space(Length::Units(800)),
|
|
||||||
"You did it!"
|
|
||||||
]
|
|
||||||
.width(Length::Fill),
|
|
||||||
)
|
)
|
||||||
.height(Length::Units(100));
|
.height(100);
|
||||||
|
|
||||||
let checkbox = checkbox(
|
let checkbox = checkbox(
|
||||||
"Check me!",
|
"Check me!",
|
||||||
|
|
@ -143,7 +139,7 @@ impl Sandbox for Styling {
|
||||||
column![checkbox, toggler].spacing(20)
|
column![checkbox, toggler].spacing(20)
|
||||||
]
|
]
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.height(Length::Units(100))
|
.height(100)
|
||||||
.align_items(Alignment::Center),
|
.align_items(Alignment::Center),
|
||||||
]
|
]
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
|
|
|
||||||
|
|
@ -460,7 +460,7 @@ fn empty_message(message: &str) -> Element<'_, Message> {
|
||||||
.style(Color::from([0.7, 0.7, 0.7])),
|
.style(Color::from([0.7, 0.7, 0.7])),
|
||||||
)
|
)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.height(Length::Units(200))
|
.height(200)
|
||||||
.center_y()
|
.center_y()
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
@ -474,7 +474,7 @@ const ICONS: Font = Font::External {
|
||||||
fn icon(unicode: char) -> Text<'static> {
|
fn icon(unicode: char) -> Text<'static> {
|
||||||
text(unicode.to_string())
|
text(unicode.to_string())
|
||||||
.font(ICONS)
|
.font(ICONS)
|
||||||
.width(Length::Units(20))
|
.width(20)
|
||||||
.horizontal_alignment(alignment::Horizontal::Center)
|
.horizontal_alignment(alignment::Horizontal::Center)
|
||||||
.size(20)
|
.size(20)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -513,14 +513,14 @@ impl<'a> Step {
|
||||||
text("Tip: You can use the scrollbar to scroll down faster!")
|
text("Tip: You can use the scrollbar to scroll down faster!")
|
||||||
.size(16),
|
.size(16),
|
||||||
)
|
)
|
||||||
.push(vertical_space(Length::Units(4096)))
|
.push(vertical_space(4096))
|
||||||
.push(
|
.push(
|
||||||
text("You are halfway there!")
|
text("You are halfway there!")
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.size(30)
|
.size(30)
|
||||||
.horizontal_alignment(alignment::Horizontal::Center),
|
.horizontal_alignment(alignment::Horizontal::Center),
|
||||||
)
|
)
|
||||||
.push(vertical_space(Length::Units(4096)))
|
.push(vertical_space(4096))
|
||||||
.push(ferris(300))
|
.push(ferris(300))
|
||||||
.push(
|
.push(
|
||||||
text("You made it!")
|
text("You made it!")
|
||||||
|
|
@ -605,7 +605,7 @@ fn ferris<'a>(width: u16) -> Container<'a, StepMessage> {
|
||||||
} else {
|
} else {
|
||||||
image(format!("{}/images/ferris.png", env!("CARGO_MANIFEST_DIR")))
|
image(format!("{}/images/ferris.png", env!("CARGO_MANIFEST_DIR")))
|
||||||
}
|
}
|
||||||
.width(Length::Units(width)),
|
.width(width),
|
||||||
)
|
)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.center_x()
|
.center_x()
|
||||||
|
|
@ -616,7 +616,7 @@ fn button<'a, Message: Clone>(label: &str) -> Button<'a, Message> {
|
||||||
text(label).horizontal_alignment(alignment::Horizontal::Center),
|
text(label).horizontal_alignment(alignment::Horizontal::Center),
|
||||||
)
|
)
|
||||||
.padding(12)
|
.padding(12)
|
||||||
.width(Length::Units(100))
|
.width(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn color_slider<'a>(
|
fn color_slider<'a>(
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced_futures"
|
name = "iced_futures"
|
||||||
version = "0.5.1"
|
version = "0.6.0"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Commands, subscriptions, and runtimes for Iced"
|
description = "Commands, subscriptions, and runtimes for Iced"
|
||||||
|
|
|
||||||
|
|
@ -126,9 +126,9 @@ impl<I, O, H> std::fmt::Debug for Subscription<I, O, H> {
|
||||||
/// - [`stopwatch`], a watch with start/stop and reset buttons showcasing how
|
/// - [`stopwatch`], a watch with start/stop and reset buttons showcasing how
|
||||||
/// to listen to time.
|
/// to listen to time.
|
||||||
///
|
///
|
||||||
/// [examples]: https://github.com/iced-rs/iced/tree/0.7/examples
|
/// [examples]: https://github.com/iced-rs/iced/tree/0.8/examples
|
||||||
/// [`download_progress`]: https://github.com/iced-rs/iced/tree/0.7/examples/download_progress
|
/// [`download_progress`]: https://github.com/iced-rs/iced/tree/0.8/examples/download_progress
|
||||||
/// [`stopwatch`]: https://github.com/iced-rs/iced/tree/0.7/examples/stopwatch
|
/// [`stopwatch`]: https://github.com/iced-rs/iced/tree/0.8/examples/stopwatch
|
||||||
pub trait Recipe<Hasher: std::hash::Hasher, Event> {
|
pub trait Recipe<Hasher: std::hash::Hasher, Event> {
|
||||||
/// The events that will be produced by a [`Subscription`] with this
|
/// The events that will be produced by a [`Subscription`] with this
|
||||||
/// [`Recipe`].
|
/// [`Recipe`].
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced_glow"
|
name = "iced_glow"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A glow renderer for iced"
|
description = "A glow renderer for iced"
|
||||||
|
|
@ -34,11 +34,11 @@ bytemuck = "1.4"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
[dependencies.iced_native]
|
[dependencies.iced_native]
|
||||||
version = "0.8"
|
version = "0.9"
|
||||||
path = "../native"
|
path = "../native"
|
||||||
|
|
||||||
[dependencies.iced_graphics]
|
[dependencies.iced_graphics]
|
||||||
version = "0.6"
|
version = "0.7"
|
||||||
path = "../graphics"
|
path = "../graphics"
|
||||||
features = ["font-fallback", "font-icons", "opengl"]
|
features = ["font-fallback", "font-icons", "opengl"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ Currently, `iced_glow` supports the following primitives:
|
||||||
Add `iced_glow` as a dependency in your `Cargo.toml`:
|
Add `iced_glow` as a dependency in your `Cargo.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
iced_glow = "0.6"
|
iced_glow = "0.7"
|
||||||
```
|
```
|
||||||
|
|
||||||
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ pub struct Backend {
|
||||||
quad_pipeline: quad::Pipeline,
|
quad_pipeline: quad::Pipeline,
|
||||||
text_pipeline: text::Pipeline,
|
text_pipeline: text::Pipeline,
|
||||||
triangle_pipeline: triangle::Pipeline,
|
triangle_pipeline: triangle::Pipeline,
|
||||||
default_text_size: u16,
|
default_text_size: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Backend {
|
impl Backend {
|
||||||
|
|
@ -228,7 +228,7 @@ impl backend::Text for Backend {
|
||||||
const CHECKMARK_ICON: char = font::CHECKMARK_ICON;
|
const CHECKMARK_ICON: char = font::CHECKMARK_ICON;
|
||||||
const ARROW_DOWN_ICON: char = font::ARROW_DOWN_ICON;
|
const ARROW_DOWN_ICON: char = font::ARROW_DOWN_ICON;
|
||||||
|
|
||||||
fn default_size(&self) -> u16 {
|
fn default_size(&self) -> f32 {
|
||||||
self.default_text_size
|
self.default_text_size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
//! 
|
//! 
|
||||||
//!
|
//!
|
||||||
//! [`glow`]: https://github.com/grovesNL/glow
|
//! [`glow`]: https://github.com/grovesNL/glow
|
||||||
//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.7/native
|
//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native
|
||||||
#![doc(
|
#![doc(
|
||||||
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
||||||
)]
|
)]
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,17 @@ impl Version {
|
||||||
) {
|
) {
|
||||||
// OpenGL 3.0+
|
// OpenGL 3.0+
|
||||||
(3, 0 | 1 | 2, false) => (
|
(3, 0 | 1 | 2, false) => (
|
||||||
format!("#version 1{}0", version.minor + 3),
|
format!("#version 1{}0\n#extension GL_ARB_explicit_attrib_location : enable", version.minor + 3),
|
||||||
format!(
|
format!(
|
||||||
"#version 1{}0\n#define HIGHER_THAN_300 1",
|
"#version 1{}0\n#extension GL_ARB_explicit_attrib_location : enable\n#define HIGHER_THAN_300 1",
|
||||||
version.minor + 3
|
version.minor + 3
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// OpenGL 3.3+
|
// OpenGL 3.3+
|
||||||
(3 | 4, _, false) => (
|
(3 | 4, _, false) => (
|
||||||
format!("#version {}{}0", version.major, version.minor),
|
format!("#version {}{}0\n#extension GL_ARB_explicit_attrib_location : enable", version.major, version.minor),
|
||||||
format!(
|
format!(
|
||||||
"#version {}{}0\n#define HIGHER_THAN_300 1",
|
"#version {}{}0\n#extension GL_ARB_explicit_attrib_location : enable\n#define HIGHER_THAN_300 1",
|
||||||
version.major, version.minor
|
version.major, version.minor
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ pub use iced_graphics::Antialiasing;
|
||||||
/// The settings of a [`Backend`].
|
/// The settings of a [`Backend`].
|
||||||
///
|
///
|
||||||
/// [`Backend`]: crate::Backend
|
/// [`Backend`]: crate::Backend
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
/// The bytes of the font that will be used by default.
|
/// The bytes of the font that will be used by default.
|
||||||
///
|
///
|
||||||
|
|
@ -13,8 +13,8 @@ pub struct Settings {
|
||||||
|
|
||||||
/// The default size of text.
|
/// The default size of text.
|
||||||
///
|
///
|
||||||
/// By default, it will be set to 20.
|
/// By default, it will be set to `20.0`.
|
||||||
pub default_text_size: u16,
|
pub default_text_size: f32,
|
||||||
|
|
||||||
/// If enabled, spread text workload in multiple threads when multiple cores
|
/// If enabled, spread text workload in multiple threads when multiple cores
|
||||||
/// are available.
|
/// are available.
|
||||||
|
|
@ -32,7 +32,7 @@ impl Default for Settings {
|
||||||
fn default() -> Settings {
|
fn default() -> Settings {
|
||||||
Settings {
|
Settings {
|
||||||
default_font: None,
|
default_font: None,
|
||||||
default_text_size: 20,
|
default_text_size: 20.0,
|
||||||
text_multithreading: false,
|
text_multithreading: false,
|
||||||
antialiasing: None,
|
antialiasing: None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced_glutin"
|
name = "iced_glutin"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A glutin runtime for Iced"
|
description = "A glutin runtime for Iced"
|
||||||
|
|
@ -24,16 +24,16 @@ git = "https://github.com/iced-rs/glutin"
|
||||||
rev = "da8d291486b4c9bec12487a46c119c4b1d386abf"
|
rev = "da8d291486b4c9bec12487a46c119c4b1d386abf"
|
||||||
|
|
||||||
[dependencies.iced_native]
|
[dependencies.iced_native]
|
||||||
version = "0.8"
|
version = "0.9"
|
||||||
path = "../native"
|
path = "../native"
|
||||||
|
|
||||||
[dependencies.iced_winit]
|
[dependencies.iced_winit]
|
||||||
version = "0.7"
|
version = "0.8"
|
||||||
path = "../winit"
|
path = "../winit"
|
||||||
features = ["application"]
|
features = ["application"]
|
||||||
|
|
||||||
[dependencies.iced_graphics]
|
[dependencies.iced_graphics]
|
||||||
version = "0.6"
|
version = "0.7"
|
||||||
path = "../graphics"
|
path = "../graphics"
|
||||||
features = ["opengl"]
|
features = ["opengl"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ It exposes a renderer-agnostic `Application` trait that can be implemented and t
|
||||||
Add `iced_glutin` as a dependency in your `Cargo.toml`:
|
Add `iced_glutin` as a dependency in your `Cargo.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
iced_glutin = "0.6"
|
iced_glutin = "0.7"
|
||||||
```
|
```
|
||||||
|
|
||||||
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced_graphics"
|
name = "iced_graphics"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A bunch of backend-agnostic types that can be leveraged to build a renderer for Iced"
|
description = "A bunch of backend-agnostic types that can be leveraged to build a renderer for Iced"
|
||||||
|
|
@ -44,11 +44,11 @@ version = "1.4"
|
||||||
features = ["derive"]
|
features = ["derive"]
|
||||||
|
|
||||||
[dependencies.iced_native]
|
[dependencies.iced_native]
|
||||||
version = "0.8"
|
version = "0.9"
|
||||||
path = "../native"
|
path = "../native"
|
||||||
|
|
||||||
[dependencies.iced_style]
|
[dependencies.iced_style]
|
||||||
version = "0.6"
|
version = "0.7"
|
||||||
path = "../style"
|
path = "../style"
|
||||||
|
|
||||||
[dependencies.lyon]
|
[dependencies.lyon]
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ pub trait Text {
|
||||||
const ARROW_DOWN_ICON: char;
|
const ARROW_DOWN_ICON: char;
|
||||||
|
|
||||||
/// Returns the default size of text.
|
/// Returns the default size of text.
|
||||||
fn default_size(&self) -> u16;
|
fn default_size(&self) -> f32;
|
||||||
|
|
||||||
/// Measures the text contents with the given size and font,
|
/// Measures the text contents with the given size and font,
|
||||||
/// returning the size of a laid out paragraph that fits in the provided
|
/// returning the size of a laid out paragraph that fits in the provided
|
||||||
|
|
|
||||||
|
|
@ -130,19 +130,18 @@ where
|
||||||
const CHECKMARK_ICON: char = B::CHECKMARK_ICON;
|
const CHECKMARK_ICON: char = B::CHECKMARK_ICON;
|
||||||
const ARROW_DOWN_ICON: char = B::ARROW_DOWN_ICON;
|
const ARROW_DOWN_ICON: char = B::ARROW_DOWN_ICON;
|
||||||
|
|
||||||
fn default_size(&self) -> u16 {
|
fn default_size(&self) -> f32 {
|
||||||
self.backend().default_size()
|
self.backend().default_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn measure(
|
fn measure(
|
||||||
&self,
|
&self,
|
||||||
content: &str,
|
content: &str,
|
||||||
size: u16,
|
size: f32,
|
||||||
font: Font,
|
font: Font,
|
||||||
bounds: Size,
|
bounds: Size,
|
||||||
) -> (f32, f32) {
|
) -> (f32, f32) {
|
||||||
self.backend()
|
self.backend().measure(content, size, font, bounds)
|
||||||
.measure(content, f32::from(size), font, bounds)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hit_test(
|
fn hit_test(
|
||||||
|
|
|
||||||
|
|
@ -100,13 +100,13 @@ impl<Message, Theme, P> Canvas<Message, Theme, P>
|
||||||
where
|
where
|
||||||
P: Program<Message, Theme>,
|
P: Program<Message, Theme>,
|
||||||
{
|
{
|
||||||
const DEFAULT_SIZE: u16 = 100;
|
const DEFAULT_SIZE: f32 = 100.0;
|
||||||
|
|
||||||
/// Creates a new [`Canvas`].
|
/// Creates a new [`Canvas`].
|
||||||
pub fn new(program: P) -> Self {
|
pub fn new(program: P) -> Self {
|
||||||
Canvas {
|
Canvas {
|
||||||
width: Length::Units(Self::DEFAULT_SIZE),
|
width: Length::Fixed(Self::DEFAULT_SIZE),
|
||||||
height: Length::Units(Self::DEFAULT_SIZE),
|
height: Length::Fixed(Self::DEFAULT_SIZE),
|
||||||
program,
|
program,
|
||||||
message_: PhantomData,
|
message_: PhantomData,
|
||||||
theme_: PhantomData,
|
theme_: PhantomData,
|
||||||
|
|
@ -114,14 +114,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Canvas`].
|
/// Sets the width of the [`Canvas`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`Canvas`].
|
/// Sets the height of the [`Canvas`].
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,11 @@ impl Cache {
|
||||||
/// Otherwise, the previously stored [`Geometry`] will be returned. The
|
/// Otherwise, the previously stored [`Geometry`] will be returned. The
|
||||||
/// [`Cache`] is not cleared in this case. In other words, it will keep
|
/// [`Cache`] is not cleared in this case. In other words, it will keep
|
||||||
/// returning the stored [`Geometry`] if needed.
|
/// returning the stored [`Geometry`] if needed.
|
||||||
pub fn draw(&self, bounds: Size, draw_fn: impl Fn(&mut Frame)) -> Geometry {
|
pub fn draw(
|
||||||
|
&self,
|
||||||
|
bounds: Size,
|
||||||
|
draw_fn: impl FnOnce(&mut Frame),
|
||||||
|
) -> Geometry {
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
if let State::Filled {
|
if let State::Filled {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced_lazy"
|
name = "iced_lazy"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Lazy widgets for Iced"
|
description = "Lazy widgets for Iced"
|
||||||
|
|
@ -14,5 +14,5 @@ categories = ["gui"]
|
||||||
ouroboros = "0.13"
|
ouroboros = "0.13"
|
||||||
|
|
||||||
[dependencies.iced_native]
|
[dependencies.iced_native]
|
||||||
version = "0.8"
|
version = "0.9"
|
||||||
path = "../native"
|
path = "../native"
|
||||||
|
|
|
||||||
|
|
@ -311,6 +311,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
self.with_element(|element| {
|
self.with_element(|element| {
|
||||||
|
tree.diff_children(std::slice::from_ref(&element));
|
||||||
|
|
||||||
element.as_widget().operate(
|
element.as_widget().operate(
|
||||||
&mut tree.children[0],
|
&mut tree.children[0],
|
||||||
layout,
|
layout,
|
||||||
|
|
@ -563,4 +565,11 @@ where
|
||||||
|
|
||||||
event_status
|
event_status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_over(&self, layout: Layout<'_>, cursor_position: Point) -> bool {
|
||||||
|
self.with_overlay_maybe(|overlay| {
|
||||||
|
overlay.is_over(layout, cursor_position)
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -372,6 +372,13 @@ where
|
||||||
})
|
})
|
||||||
.unwrap_or(iced_native::event::Status::Ignored)
|
.unwrap_or(iced_native::event::Status::Ignored)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_over(&self, layout: Layout<'_>, cursor_position: Point) -> bool {
|
||||||
|
self.with_overlay_maybe(|overlay| {
|
||||||
|
overlay.is_over(layout, cursor_position)
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Renderer, Dependency, View>
|
impl<'a, Message, Renderer, Dependency, View>
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ where
|
||||||
content: RefCell::new(Content {
|
content: RefCell::new(Content {
|
||||||
size: Size::ZERO,
|
size: Size::ZERO,
|
||||||
layout: layout::Node::new(Size::ZERO),
|
layout: layout::Node::new(Size::ZERO),
|
||||||
element: Element::new(horizontal_space(Length::Units(0))),
|
element: Element::new(horizontal_space(0)),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -415,4 +415,11 @@ where
|
||||||
})
|
})
|
||||||
.unwrap_or(iced_native::event::Status::Ignored)
|
.unwrap_or(iced_native::event::Status::Ignored)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_over(&self, layout: Layout<'_>, cursor_position: Point) -> bool {
|
||||||
|
self.with_overlay_maybe(|overlay| {
|
||||||
|
overlay.is_over(layout, cursor_position)
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced_native"
|
name = "iced_native"
|
||||||
version = "0.8.0"
|
version = "0.9.1"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A renderer-agnostic library for native GUIs"
|
description = "A renderer-agnostic library for native GUIs"
|
||||||
|
|
@ -16,14 +16,14 @@ unicode-segmentation = "1.6"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
|
|
||||||
[dependencies.iced_core]
|
[dependencies.iced_core]
|
||||||
version = "0.7"
|
version = "0.8"
|
||||||
path = "../core"
|
path = "../core"
|
||||||
|
|
||||||
[dependencies.iced_futures]
|
[dependencies.iced_futures]
|
||||||
version = "0.5"
|
version = "0.6"
|
||||||
path = "../futures"
|
path = "../futures"
|
||||||
features = ["thread-pool"]
|
features = ["thread-pool"]
|
||||||
|
|
||||||
[dependencies.iced_style]
|
[dependencies.iced_style]
|
||||||
version = "0.6.0"
|
version = "0.7"
|
||||||
path = "../style"
|
path = "../style"
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ To achieve this, it introduces a bunch of reusable interfaces:
|
||||||
Add `iced_native` as a dependency in your `Cargo.toml`:
|
Add `iced_native` as a dependency in your `Cargo.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
iced_native = "0.8"
|
iced_native = "0.9"
|
||||||
```
|
```
|
||||||
|
|
||||||
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
//! Load and draw raster graphics.
|
//! Load and draw raster graphics.
|
||||||
use crate::{Hasher, Rectangle, Size};
|
use crate::{Hasher, Rectangle, Size};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::hash::{Hash, Hasher as _};
|
use std::hash::{Hash, Hasher as _};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
@ -10,7 +9,7 @@ use std::sync::Arc;
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Handle {
|
pub struct Handle {
|
||||||
id: u64,
|
id: u64,
|
||||||
data: Arc<Data>,
|
data: Data,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Handle {
|
impl Handle {
|
||||||
|
|
@ -29,12 +28,12 @@ impl Handle {
|
||||||
pub fn from_pixels(
|
pub fn from_pixels(
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
pixels: impl Into<Cow<'static, [u8]>>,
|
pixels: impl AsRef<[u8]> + Send + Sync + 'static,
|
||||||
) -> Handle {
|
) -> Handle {
|
||||||
Self::from_data(Data::Rgba {
|
Self::from_data(Data::Rgba {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
pixels: pixels.into(),
|
pixels: Bytes::new(pixels),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,8 +43,10 @@ impl Handle {
|
||||||
///
|
///
|
||||||
/// This is useful if you already have your image loaded in-memory, maybe
|
/// This is useful if you already have your image loaded in-memory, maybe
|
||||||
/// because you downloaded or generated it procedurally.
|
/// because you downloaded or generated it procedurally.
|
||||||
pub fn from_memory(bytes: impl Into<Cow<'static, [u8]>>) -> Handle {
|
pub fn from_memory(
|
||||||
Self::from_data(Data::Bytes(bytes.into()))
|
bytes: impl AsRef<[u8]> + Send + Sync + 'static,
|
||||||
|
) -> Handle {
|
||||||
|
Self::from_data(Data::Bytes(Bytes::new(bytes)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_data(data: Data) -> Handle {
|
fn from_data(data: Data) -> Handle {
|
||||||
|
|
@ -54,7 +55,7 @@ impl Handle {
|
||||||
|
|
||||||
Handle {
|
Handle {
|
||||||
id: hasher.finish(),
|
id: hasher.finish(),
|
||||||
data: Arc::new(data),
|
data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,6 +85,45 @@ impl Hash for Handle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A wrapper around raw image data.
|
||||||
|
///
|
||||||
|
/// It behaves like a `&[u8]`.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Bytes(Arc<dyn AsRef<[u8]> + Send + Sync + 'static>);
|
||||||
|
|
||||||
|
impl Bytes {
|
||||||
|
/// Creates new [`Bytes`] around `data`.
|
||||||
|
pub fn new(data: impl AsRef<[u8]> + Send + Sync + 'static) -> Self {
|
||||||
|
Self(Arc::new(data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Debug for Bytes {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
self.0.as_ref().as_ref().fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::hash::Hash for Bytes {
|
||||||
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
|
self.0.as_ref().as_ref().hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRef<[u8]> for Bytes {
|
||||||
|
fn as_ref(&self) -> &[u8] {
|
||||||
|
self.0.as_ref().as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Deref for Bytes {
|
||||||
|
type Target = [u8];
|
||||||
|
|
||||||
|
fn deref(&self) -> &[u8] {
|
||||||
|
self.0.as_ref().as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The data of a raster image.
|
/// The data of a raster image.
|
||||||
#[derive(Clone, Hash)]
|
#[derive(Clone, Hash)]
|
||||||
pub enum Data {
|
pub enum Data {
|
||||||
|
|
@ -91,7 +131,7 @@ pub enum Data {
|
||||||
Path(PathBuf),
|
Path(PathBuf),
|
||||||
|
|
||||||
/// In-memory data
|
/// In-memory data
|
||||||
Bytes(Cow<'static, [u8]>),
|
Bytes(Bytes),
|
||||||
|
|
||||||
/// Decoded image pixels in RGBA format.
|
/// Decoded image pixels in RGBA format.
|
||||||
Rgba {
|
Rgba {
|
||||||
|
|
@ -100,7 +140,7 @@ pub enum Data {
|
||||||
/// The height of the image.
|
/// The height of the image.
|
||||||
height: u32,
|
height: u32,
|
||||||
/// The pixels.
|
/// The pixels.
|
||||||
pixels: Cow<'static, [u8]>,
|
pixels: Bytes,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let pad = axis.pack(padding.left as f32, padding.top as f32);
|
let pad = axis.pack(padding.left, padding.top);
|
||||||
let mut main = pad.0;
|
let mut main = pad.0;
|
||||||
|
|
||||||
for (i, node) in nodes.iter_mut().enumerate() {
|
for (i, node) in nodes.iter_mut().enumerate() {
|
||||||
|
|
|
||||||
|
|
@ -42,17 +42,16 @@ impl Limits {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a width constraint to the current [`Limits`].
|
/// Applies a width constraint to the current [`Limits`].
|
||||||
pub fn width(mut self, width: Length) -> Limits {
|
pub fn width(mut self, width: impl Into<Length>) -> Limits {
|
||||||
match width {
|
match width.into() {
|
||||||
Length::Shrink => {
|
Length::Shrink => {
|
||||||
self.fill.width = self.min.width;
|
self.fill.width = self.min.width;
|
||||||
}
|
}
|
||||||
Length::Fill | Length::FillPortion(_) => {
|
Length::Fill | Length::FillPortion(_) => {
|
||||||
self.fill.width = self.fill.width.min(self.max.width);
|
self.fill.width = self.fill.width.min(self.max.width);
|
||||||
}
|
}
|
||||||
Length::Units(units) => {
|
Length::Fixed(amount) => {
|
||||||
let new_width =
|
let new_width = amount.min(self.max.width).max(self.min.width);
|
||||||
(units as f32).min(self.max.width).max(self.min.width);
|
|
||||||
|
|
||||||
self.min.width = new_width;
|
self.min.width = new_width;
|
||||||
self.max.width = new_width;
|
self.max.width = new_width;
|
||||||
|
|
@ -64,17 +63,17 @@ impl Limits {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a height constraint to the current [`Limits`].
|
/// Applies a height constraint to the current [`Limits`].
|
||||||
pub fn height(mut self, height: Length) -> Limits {
|
pub fn height(mut self, height: impl Into<Length>) -> Limits {
|
||||||
match height {
|
match height.into() {
|
||||||
Length::Shrink => {
|
Length::Shrink => {
|
||||||
self.fill.height = self.min.height;
|
self.fill.height = self.min.height;
|
||||||
}
|
}
|
||||||
Length::Fill | Length::FillPortion(_) => {
|
Length::Fill | Length::FillPortion(_) => {
|
||||||
self.fill.height = self.fill.height.min(self.max.height);
|
self.fill.height = self.fill.height.min(self.max.height);
|
||||||
}
|
}
|
||||||
Length::Units(units) => {
|
Length::Fixed(amount) => {
|
||||||
let new_height =
|
let new_height =
|
||||||
(units as f32).min(self.max.height).max(self.min.height);
|
amount.min(self.max.height).max(self.min.height);
|
||||||
|
|
||||||
self.min.height = new_height;
|
self.min.height = new_height;
|
||||||
self.max.height = new_height;
|
self.max.height = new_height;
|
||||||
|
|
@ -86,43 +85,36 @@ impl Limits {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a minimum width constraint to the current [`Limits`].
|
/// Applies a minimum width constraint to the current [`Limits`].
|
||||||
pub fn min_width(mut self, min_width: u32) -> Limits {
|
pub fn min_width(mut self, min_width: f32) -> Limits {
|
||||||
self.min.width =
|
self.min.width = self.min.width.max(min_width).min(self.max.width);
|
||||||
self.min.width.max(min_width as f32).min(self.max.width);
|
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a maximum width constraint to the current [`Limits`].
|
/// Applies a maximum width constraint to the current [`Limits`].
|
||||||
pub fn max_width(mut self, max_width: u32) -> Limits {
|
pub fn max_width(mut self, max_width: f32) -> Limits {
|
||||||
self.max.width =
|
self.max.width = self.max.width.min(max_width).max(self.min.width);
|
||||||
self.max.width.min(max_width as f32).max(self.min.width);
|
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a minimum height constraint to the current [`Limits`].
|
/// Applies a minimum height constraint to the current [`Limits`].
|
||||||
pub fn min_height(mut self, min_height: u32) -> Limits {
|
pub fn min_height(mut self, min_height: f32) -> Limits {
|
||||||
self.min.height =
|
self.min.height = self.min.height.max(min_height).min(self.max.height);
|
||||||
self.min.height.max(min_height as f32).min(self.max.height);
|
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a maximum height constraint to the current [`Limits`].
|
/// Applies a maximum height constraint to the current [`Limits`].
|
||||||
pub fn max_height(mut self, max_height: u32) -> Limits {
|
pub fn max_height(mut self, max_height: f32) -> Limits {
|
||||||
self.max.height =
|
self.max.height = self.max.height.min(max_height).max(self.min.height);
|
||||||
self.max.height.min(max_height as f32).max(self.min.height);
|
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shrinks the current [`Limits`] to account for the given padding.
|
/// Shrinks the current [`Limits`] to account for the given padding.
|
||||||
pub fn pad(&self, padding: Padding) -> Limits {
|
pub fn pad(&self, padding: Padding) -> Limits {
|
||||||
self.shrink(Size::new(
|
self.shrink(Size::new(padding.horizontal(), padding.vertical()))
|
||||||
padding.horizontal() as f32,
|
|
||||||
padding.vertical() as f32,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shrinks the current [`Limits`] by the given [`Size`].
|
/// Shrinks the current [`Limits`] by the given [`Size`].
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
//! - Build a new renderer, see the [renderer] module.
|
//! - Build a new renderer, see the [renderer] module.
|
||||||
//! - Build a custom widget, start at the [`Widget`] trait.
|
//! - Build a custom widget, start at the [`Widget`] trait.
|
||||||
//!
|
//!
|
||||||
//! [`iced_core`]: https://github.com/iced-rs/iced/tree/0.7/core
|
//! [`iced_core`]: https://github.com/iced-rs/iced/tree/0.8/core
|
||||||
//! [`iced_winit`]: https://github.com/iced-rs/iced/tree/0.7/winit
|
//! [`iced_winit`]: https://github.com/iced-rs/iced/tree/0.8/winit
|
||||||
//! [`druid`]: https://github.com/xi-editor/druid
|
//! [`druid`]: https://github.com/xi-editor/druid
|
||||||
//! [`raw-window-handle`]: https://github.com/rust-windowing/raw-window-handle
|
//! [`raw-window-handle`]: https://github.com/rust-windowing/raw-window-handle
|
||||||
//! [renderer]: crate::renderer
|
//! [renderer]: crate::renderer
|
||||||
|
|
@ -81,7 +81,7 @@ pub use iced_core::alignment;
|
||||||
pub use iced_core::time;
|
pub use iced_core::time;
|
||||||
pub use iced_core::{
|
pub use iced_core::{
|
||||||
color, Alignment, Background, Color, ContentFit, Font, Length, Padding,
|
color, Alignment, Background, Color, ContentFit, Font, Length, Padding,
|
||||||
Point, Rectangle, Size, Vector,
|
Pixels, Point, Rectangle, Size, Vector,
|
||||||
};
|
};
|
||||||
pub use iced_futures::{executor, futures};
|
pub use iced_futures::{executor, futures};
|
||||||
pub use iced_style::application;
|
pub use iced_style::application;
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ use crate::widget::container::{self, Container};
|
||||||
use crate::widget::scrollable::{self, Scrollable};
|
use crate::widget::scrollable::{self, Scrollable};
|
||||||
use crate::widget::Tree;
|
use crate::widget::Tree;
|
||||||
use crate::{
|
use crate::{
|
||||||
Clipboard, Color, Element, Layout, Length, Padding, Point, Rectangle,
|
Clipboard, Color, Element, Layout, Length, Padding, Pixels, Point,
|
||||||
Shell, Size, Vector, Widget,
|
Rectangle, Shell, Size, Vector, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use iced_style::menu::{Appearance, StyleSheet};
|
pub use iced_style::menu::{Appearance, StyleSheet};
|
||||||
|
|
@ -28,9 +28,9 @@ where
|
||||||
options: &'a [T],
|
options: &'a [T],
|
||||||
hovered_option: &'a mut Option<usize>,
|
hovered_option: &'a mut Option<usize>,
|
||||||
last_selection: &'a mut Option<T>,
|
last_selection: &'a mut Option<T>,
|
||||||
width: u16,
|
width: f32,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
text_size: Option<u16>,
|
text_size: Option<f32>,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +55,7 @@ where
|
||||||
options,
|
options,
|
||||||
hovered_option,
|
hovered_option,
|
||||||
last_selection,
|
last_selection,
|
||||||
width: 0,
|
width: 0.0,
|
||||||
padding: Padding::ZERO,
|
padding: Padding::ZERO,
|
||||||
text_size: None,
|
text_size: None,
|
||||||
font: Default::default(),
|
font: Default::default(),
|
||||||
|
|
@ -64,7 +64,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Menu`].
|
/// Sets the width of the [`Menu`].
|
||||||
pub fn width(mut self, width: u16) -> Self {
|
pub fn width(mut self, width: f32) -> Self {
|
||||||
self.width = width;
|
self.width = width;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
@ -76,8 +76,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the text size of the [`Menu`].
|
/// Sets the text size of the [`Menu`].
|
||||||
pub fn text_size(mut self, text_size: u16) -> Self {
|
pub fn text_size(mut self, text_size: impl Into<Pixels>) -> Self {
|
||||||
self.text_size = Some(text_size);
|
self.text_size = Some(text_size.into().0);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,7 +142,7 @@ where
|
||||||
{
|
{
|
||||||
state: &'a mut Tree,
|
state: &'a mut Tree,
|
||||||
container: Container<'a, Message, Renderer>,
|
container: Container<'a, Message, Renderer>,
|
||||||
width: u16,
|
width: f32,
|
||||||
target_height: f32,
|
target_height: f32,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
@ -219,7 +219,7 @@ where
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.width(Length::Units(self.width));
|
.width(self.width);
|
||||||
|
|
||||||
let mut node = self.container.layout(renderer, &limits);
|
let mut node = self.container.layout(renderer, &limits);
|
||||||
|
|
||||||
|
|
@ -310,7 +310,7 @@ where
|
||||||
hovered_option: &'a mut Option<usize>,
|
hovered_option: &'a mut Option<usize>,
|
||||||
last_selection: &'a mut Option<T>,
|
last_selection: &'a mut Option<T>,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
text_size: Option<u16>,
|
text_size: Option<f32>,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
@ -344,7 +344,7 @@ where
|
||||||
let size = {
|
let size = {
|
||||||
let intrinsic = Size::new(
|
let intrinsic = Size::new(
|
||||||
0.0,
|
0.0,
|
||||||
f32::from(text_size + self.padding.vertical())
|
(text_size + self.padding.vertical())
|
||||||
* self.options.len() as f32,
|
* self.options.len() as f32,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -386,7 +386,7 @@ where
|
||||||
|
|
||||||
*self.hovered_option = Some(
|
*self.hovered_option = Some(
|
||||||
((cursor_position.y - bounds.y)
|
((cursor_position.y - bounds.y)
|
||||||
/ f32::from(text_size + self.padding.vertical()))
|
/ (text_size + self.padding.vertical()))
|
||||||
as usize,
|
as usize,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -401,7 +401,7 @@ where
|
||||||
|
|
||||||
*self.hovered_option = Some(
|
*self.hovered_option = Some(
|
||||||
((cursor_position.y - bounds.y)
|
((cursor_position.y - bounds.y)
|
||||||
/ f32::from(text_size + self.padding.vertical()))
|
/ (text_size + self.padding.vertical()))
|
||||||
as usize,
|
as usize,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -467,7 +467,7 @@ where
|
||||||
x: bounds.x,
|
x: bounds.x,
|
||||||
y: bounds.y + (option_height * i) as f32,
|
y: bounds.y + (option_height * i) as f32,
|
||||||
width: bounds.width,
|
width: bounds.width,
|
||||||
height: f32::from(text_size + self.padding.vertical()),
|
height: text_size + self.padding.vertical(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_selected {
|
if is_selected {
|
||||||
|
|
@ -485,12 +485,12 @@ where
|
||||||
renderer.fill_text(Text {
|
renderer.fill_text(Text {
|
||||||
content: &option.to_string(),
|
content: &option.to_string(),
|
||||||
bounds: Rectangle {
|
bounds: Rectangle {
|
||||||
x: bounds.x + self.padding.left as f32,
|
x: bounds.x + self.padding.left,
|
||||||
y: bounds.center_y(),
|
y: bounds.center_y(),
|
||||||
width: f32::INFINITY,
|
width: f32::INFINITY,
|
||||||
..bounds
|
..bounds
|
||||||
},
|
},
|
||||||
size: f32::from(text_size),
|
size: text_size,
|
||||||
font: self.font.clone(),
|
font: self.font.clone(),
|
||||||
color: if is_selected {
|
color: if is_selected {
|
||||||
appearance.selected_text_color
|
appearance.selected_text_color
|
||||||
|
|
|
||||||
|
|
@ -44,14 +44,14 @@ impl text::Renderer for Null {
|
||||||
const CHECKMARK_ICON: char = '0';
|
const CHECKMARK_ICON: char = '0';
|
||||||
const ARROW_DOWN_ICON: char = '0';
|
const ARROW_DOWN_ICON: char = '0';
|
||||||
|
|
||||||
fn default_size(&self) -> u16 {
|
fn default_size(&self) -> f32 {
|
||||||
20
|
20.0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn measure(
|
fn measure(
|
||||||
&self,
|
&self,
|
||||||
_content: &str,
|
_content: &str,
|
||||||
_size: u16,
|
_size: f32,
|
||||||
_font: Font,
|
_font: Font,
|
||||||
_bounds: Size,
|
_bounds: Size,
|
||||||
) -> (f32, f32) {
|
) -> (f32, f32) {
|
||||||
|
|
|
||||||
|
|
@ -100,11 +100,24 @@ where
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a [`Subscription`] that will call the given function to create and
|
||||||
|
/// asynchronously run the given [`Stream`].
|
||||||
|
pub fn run<S, Message>(builder: fn() -> S) -> Subscription<Message>
|
||||||
|
where
|
||||||
|
S: Stream<Item = Message> + MaybeSend + 'static,
|
||||||
|
Message: 'static,
|
||||||
|
{
|
||||||
|
Subscription::from_recipe(Runner {
|
||||||
|
id: builder,
|
||||||
|
spawn: move |_| builder(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a [`Subscription`] that will create and asynchronously run the
|
/// Returns a [`Subscription`] that will create and asynchronously run the
|
||||||
/// given [`Stream`].
|
/// given [`Stream`].
|
||||||
///
|
///
|
||||||
/// The `id` will be used to uniquely identify the [`Subscription`].
|
/// The `id` will be used to uniquely identify the [`Subscription`].
|
||||||
pub fn run<I, S, Message>(id: I, stream: S) -> Subscription<Message>
|
pub fn run_with_id<I, S, Message>(id: I, stream: S) -> Subscription<Message>
|
||||||
where
|
where
|
||||||
I: Hash + 'static,
|
I: Hash + 'static,
|
||||||
S: Stream<Item = Message> + MaybeSend + 'static,
|
S: Stream<Item = Message> + MaybeSend + 'static,
|
||||||
|
|
@ -184,7 +197,7 @@ where
|
||||||
/// Check out the [`websocket`] example, which showcases this pattern to maintain a WebSocket
|
/// Check out the [`websocket`] example, which showcases this pattern to maintain a WebSocket
|
||||||
/// connection open.
|
/// connection open.
|
||||||
///
|
///
|
||||||
/// [`websocket`]: https://github.com/iced-rs/iced/tree/0.7/examples/websocket
|
/// [`websocket`]: https://github.com/iced-rs/iced/tree/0.8/examples/websocket
|
||||||
pub fn unfold<I, T, Fut, Message>(
|
pub fn unfold<I, T, Fut, Message>(
|
||||||
id: I,
|
id: I,
|
||||||
initial: T,
|
initial: T,
|
||||||
|
|
@ -199,7 +212,7 @@ where
|
||||||
use futures::future::{self, FutureExt};
|
use futures::future::{self, FutureExt};
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
|
|
||||||
run(
|
run_with_id(
|
||||||
id,
|
id,
|
||||||
futures::stream::unfold(initial, move |state| f(state).map(Some))
|
futures::stream::unfold(initial, move |state| f(state).map(Some))
|
||||||
.filter_map(future::ready),
|
.filter_map(future::ready),
|
||||||
|
|
|
||||||
|
|
@ -73,20 +73,20 @@ pub trait Renderer: crate::Renderer {
|
||||||
const ARROW_DOWN_ICON: char;
|
const ARROW_DOWN_ICON: char;
|
||||||
|
|
||||||
/// Returns the default size of [`Text`].
|
/// Returns the default size of [`Text`].
|
||||||
fn default_size(&self) -> u16;
|
fn default_size(&self) -> f32;
|
||||||
|
|
||||||
/// Measures the text in the given bounds and returns the minimum boundaries
|
/// Measures the text in the given bounds and returns the minimum boundaries
|
||||||
/// that can fit the contents.
|
/// that can fit the contents.
|
||||||
fn measure(
|
fn measure(
|
||||||
&self,
|
&self,
|
||||||
content: &str,
|
content: &str,
|
||||||
size: u16,
|
size: f32,
|
||||||
font: Self::Font,
|
font: Self::Font,
|
||||||
bounds: Size,
|
bounds: Size,
|
||||||
) -> (f32, f32);
|
) -> (f32, f32);
|
||||||
|
|
||||||
/// Measures the width of the text as if it were laid out in a single line.
|
/// Measures the width of the text as if it were laid out in a single line.
|
||||||
fn measure_width(&self, content: &str, size: u16, font: Self::Font) -> f32 {
|
fn measure_width(&self, content: &str, size: f32, font: Self::Font) -> f32 {
|
||||||
let (width, _) = self.measure(content, size, font, Size::INFINITY);
|
let (width, _) = self.measure(content, size, font, Size::INFINITY);
|
||||||
|
|
||||||
width
|
width
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ use crate::{
|
||||||
/// The [`integration_opengl`] & [`integration_wgpu`] examples use a
|
/// The [`integration_opengl`] & [`integration_wgpu`] examples use a
|
||||||
/// [`UserInterface`] to integrate Iced in an existing graphical application.
|
/// [`UserInterface`] to integrate Iced in an existing graphical application.
|
||||||
///
|
///
|
||||||
/// [`integration_opengl`]: https://github.com/iced-rs/iced/tree/0.7/examples/integration_opengl
|
/// [`integration_opengl`]: https://github.com/iced-rs/iced/tree/0.8/examples/integration_opengl
|
||||||
/// [`integration_wgpu`]: https://github.com/iced-rs/iced/tree/0.7/examples/integration_wgpu
|
/// [`integration_wgpu`]: https://github.com/iced-rs/iced/tree/0.8/examples/integration_wgpu
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct UserInterface<'a, Message, Renderer> {
|
pub struct UserInterface<'a, Message, Renderer> {
|
||||||
root: Element<'a, Message, Renderer>,
|
root: Element<'a, Message, Renderer>,
|
||||||
|
|
@ -263,16 +263,16 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let base_cursor = if manual_overlay
|
let base_cursor = manual_overlay
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.filter(|overlay| {
|
||||||
.is_over(Layout::new(&layout), cursor_position)
|
overlay.is_over(Layout::new(&layout), cursor_position)
|
||||||
{
|
})
|
||||||
// TODO: Type-safe cursor availability
|
.map(|_| {
|
||||||
Point::new(-1.0, -1.0)
|
// TODO: Type-safe cursor availability
|
||||||
} else {
|
Point::new(-1.0, -1.0)
|
||||||
cursor_position
|
})
|
||||||
};
|
.unwrap_or(cursor_position);
|
||||||
|
|
||||||
self.overlay = Some(layout);
|
self.overlay = Some(layout);
|
||||||
|
|
||||||
|
|
@ -440,12 +440,13 @@ where
|
||||||
overlay.layout(renderer, self.bounds, Vector::ZERO)
|
overlay.layout(renderer, self.bounds, Vector::ZERO)
|
||||||
});
|
});
|
||||||
|
|
||||||
let new_cursor_position =
|
let new_cursor_position = if overlay
|
||||||
if overlay_layout.bounds().contains(cursor_position) {
|
.is_over(Layout::new(&overlay_layout), cursor_position)
|
||||||
Point::new(-1.0, -1.0)
|
{
|
||||||
} else {
|
Point::new(-1.0, -1.0)
|
||||||
cursor_position
|
} else {
|
||||||
};
|
cursor_position
|
||||||
|
};
|
||||||
|
|
||||||
self.overlay = Some(overlay_layout);
|
self.overlay = Some(overlay_layout);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,12 +110,12 @@ use crate::{Clipboard, Layout, Length, Point, Rectangle, Shell};
|
||||||
/// - [`geometry`], a custom widget showcasing how to draw geometry with the
|
/// - [`geometry`], a custom widget showcasing how to draw geometry with the
|
||||||
/// `Mesh2D` primitive in [`iced_wgpu`].
|
/// `Mesh2D` primitive in [`iced_wgpu`].
|
||||||
///
|
///
|
||||||
/// [examples]: https://github.com/iced-rs/iced/tree/0.7/examples
|
/// [examples]: https://github.com/iced-rs/iced/tree/0.8/examples
|
||||||
/// [`bezier_tool`]: https://github.com/iced-rs/iced/tree/0.7/examples/bezier_tool
|
/// [`bezier_tool`]: https://github.com/iced-rs/iced/tree/0.8/examples/bezier_tool
|
||||||
/// [`custom_widget`]: https://github.com/iced-rs/iced/tree/0.7/examples/custom_widget
|
/// [`custom_widget`]: https://github.com/iced-rs/iced/tree/0.8/examples/custom_widget
|
||||||
/// [`geometry`]: https://github.com/iced-rs/iced/tree/0.7/examples/geometry
|
/// [`geometry`]: https://github.com/iced-rs/iced/tree/0.8/examples/geometry
|
||||||
/// [`lyon`]: https://github.com/nical/lyon
|
/// [`lyon`]: https://github.com/nical/lyon
|
||||||
/// [`iced_wgpu`]: https://github.com/iced-rs/iced/tree/0.7/wgpu
|
/// [`iced_wgpu`]: https://github.com/iced-rs/iced/tree/0.8/wgpu
|
||||||
pub trait Widget<Message, Renderer>
|
pub trait Widget<Message, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: crate::Renderer,
|
Renderer: crate::Renderer,
|
||||||
|
|
|
||||||
|
|
@ -76,20 +76,20 @@ where
|
||||||
on_press: None,
|
on_press: None,
|
||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
padding: Padding::new(5),
|
padding: Padding::new(5.0),
|
||||||
style: <Renderer::Theme as StyleSheet>::Style::default(),
|
style: <Renderer::Theme as StyleSheet>::Style::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Button`].
|
/// Sets the width of the [`Button`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`Button`].
|
/// Sets the height of the [`Button`].
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -434,7 +434,7 @@ pub fn layout<Renderer>(
|
||||||
let padding = padding.fit(content.size(), limits.max());
|
let padding = padding.fit(content.size(), limits.max());
|
||||||
let size = limits.pad(padding).resolve(content.size()).pad(padding);
|
let size = limits.pad(padding).resolve(content.size()).pad(padding);
|
||||||
|
|
||||||
content.move_to(Point::new(padding.left.into(), padding.top.into()));
|
content.move_to(Point::new(padding.left, padding.top));
|
||||||
|
|
||||||
layout::Node::with_children(size, vec![content])
|
layout::Node::with_children(size, vec![content])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,23 @@ use crate::text;
|
||||||
use crate::touch;
|
use crate::touch;
|
||||||
use crate::widget::{self, Row, Text, Tree};
|
use crate::widget::{self, Row, Text, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Alignment, Clipboard, Element, Layout, Length, Point, Rectangle, Shell,
|
Alignment, Clipboard, Element, Layout, Length, Pixels, Point, Rectangle,
|
||||||
Widget,
|
Shell, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use iced_style::checkbox::{Appearance, StyleSheet};
|
pub use iced_style::checkbox::{Appearance, StyleSheet};
|
||||||
|
|
||||||
|
/// The icon in a [`Checkbox`].
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct Icon<Font> {
|
||||||
|
/// Font that will be used to display the `code_point`,
|
||||||
|
pub font: Font,
|
||||||
|
/// The unicode code point that will be used as the icon.
|
||||||
|
pub code_point: char,
|
||||||
|
/// Font size of the content.
|
||||||
|
pub size: Option<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
/// A box that can be checked.
|
/// A box that can be checked.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
|
|
@ -41,10 +52,11 @@ where
|
||||||
on_toggle: Box<dyn Fn(bool) -> Message + 'a>,
|
on_toggle: Box<dyn Fn(bool) -> Message + 'a>,
|
||||||
label: String,
|
label: String,
|
||||||
width: Length,
|
width: Length,
|
||||||
size: u16,
|
size: f32,
|
||||||
spacing: u16,
|
spacing: f32,
|
||||||
text_size: Option<u16>,
|
text_size: Option<f32>,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
|
icon: Icon<Renderer::Font>,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,10 +66,10 @@ where
|
||||||
Renderer::Theme: StyleSheet + widget::text::StyleSheet,
|
Renderer::Theme: StyleSheet + widget::text::StyleSheet,
|
||||||
{
|
{
|
||||||
/// The default size of a [`Checkbox`].
|
/// The default size of a [`Checkbox`].
|
||||||
const DEFAULT_SIZE: u16 = 20;
|
const DEFAULT_SIZE: f32 = 20.0;
|
||||||
|
|
||||||
/// The default spacing of a [`Checkbox`].
|
/// The default spacing of a [`Checkbox`].
|
||||||
const DEFAULT_SPACING: u16 = 15;
|
const DEFAULT_SPACING: f32 = 15.0;
|
||||||
|
|
||||||
/// Creates a new [`Checkbox`].
|
/// Creates a new [`Checkbox`].
|
||||||
///
|
///
|
||||||
|
|
@ -80,31 +92,36 @@ where
|
||||||
spacing: Self::DEFAULT_SPACING,
|
spacing: Self::DEFAULT_SPACING,
|
||||||
text_size: None,
|
text_size: None,
|
||||||
font: Renderer::Font::default(),
|
font: Renderer::Font::default(),
|
||||||
|
icon: Icon {
|
||||||
|
font: Renderer::ICON_FONT,
|
||||||
|
code_point: Renderer::CHECKMARK_ICON,
|
||||||
|
size: None,
|
||||||
|
},
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the size of the [`Checkbox`].
|
/// Sets the size of the [`Checkbox`].
|
||||||
pub fn size(mut self, size: u16) -> Self {
|
pub fn size(mut self, size: impl Into<Pixels>) -> Self {
|
||||||
self.size = size;
|
self.size = size.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Checkbox`].
|
/// Sets the width of the [`Checkbox`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the spacing between the [`Checkbox`] and the text.
|
/// Sets the spacing between the [`Checkbox`] and the text.
|
||||||
pub fn spacing(mut self, spacing: u16) -> Self {
|
pub fn spacing(mut self, spacing: impl Into<Pixels>) -> Self {
|
||||||
self.spacing = spacing;
|
self.spacing = spacing.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the text size of the [`Checkbox`].
|
/// Sets the text size of the [`Checkbox`].
|
||||||
pub fn text_size(mut self, text_size: u16) -> Self {
|
pub fn text_size(mut self, text_size: impl Into<Pixels>) -> Self {
|
||||||
self.text_size = Some(text_size);
|
self.text_size = Some(text_size.into().0);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,6 +133,12 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the [`Icon`] of the [`Checkbox`].
|
||||||
|
pub fn icon(mut self, icon: Icon<Renderer::Font>) -> Self {
|
||||||
|
self.icon = icon;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the style of the [`Checkbox`].
|
/// Sets the style of the [`Checkbox`].
|
||||||
pub fn style(
|
pub fn style(
|
||||||
mut self,
|
mut self,
|
||||||
|
|
@ -149,11 +172,7 @@ where
|
||||||
.width(self.width)
|
.width(self.width)
|
||||||
.spacing(self.spacing)
|
.spacing(self.spacing)
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.push(
|
.push(Row::new().width(self.size).height(self.size))
|
||||||
Row::new()
|
|
||||||
.width(Length::Units(self.size))
|
|
||||||
.height(Length::Units(self.size)),
|
|
||||||
)
|
|
||||||
.push(
|
.push(
|
||||||
Text::new(&self.label)
|
Text::new(&self.label)
|
||||||
.font(self.font.clone())
|
.font(self.font.clone())
|
||||||
|
|
@ -243,17 +262,24 @@ where
|
||||||
custom_style.background,
|
custom_style.background,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let Icon {
|
||||||
|
font,
|
||||||
|
code_point,
|
||||||
|
size,
|
||||||
|
} = &self.icon;
|
||||||
|
let size = size.map(f32::from).unwrap_or(bounds.height * 0.7);
|
||||||
|
|
||||||
if self.is_checked {
|
if self.is_checked {
|
||||||
renderer.fill_text(text::Text {
|
renderer.fill_text(text::Text {
|
||||||
content: &Renderer::CHECKMARK_ICON.to_string(),
|
content: &code_point.to_string(),
|
||||||
font: Renderer::ICON_FONT,
|
font: font.clone(),
|
||||||
size: bounds.height * 0.7,
|
size,
|
||||||
bounds: Rectangle {
|
bounds: Rectangle {
|
||||||
x: bounds.center_x(),
|
x: bounds.center_x(),
|
||||||
y: bounds.center_y(),
|
y: bounds.center_y(),
|
||||||
..bounds
|
..bounds
|
||||||
},
|
},
|
||||||
color: custom_style.checkmark_color,
|
color: custom_style.icon_color,
|
||||||
horizontal_alignment: alignment::Horizontal::Center,
|
horizontal_alignment: alignment::Horizontal::Center,
|
||||||
vertical_alignment: alignment::Vertical::Center,
|
vertical_alignment: alignment::Vertical::Center,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,18 @@ use crate::overlay;
|
||||||
use crate::renderer;
|
use crate::renderer;
|
||||||
use crate::widget::{Operation, Tree};
|
use crate::widget::{Operation, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Alignment, Clipboard, Element, Layout, Length, Padding, Point, Rectangle,
|
Alignment, Clipboard, Element, Layout, Length, Padding, Pixels, Point,
|
||||||
Shell, Widget,
|
Rectangle, Shell, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A container that distributes its contents vertically.
|
/// A container that distributes its contents vertically.
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Column<'a, Message, Renderer> {
|
pub struct Column<'a, Message, Renderer> {
|
||||||
spacing: u16,
|
spacing: f32,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
max_width: u32,
|
max_width: f32,
|
||||||
align_items: Alignment,
|
align_items: Alignment,
|
||||||
children: Vec<Element<'a, Message, Renderer>>,
|
children: Vec<Element<'a, Message, Renderer>>,
|
||||||
}
|
}
|
||||||
|
|
@ -33,11 +33,11 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
||||||
children: Vec<Element<'a, Message, Renderer>>,
|
children: Vec<Element<'a, Message, Renderer>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Column {
|
Column {
|
||||||
spacing: 0,
|
spacing: 0.0,
|
||||||
padding: Padding::ZERO,
|
padding: Padding::ZERO,
|
||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
max_width: u32::MAX,
|
max_width: f32::INFINITY,
|
||||||
align_items: Alignment::Start,
|
align_items: Alignment::Start,
|
||||||
children,
|
children,
|
||||||
}
|
}
|
||||||
|
|
@ -48,8 +48,8 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
||||||
/// Custom margins per element do not exist in iced. You should use this
|
/// Custom margins per element do not exist in iced. You should use this
|
||||||
/// method instead! While less flexible, it helps you keep spacing between
|
/// method instead! While less flexible, it helps you keep spacing between
|
||||||
/// elements consistent.
|
/// elements consistent.
|
||||||
pub fn spacing(mut self, units: u16) -> Self {
|
pub fn spacing(mut self, amount: impl Into<Pixels>) -> Self {
|
||||||
self.spacing = units;
|
self.spacing = amount.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,20 +60,20 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Column`].
|
/// Sets the width of the [`Column`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`Column`].
|
/// Sets the height of the [`Column`].
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the maximum width of the [`Column`].
|
/// Sets the maximum width of the [`Column`].
|
||||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
pub fn max_width(mut self, max_width: impl Into<Pixels>) -> Self {
|
||||||
self.max_width = max_width;
|
self.max_width = max_width.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,7 +135,7 @@ where
|
||||||
renderer,
|
renderer,
|
||||||
&limits,
|
&limits,
|
||||||
self.padding,
|
self.padding,
|
||||||
self.spacing as f32,
|
self.spacing,
|
||||||
self.align_items,
|
self.align_items,
|
||||||
&self.children,
|
&self.children,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,12 @@ use crate::layout;
|
||||||
use crate::mouse;
|
use crate::mouse;
|
||||||
use crate::overlay;
|
use crate::overlay;
|
||||||
use crate::renderer;
|
use crate::renderer;
|
||||||
use crate::widget::{Operation, Tree};
|
use crate::widget::{self, Operation, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Background, Clipboard, Color, Element, Layout, Length, Padding, Point,
|
Background, Clipboard, Color, Element, Layout, Length, Padding, Pixels,
|
||||||
Rectangle, Shell, Widget,
|
Point, Rectangle, Shell, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::u32;
|
|
||||||
|
|
||||||
pub use iced_style::container::{Appearance, StyleSheet};
|
pub use iced_style::container::{Appearance, StyleSheet};
|
||||||
|
|
||||||
/// An element decorating some content.
|
/// An element decorating some content.
|
||||||
|
|
@ -24,11 +22,12 @@ where
|
||||||
Renderer: crate::Renderer,
|
Renderer: crate::Renderer,
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
|
id: Option<Id>,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
max_width: u32,
|
max_width: f32,
|
||||||
max_height: u32,
|
max_height: f32,
|
||||||
horizontal_alignment: alignment::Horizontal,
|
horizontal_alignment: alignment::Horizontal,
|
||||||
vertical_alignment: alignment::Vertical,
|
vertical_alignment: alignment::Vertical,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
|
|
@ -46,11 +45,12 @@ where
|
||||||
T: Into<Element<'a, Message, Renderer>>,
|
T: Into<Element<'a, Message, Renderer>>,
|
||||||
{
|
{
|
||||||
Container {
|
Container {
|
||||||
|
id: None,
|
||||||
padding: Padding::ZERO,
|
padding: Padding::ZERO,
|
||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
max_width: u32::MAX,
|
max_width: f32::INFINITY,
|
||||||
max_height: u32::MAX,
|
max_height: f32::INFINITY,
|
||||||
horizontal_alignment: alignment::Horizontal::Left,
|
horizontal_alignment: alignment::Horizontal::Left,
|
||||||
vertical_alignment: alignment::Vertical::Top,
|
vertical_alignment: alignment::Vertical::Top,
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
|
|
@ -58,6 +58,12 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the [`Id`] of the [`Container`].
|
||||||
|
pub fn id(mut self, id: Id) -> Self {
|
||||||
|
self.id = Some(id);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the [`Padding`] of the [`Container`].
|
/// Sets the [`Padding`] of the [`Container`].
|
||||||
pub fn padding<P: Into<Padding>>(mut self, padding: P) -> Self {
|
pub fn padding<P: Into<Padding>>(mut self, padding: P) -> Self {
|
||||||
self.padding = padding.into();
|
self.padding = padding.into();
|
||||||
|
|
@ -65,26 +71,26 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Container`].
|
/// Sets the width of the [`Container`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`Container`].
|
/// Sets the height of the [`Container`].
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the maximum width of the [`Container`].
|
/// Sets the maximum width of the [`Container`].
|
||||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
pub fn max_width(mut self, max_width: impl Into<Pixels>) -> Self {
|
||||||
self.max_width = max_width;
|
self.max_width = max_width.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the maximum height of the [`Container`] in pixels.
|
/// Sets the maximum height of the [`Container`].
|
||||||
pub fn max_height(mut self, max_height: u32) -> Self {
|
pub fn max_height(mut self, max_height: impl Into<Pixels>) -> Self {
|
||||||
self.max_height = max_height;
|
self.max_height = max_height.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,14 +178,17 @@ where
|
||||||
renderer: &Renderer,
|
renderer: &Renderer,
|
||||||
operation: &mut dyn Operation<Message>,
|
operation: &mut dyn Operation<Message>,
|
||||||
) {
|
) {
|
||||||
operation.container(None, &mut |operation| {
|
operation.container(
|
||||||
self.content.as_widget().operate(
|
self.id.as_ref().map(|id| &id.0),
|
||||||
&mut tree.children[0],
|
&mut |operation| {
|
||||||
layout.children().next().unwrap(),
|
self.content.as_widget().operate(
|
||||||
renderer,
|
&mut tree.children[0],
|
||||||
operation,
|
layout.children().next().unwrap(),
|
||||||
);
|
renderer,
|
||||||
});
|
operation,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(
|
fn on_event(
|
||||||
|
|
@ -283,8 +292,8 @@ pub fn layout<Renderer>(
|
||||||
limits: &layout::Limits,
|
limits: &layout::Limits,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
max_width: u32,
|
max_width: f32,
|
||||||
max_height: u32,
|
max_height: f32,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
horizontal_alignment: alignment::Horizontal,
|
horizontal_alignment: alignment::Horizontal,
|
||||||
vertical_alignment: alignment::Vertical,
|
vertical_alignment: alignment::Vertical,
|
||||||
|
|
@ -301,7 +310,7 @@ pub fn layout<Renderer>(
|
||||||
let padding = padding.fit(content.size(), limits.max());
|
let padding = padding.fit(content.size(), limits.max());
|
||||||
let size = limits.pad(padding).resolve(content.size());
|
let size = limits.pad(padding).resolve(content.size());
|
||||||
|
|
||||||
content.move_to(Point::new(padding.left.into(), padding.top.into()));
|
content.move_to(Point::new(padding.left, padding.top));
|
||||||
content.align(
|
content.align(
|
||||||
Alignment::from(horizontal_alignment),
|
Alignment::from(horizontal_alignment),
|
||||||
Alignment::from(vertical_alignment),
|
Alignment::from(vertical_alignment),
|
||||||
|
|
@ -333,3 +342,27 @@ pub fn draw_background<Renderer>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The identifier of a [`Container`].
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Id(widget::Id);
|
||||||
|
|
||||||
|
impl Id {
|
||||||
|
/// Creates a custom [`Id`].
|
||||||
|
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
|
||||||
|
Self(widget::Id::new(id))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a unique [`Id`].
|
||||||
|
///
|
||||||
|
/// This function produces a different [`Id`] every time it is called.
|
||||||
|
pub fn unique() -> Self {
|
||||||
|
Self(widget::Id::unique())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Id> for widget::Id {
|
||||||
|
fn from(id: Id) -> Self {
|
||||||
|
id.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
//! Helper functions to create pure widgets.
|
//! Helper functions to create pure widgets.
|
||||||
use crate::overlay;
|
use crate::overlay;
|
||||||
use crate::widget;
|
use crate::widget;
|
||||||
use crate::{Element, Length};
|
use crate::{Element, Length, Pixels};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
|
|
@ -247,21 +247,23 @@ pub fn image<Handle>(handle: impl Into<Handle>) -> widget::Image<Handle> {
|
||||||
/// Creates a new horizontal [`Space`] with the given [`Length`].
|
/// Creates a new horizontal [`Space`] with the given [`Length`].
|
||||||
///
|
///
|
||||||
/// [`Space`]: widget::Space
|
/// [`Space`]: widget::Space
|
||||||
pub fn horizontal_space(width: Length) -> widget::Space {
|
pub fn horizontal_space(width: impl Into<Length>) -> widget::Space {
|
||||||
widget::Space::with_width(width)
|
widget::Space::with_width(width)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new vertical [`Space`] with the given [`Length`].
|
/// Creates a new vertical [`Space`] with the given [`Length`].
|
||||||
///
|
///
|
||||||
/// [`Space`]: widget::Space
|
/// [`Space`]: widget::Space
|
||||||
pub fn vertical_space(height: Length) -> widget::Space {
|
pub fn vertical_space(height: impl Into<Length>) -> widget::Space {
|
||||||
widget::Space::with_height(height)
|
widget::Space::with_height(height)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a horizontal [`Rule`] with the given height.
|
/// Creates a horizontal [`Rule`] with the given height.
|
||||||
///
|
///
|
||||||
/// [`Rule`]: widget::Rule
|
/// [`Rule`]: widget::Rule
|
||||||
pub fn horizontal_rule<Renderer>(height: u16) -> widget::Rule<Renderer>
|
pub fn horizontal_rule<Renderer>(
|
||||||
|
height: impl Into<Pixels>,
|
||||||
|
) -> widget::Rule<Renderer>
|
||||||
where
|
where
|
||||||
Renderer: crate::Renderer,
|
Renderer: crate::Renderer,
|
||||||
Renderer::Theme: widget::rule::StyleSheet,
|
Renderer::Theme: widget::rule::StyleSheet,
|
||||||
|
|
@ -272,7 +274,9 @@ where
|
||||||
/// Creates a vertical [`Rule`] with the given width.
|
/// Creates a vertical [`Rule`] with the given width.
|
||||||
///
|
///
|
||||||
/// [`Rule`]: widget::Rule
|
/// [`Rule`]: widget::Rule
|
||||||
pub fn vertical_rule<Renderer>(width: u16) -> widget::Rule<Renderer>
|
pub fn vertical_rule<Renderer>(
|
||||||
|
width: impl Into<Pixels>,
|
||||||
|
) -> widget::Rule<Renderer>
|
||||||
where
|
where
|
||||||
Renderer: crate::Renderer,
|
Renderer: crate::Renderer,
|
||||||
Renderer::Theme: widget::rule::StyleSheet,
|
Renderer::Theme: widget::rule::StyleSheet,
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ pub fn viewer<Handle>(handle: Handle) -> Viewer<Handle> {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// <img src="https://github.com/iced-rs/iced/blob/9712b319bb7a32848001b96bd84977430f14b623/examples/resources/ferris.png?raw=true" width="300">
|
/// <img src="https://github.com/iced-rs/iced/blob/9712b319bb7a32848001b96bd84977430f14b623/examples/resources/ferris.png?raw=true" width="300">
|
||||||
#[derive(Debug, Hash)]
|
#[derive(Debug)]
|
||||||
pub struct Image<Handle> {
|
pub struct Image<Handle> {
|
||||||
handle: Handle,
|
handle: Handle,
|
||||||
width: Length,
|
width: Length,
|
||||||
|
|
@ -49,14 +49,14 @@ impl<Handle> Image<Handle> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Image`] boundaries.
|
/// Sets the width of the [`Image`] boundaries.
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`Image`] boundaries.
|
/// Sets the height of the [`Image`] boundaries.
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ use crate::mouse;
|
||||||
use crate::renderer;
|
use crate::renderer;
|
||||||
use crate::widget::tree::{self, Tree};
|
use crate::widget::tree::{self, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Clipboard, Element, Layout, Length, Point, Rectangle, Shell, Size, Vector,
|
Clipboard, Element, Layout, Length, Pixels, Point, Rectangle, Shell, Size,
|
||||||
Widget,
|
Vector, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
@ -15,7 +15,7 @@ use std::hash::Hash;
|
||||||
/// A frame that displays an image with the ability to zoom in/out and pan.
|
/// A frame that displays an image with the ability to zoom in/out and pan.
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Viewer<Handle> {
|
pub struct Viewer<Handle> {
|
||||||
padding: u16,
|
padding: f32,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
min_scale: f32,
|
min_scale: f32,
|
||||||
|
|
@ -28,7 +28,7 @@ impl<Handle> Viewer<Handle> {
|
||||||
/// Creates a new [`Viewer`] with the given [`State`].
|
/// Creates a new [`Viewer`] with the given [`State`].
|
||||||
pub fn new(handle: Handle) -> Self {
|
pub fn new(handle: Handle) -> Self {
|
||||||
Viewer {
|
Viewer {
|
||||||
padding: 0,
|
padding: 0.0,
|
||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
min_scale: 0.25,
|
min_scale: 0.25,
|
||||||
|
|
@ -39,20 +39,20 @@ impl<Handle> Viewer<Handle> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the padding of the [`Viewer`].
|
/// Sets the padding of the [`Viewer`].
|
||||||
pub fn padding(mut self, units: u16) -> Self {
|
pub fn padding(mut self, padding: impl Into<Pixels>) -> Self {
|
||||||
self.padding = units;
|
self.padding = padding.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Viewer`].
|
/// Sets the width of the [`Viewer`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`Viewer`].
|
/// Sets the height of the [`Viewer`].
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +124,7 @@ where
|
||||||
// Only calculate viewport sizes if the images are constrained to a limited space.
|
// Only calculate viewport sizes if the images are constrained to a limited space.
|
||||||
// If they are Fill|Portion let them expand within their alotted space.
|
// If they are Fill|Portion let them expand within their alotted space.
|
||||||
match expansion_size {
|
match expansion_size {
|
||||||
Length::Shrink | Length::Units(_) => {
|
Length::Shrink | Length::Fixed(_) => {
|
||||||
let aspect_ratio = width as f32 / height as f32;
|
let aspect_ratio = width as f32 / height as f32;
|
||||||
let viewport_aspect_ratio = size.width / size.height;
|
let viewport_aspect_ratio = size.width / size.height;
|
||||||
if viewport_aspect_ratio > aspect_ratio {
|
if viewport_aspect_ratio > aspect_ratio {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
//! The [`pane_grid` example] showcases how to use a [`PaneGrid`] with resizing,
|
//! The [`pane_grid` example] showcases how to use a [`PaneGrid`] with resizing,
|
||||||
//! drag and drop, and hotkey support.
|
//! drag and drop, and hotkey support.
|
||||||
//!
|
//!
|
||||||
//! [`pane_grid` example]: https://github.com/iced-rs/iced/tree/0.7/examples/pane_grid
|
//! [`pane_grid` example]: https://github.com/iced-rs/iced/tree/0.8/examples/pane_grid
|
||||||
mod axis;
|
mod axis;
|
||||||
mod configuration;
|
mod configuration;
|
||||||
mod content;
|
mod content;
|
||||||
|
|
@ -42,8 +42,8 @@ use crate::widget;
|
||||||
use crate::widget::container;
|
use crate::widget::container;
|
||||||
use crate::widget::tree::{self, Tree};
|
use crate::widget::tree::{self, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Clipboard, Color, Element, Layout, Length, Point, Rectangle, Shell, Size,
|
Clipboard, Color, Element, Layout, Length, Pixels, Point, Rectangle, Shell,
|
||||||
Vector, Widget,
|
Size, Vector, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A collection of panes distributed using either vertical or horizontal splits
|
/// A collection of panes distributed using either vertical or horizontal splits
|
||||||
|
|
@ -104,10 +104,10 @@ where
|
||||||
contents: Contents<'a, Content<'a, Message, Renderer>>,
|
contents: Contents<'a, Content<'a, Message, Renderer>>,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
spacing: u16,
|
spacing: f32,
|
||||||
on_click: Option<Box<dyn Fn(Pane) -> Message + 'a>>,
|
on_click: Option<Box<dyn Fn(Pane) -> Message + 'a>>,
|
||||||
on_drag: Option<Box<dyn Fn(DragEvent) -> Message + 'a>>,
|
on_drag: Option<Box<dyn Fn(DragEvent) -> Message + 'a>>,
|
||||||
on_resize: Option<(u16, Box<dyn Fn(ResizeEvent) -> Message + 'a>)>,
|
on_resize: Option<(f32, Box<dyn Fn(ResizeEvent) -> Message + 'a>)>,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ where
|
||||||
contents,
|
contents,
|
||||||
width: Length::Fill,
|
width: Length::Fill,
|
||||||
height: Length::Fill,
|
height: Length::Fill,
|
||||||
spacing: 0,
|
spacing: 0.0,
|
||||||
on_click: None,
|
on_click: None,
|
||||||
on_drag: None,
|
on_drag: None,
|
||||||
on_resize: None,
|
on_resize: None,
|
||||||
|
|
@ -159,20 +159,20 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`PaneGrid`].
|
/// Sets the width of the [`PaneGrid`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`PaneGrid`].
|
/// Sets the height of the [`PaneGrid`].
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the spacing _between_ the panes of the [`PaneGrid`].
|
/// Sets the spacing _between_ the panes of the [`PaneGrid`].
|
||||||
pub fn spacing(mut self, units: u16) -> Self {
|
pub fn spacing(mut self, amount: impl Into<Pixels>) -> Self {
|
||||||
self.spacing = units;
|
self.spacing = amount.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,11 +205,11 @@ where
|
||||||
/// The grabbable area of a split will have a length of `spacing + leeway`,
|
/// The grabbable area of a split will have a length of `spacing + leeway`,
|
||||||
/// properly centered. In other words, a length of
|
/// properly centered. In other words, a length of
|
||||||
/// `(spacing + leeway) / 2.0` on either side of the split line.
|
/// `(spacing + leeway) / 2.0` on either side of the split line.
|
||||||
pub fn on_resize<F>(mut self, leeway: u16, f: F) -> Self
|
pub fn on_resize<F>(mut self, leeway: impl Into<Pixels>, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: 'a + Fn(ResizeEvent) -> Message,
|
F: 'a + Fn(ResizeEvent) -> Message,
|
||||||
{
|
{
|
||||||
self.on_resize = Some((leeway, Box::new(f)));
|
self.on_resize = Some((leeway.into().0, Box::new(f)));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -485,14 +485,14 @@ pub fn layout<Renderer, T>(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
spacing: u16,
|
spacing: f32,
|
||||||
contents: impl Iterator<Item = (Pane, T)>,
|
contents: impl Iterator<Item = (Pane, T)>,
|
||||||
layout_content: impl Fn(T, &Renderer, &layout::Limits) -> layout::Node,
|
layout_content: impl Fn(T, &Renderer, &layout::Limits) -> layout::Node,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
let limits = limits.width(width).height(height);
|
let limits = limits.width(width).height(height);
|
||||||
let size = limits.resolve(Size::ZERO);
|
let size = limits.resolve(Size::ZERO);
|
||||||
|
|
||||||
let regions = node.pane_regions(f32::from(spacing), size);
|
let regions = node.pane_regions(spacing, size);
|
||||||
let children = contents
|
let children = contents
|
||||||
.filter_map(|(pane, content)| {
|
.filter_map(|(pane, content)| {
|
||||||
let region = regions.get(&pane)?;
|
let region = regions.get(&pane)?;
|
||||||
|
|
@ -522,11 +522,11 @@ pub fn update<'a, Message, T: Draggable>(
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
shell: &mut Shell<'_, Message>,
|
shell: &mut Shell<'_, Message>,
|
||||||
spacing: u16,
|
spacing: f32,
|
||||||
contents: impl Iterator<Item = (Pane, T)>,
|
contents: impl Iterator<Item = (Pane, T)>,
|
||||||
on_click: &Option<Box<dyn Fn(Pane) -> Message + 'a>>,
|
on_click: &Option<Box<dyn Fn(Pane) -> Message + 'a>>,
|
||||||
on_drag: &Option<Box<dyn Fn(DragEvent) -> Message + 'a>>,
|
on_drag: &Option<Box<dyn Fn(DragEvent) -> Message + 'a>>,
|
||||||
on_resize: &Option<(u16, Box<dyn Fn(ResizeEvent) -> Message + 'a>)>,
|
on_resize: &Option<(f32, Box<dyn Fn(ResizeEvent) -> Message + 'a>)>,
|
||||||
) -> event::Status {
|
) -> event::Status {
|
||||||
let mut event_status = event::Status::Ignored;
|
let mut event_status = event::Status::Ignored;
|
||||||
|
|
||||||
|
|
@ -546,13 +546,13 @@ pub fn update<'a, Message, T: Draggable>(
|
||||||
);
|
);
|
||||||
|
|
||||||
let splits = node.split_regions(
|
let splits = node.split_regions(
|
||||||
f32::from(spacing),
|
spacing,
|
||||||
Size::new(bounds.width, bounds.height),
|
Size::new(bounds.width, bounds.height),
|
||||||
);
|
);
|
||||||
|
|
||||||
let clicked_split = hovered_split(
|
let clicked_split = hovered_split(
|
||||||
splits.iter(),
|
splits.iter(),
|
||||||
f32::from(spacing + leeway),
|
spacing + leeway,
|
||||||
relative_cursor,
|
relative_cursor,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -624,7 +624,7 @@ pub fn update<'a, Message, T: Draggable>(
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
|
|
||||||
let splits = node.split_regions(
|
let splits = node.split_regions(
|
||||||
f32::from(spacing),
|
spacing,
|
||||||
Size::new(bounds.width, bounds.height),
|
Size::new(bounds.width, bounds.height),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -698,8 +698,8 @@ pub fn mouse_interaction(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
spacing: u16,
|
spacing: f32,
|
||||||
resize_leeway: Option<u16>,
|
resize_leeway: Option<f32>,
|
||||||
) -> Option<mouse::Interaction> {
|
) -> Option<mouse::Interaction> {
|
||||||
if action.picked_pane().is_some() {
|
if action.picked_pane().is_some() {
|
||||||
return Some(mouse::Interaction::Grabbing);
|
return Some(mouse::Interaction::Grabbing);
|
||||||
|
|
@ -710,20 +710,15 @@ pub fn mouse_interaction(
|
||||||
resize_leeway.and_then(|leeway| {
|
resize_leeway.and_then(|leeway| {
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
|
|
||||||
let splits =
|
let splits = node.split_regions(spacing, bounds.size());
|
||||||
node.split_regions(f32::from(spacing), bounds.size());
|
|
||||||
|
|
||||||
let relative_cursor = Point::new(
|
let relative_cursor = Point::new(
|
||||||
cursor_position.x - bounds.x,
|
cursor_position.x - bounds.x,
|
||||||
cursor_position.y - bounds.y,
|
cursor_position.y - bounds.y,
|
||||||
);
|
);
|
||||||
|
|
||||||
hovered_split(
|
hovered_split(splits.iter(), spacing + leeway, relative_cursor)
|
||||||
splits.iter(),
|
.map(|(_, axis, _)| axis)
|
||||||
f32::from(spacing + leeway),
|
|
||||||
relative_cursor,
|
|
||||||
)
|
|
||||||
.map(|(_, axis, _)| axis)
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -747,8 +742,8 @@ pub fn draw<Renderer, T>(
|
||||||
theme: &Renderer::Theme,
|
theme: &Renderer::Theme,
|
||||||
default_style: &renderer::Style,
|
default_style: &renderer::Style,
|
||||||
viewport: &Rectangle,
|
viewport: &Rectangle,
|
||||||
spacing: u16,
|
spacing: f32,
|
||||||
resize_leeway: Option<u16>,
|
resize_leeway: Option<f32>,
|
||||||
style: &<Renderer::Theme as StyleSheet>::Style,
|
style: &<Renderer::Theme as StyleSheet>::Style,
|
||||||
contents: impl Iterator<Item = (Pane, T)>,
|
contents: impl Iterator<Item = (Pane, T)>,
|
||||||
draw_pane: impl Fn(
|
draw_pane: impl Fn(
|
||||||
|
|
@ -770,12 +765,11 @@ pub fn draw<Renderer, T>(
|
||||||
.and_then(|(split, axis)| {
|
.and_then(|(split, axis)| {
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
|
|
||||||
let splits = node.split_regions(f32::from(spacing), bounds.size());
|
let splits = node.split_regions(spacing, bounds.size());
|
||||||
|
|
||||||
let (_axis, region, ratio) = splits.get(&split)?;
|
let (_axis, region, ratio) = splits.get(&split)?;
|
||||||
|
|
||||||
let region =
|
let region = axis.split_line_bounds(*region, *ratio, spacing);
|
||||||
axis.split_line_bounds(*region, *ratio, f32::from(spacing));
|
|
||||||
|
|
||||||
Some((axis, region + Vector::new(bounds.x, bounds.y), true))
|
Some((axis, region + Vector::new(bounds.x, bounds.y), true))
|
||||||
})
|
})
|
||||||
|
|
@ -788,12 +782,11 @@ pub fn draw<Renderer, T>(
|
||||||
cursor_position.y - bounds.y,
|
cursor_position.y - bounds.y,
|
||||||
);
|
);
|
||||||
|
|
||||||
let splits =
|
let splits = node.split_regions(spacing, bounds.size());
|
||||||
node.split_regions(f32::from(spacing), bounds.size());
|
|
||||||
|
|
||||||
let (_split, axis, region) = hovered_split(
|
let (_split, axis, region) = hovered_split(
|
||||||
splits.iter(),
|
splits.iter(),
|
||||||
f32::from(spacing + leeway),
|
spacing + leeway,
|
||||||
relative_cursor,
|
relative_cursor,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -249,10 +249,7 @@ where
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
node.move_to(Point::new(
|
node.move_to(Point::new(self.padding.left, self.padding.top));
|
||||||
self.padding.left.into(),
|
|
||||||
self.padding.top.into(),
|
|
||||||
));
|
|
||||||
|
|
||||||
layout::Node::with_children(node.size().pad(self.padding), vec![node])
|
layout::Node::with_children(node.size().pad(self.padding), vec![node])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,67 +13,13 @@ use crate::widget::container;
|
||||||
use crate::widget::scrollable;
|
use crate::widget::scrollable;
|
||||||
use crate::widget::tree::{self, Tree};
|
use crate::widget::tree::{self, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Size,
|
Clipboard, Element, Layout, Length, Padding, Pixels, Point, Rectangle,
|
||||||
Widget,
|
Shell, Size, Widget,
|
||||||
};
|
};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub use iced_style::pick_list::{Appearance, StyleSheet};
|
pub use iced_style::pick_list::{Appearance, StyleSheet};
|
||||||
|
|
||||||
/// The handle to the right side of the [`PickList`].
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub enum Handle<Renderer>
|
|
||||||
where
|
|
||||||
Renderer: text::Renderer,
|
|
||||||
{
|
|
||||||
/// Displays an arrow icon (▼).
|
|
||||||
///
|
|
||||||
/// This is the default.
|
|
||||||
Arrow {
|
|
||||||
/// Font size of the content.
|
|
||||||
size: Option<u16>,
|
|
||||||
},
|
|
||||||
/// A custom handle.
|
|
||||||
Custom {
|
|
||||||
/// Font that will be used to display the `text`,
|
|
||||||
font: Renderer::Font,
|
|
||||||
/// Text that will be shown.
|
|
||||||
text: String,
|
|
||||||
/// Font size of the content.
|
|
||||||
size: Option<u16>,
|
|
||||||
},
|
|
||||||
/// No handle will be shown.
|
|
||||||
None,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Renderer> Default for Handle<Renderer>
|
|
||||||
where
|
|
||||||
Renderer: text::Renderer,
|
|
||||||
{
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Arrow { size: None }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Renderer> Handle<Renderer>
|
|
||||||
where
|
|
||||||
Renderer: text::Renderer,
|
|
||||||
{
|
|
||||||
fn content(&self) -> Option<(Renderer::Font, String, Option<u16>)> {
|
|
||||||
match self {
|
|
||||||
Self::Arrow { size } => Some((
|
|
||||||
Renderer::ICON_FONT,
|
|
||||||
Renderer::ARROW_DOWN_ICON.to_string(),
|
|
||||||
*size,
|
|
||||||
)),
|
|
||||||
Self::Custom { font, text, size } => {
|
|
||||||
Some((font.clone(), text.clone(), *size))
|
|
||||||
}
|
|
||||||
Self::None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A widget for selecting a single value from a list of options.
|
/// A widget for selecting a single value from a list of options.
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct PickList<'a, T, Message, Renderer>
|
pub struct PickList<'a, T, Message, Renderer>
|
||||||
|
|
@ -88,9 +34,9 @@ where
|
||||||
selected: Option<T>,
|
selected: Option<T>,
|
||||||
width: Length,
|
width: Length,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
text_size: Option<u16>,
|
text_size: Option<f32>,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
handle: Handle<Renderer>,
|
handle: Handle<Renderer::Font>,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,7 +53,7 @@ where
|
||||||
From<<Renderer::Theme as StyleSheet>::Style>,
|
From<<Renderer::Theme as StyleSheet>::Style>,
|
||||||
{
|
{
|
||||||
/// The default padding of a [`PickList`].
|
/// The default padding of a [`PickList`].
|
||||||
pub const DEFAULT_PADDING: Padding = Padding::new(5);
|
pub const DEFAULT_PADDING: Padding = Padding::new(5.0);
|
||||||
|
|
||||||
/// Creates a new [`PickList`] with the given list of options, the current
|
/// Creates a new [`PickList`] with the given list of options, the current
|
||||||
/// selected value, and the message to produce when an option is selected.
|
/// selected value, and the message to produce when an option is selected.
|
||||||
|
|
@ -137,8 +83,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`PickList`].
|
/// Sets the width of the [`PickList`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,8 +95,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the text size of the [`PickList`].
|
/// Sets the text size of the [`PickList`].
|
||||||
pub fn text_size(mut self, size: u16) -> Self {
|
pub fn text_size(mut self, size: impl Into<Pixels>) -> Self {
|
||||||
self.text_size = Some(size);
|
self.text_size = Some(size.into().0);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -161,7 +107,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`Handle`] of the [`PickList`].
|
/// Sets the [`Handle`] of the [`PickList`].
|
||||||
pub fn handle(mut self, handle: Handle<Renderer>) -> Self {
|
pub fn handle(mut self, handle: Handle<Renderer::Font>) -> Self {
|
||||||
self.handle = handle;
|
self.handle = handle;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
@ -258,7 +204,7 @@ where
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
_tree: &Tree,
|
tree: &Tree,
|
||||||
renderer: &mut Renderer,
|
renderer: &mut Renderer,
|
||||||
theme: &Renderer::Theme,
|
theme: &Renderer::Theme,
|
||||||
_style: &renderer::Style,
|
_style: &renderer::Style,
|
||||||
|
|
@ -278,6 +224,7 @@ where
|
||||||
self.selected.as_ref(),
|
self.selected.as_ref(),
|
||||||
&self.handle,
|
&self.handle,
|
||||||
&self.style,
|
&self.style,
|
||||||
|
|| tree.state.downcast_ref::<State<T>>(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -349,13 +296,53 @@ impl<T> Default for State<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The handle to the right side of the [`PickList`].
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum Handle<Font> {
|
||||||
|
/// Displays an arrow icon (▼).
|
||||||
|
///
|
||||||
|
/// This is the default.
|
||||||
|
Arrow {
|
||||||
|
/// Font size of the content.
|
||||||
|
size: Option<f32>,
|
||||||
|
},
|
||||||
|
/// A custom static handle.
|
||||||
|
Static(Icon<Font>),
|
||||||
|
/// A custom dynamic handle.
|
||||||
|
Dynamic {
|
||||||
|
/// The [`Icon`] used when [`PickList`] is closed.
|
||||||
|
closed: Icon<Font>,
|
||||||
|
/// The [`Icon`] used when [`PickList`] is open.
|
||||||
|
open: Icon<Font>,
|
||||||
|
},
|
||||||
|
/// No handle will be shown.
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Font> Default for Handle<Font> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Arrow { size: None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The icon of a [`Handle`].
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct Icon<Font> {
|
||||||
|
/// Font that will be used to display the `code_point`,
|
||||||
|
pub font: Font,
|
||||||
|
/// The unicode code point that will be used as the icon.
|
||||||
|
pub code_point: char,
|
||||||
|
/// Font size of the content.
|
||||||
|
pub size: Option<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Computes the layout of a [`PickList`].
|
/// Computes the layout of a [`PickList`].
|
||||||
pub fn layout<Renderer, T>(
|
pub fn layout<Renderer, T>(
|
||||||
renderer: &Renderer,
|
renderer: &Renderer,
|
||||||
limits: &layout::Limits,
|
limits: &layout::Limits,
|
||||||
width: Length,
|
width: Length,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
text_size: Option<u16>,
|
text_size: Option<f32>,
|
||||||
font: &Renderer::Font,
|
font: &Renderer::Font,
|
||||||
placeholder: Option<&str>,
|
placeholder: Option<&str>,
|
||||||
options: &[T],
|
options: &[T],
|
||||||
|
|
@ -367,12 +354,11 @@ where
|
||||||
use std::f32;
|
use std::f32;
|
||||||
|
|
||||||
let limits = limits.width(width).height(Length::Shrink).pad(padding);
|
let limits = limits.width(width).height(Length::Shrink).pad(padding);
|
||||||
|
|
||||||
let text_size = text_size.unwrap_or_else(|| renderer.default_size());
|
let text_size = text_size.unwrap_or_else(|| renderer.default_size());
|
||||||
|
|
||||||
let max_width = match width {
|
let max_width = match width {
|
||||||
Length::Shrink => {
|
Length::Shrink => {
|
||||||
let measure = |label: &str| -> u32 {
|
let measure = |label: &str| -> f32 {
|
||||||
let (width, _) = renderer.measure(
|
let (width, _) = renderer.measure(
|
||||||
label,
|
label,
|
||||||
text_size,
|
text_size,
|
||||||
|
|
@ -380,26 +366,25 @@ where
|
||||||
Size::new(f32::INFINITY, f32::INFINITY),
|
Size::new(f32::INFINITY, f32::INFINITY),
|
||||||
);
|
);
|
||||||
|
|
||||||
width.round() as u32
|
width.round()
|
||||||
};
|
};
|
||||||
|
|
||||||
let labels = options.iter().map(ToString::to_string);
|
let labels = options.iter().map(ToString::to_string);
|
||||||
|
|
||||||
let labels_width =
|
let labels_width = labels
|
||||||
labels.map(|label| measure(&label)).max().unwrap_or(100);
|
.map(|label| measure(&label))
|
||||||
|
.fold(100.0, |candidate, current| current.max(candidate));
|
||||||
|
|
||||||
let placeholder_width = placeholder.map(measure).unwrap_or(100);
|
let placeholder_width = placeholder.map(measure).unwrap_or(100.0);
|
||||||
|
|
||||||
labels_width.max(placeholder_width)
|
labels_width.max(placeholder_width)
|
||||||
}
|
}
|
||||||
_ => 0,
|
_ => 0.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let size = {
|
let size = {
|
||||||
let intrinsic = Size::new(
|
let intrinsic =
|
||||||
max_width as f32 + f32::from(text_size) + f32::from(padding.left),
|
Size::new(max_width + text_size + padding.left, text_size);
|
||||||
f32::from(text_size),
|
|
||||||
);
|
|
||||||
|
|
||||||
limits.resolve(intrinsic).pad(padding)
|
limits.resolve(intrinsic).pad(padding)
|
||||||
};
|
};
|
||||||
|
|
@ -527,7 +512,7 @@ pub fn overlay<'a, T, Message, Renderer>(
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
state: &'a mut State<T>,
|
state: &'a mut State<T>,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
text_size: Option<u16>,
|
text_size: Option<f32>,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
options: &'a [T],
|
options: &'a [T],
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
|
|
@ -552,7 +537,7 @@ where
|
||||||
&mut state.hovered_option,
|
&mut state.hovered_option,
|
||||||
&mut state.last_selection,
|
&mut state.last_selection,
|
||||||
)
|
)
|
||||||
.width(bounds.width.round() as u16)
|
.width(bounds.width)
|
||||||
.padding(padding)
|
.padding(padding)
|
||||||
.font(font)
|
.font(font)
|
||||||
.style(style);
|
.style(style);
|
||||||
|
|
@ -568,22 +553,23 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draws a [`PickList`].
|
/// Draws a [`PickList`].
|
||||||
pub fn draw<T, Renderer>(
|
pub fn draw<'a, T, Renderer>(
|
||||||
renderer: &mut Renderer,
|
renderer: &mut Renderer,
|
||||||
theme: &Renderer::Theme,
|
theme: &Renderer::Theme,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
text_size: Option<u16>,
|
text_size: Option<f32>,
|
||||||
font: &Renderer::Font,
|
font: &Renderer::Font,
|
||||||
placeholder: Option<&str>,
|
placeholder: Option<&str>,
|
||||||
selected: Option<&T>,
|
selected: Option<&T>,
|
||||||
handle: &Handle<Renderer>,
|
handle: &Handle<Renderer::Font>,
|
||||||
style: &<Renderer::Theme as StyleSheet>::Style,
|
style: &<Renderer::Theme as StyleSheet>::Style,
|
||||||
|
state: impl FnOnce() -> &'a State<T>,
|
||||||
) where
|
) where
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
T: ToString,
|
T: ToString + 'a,
|
||||||
{
|
{
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
let is_mouse_over = bounds.contains(cursor_position);
|
let is_mouse_over = bounds.contains(cursor_position);
|
||||||
|
|
@ -605,16 +591,35 @@ pub fn draw<T, Renderer>(
|
||||||
style.background,
|
style.background,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some((font, text, size)) = handle.content() {
|
let handle = match handle {
|
||||||
let size = f32::from(size.unwrap_or_else(|| renderer.default_size()));
|
Handle::Arrow { size } => {
|
||||||
|
Some((Renderer::ICON_FONT, Renderer::ARROW_DOWN_ICON, *size))
|
||||||
|
}
|
||||||
|
Handle::Static(Icon {
|
||||||
|
font,
|
||||||
|
code_point,
|
||||||
|
size,
|
||||||
|
}) => Some((font.clone(), *code_point, *size)),
|
||||||
|
Handle::Dynamic { open, closed } => {
|
||||||
|
if state().is_open {
|
||||||
|
Some((open.font.clone(), open.code_point, open.size))
|
||||||
|
} else {
|
||||||
|
Some((closed.font.clone(), closed.code_point, closed.size))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Handle::None => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some((font, code_point, size)) = handle {
|
||||||
|
let size = size.unwrap_or_else(|| renderer.default_size());
|
||||||
|
|
||||||
renderer.fill_text(Text {
|
renderer.fill_text(Text {
|
||||||
content: &text,
|
content: &code_point.to_string(),
|
||||||
size,
|
size,
|
||||||
font,
|
font,
|
||||||
color: style.handle_color,
|
color: style.handle_color,
|
||||||
bounds: Rectangle {
|
bounds: Rectangle {
|
||||||
x: bounds.x + bounds.width - f32::from(padding.horizontal()),
|
x: bounds.x + bounds.width - padding.horizontal(),
|
||||||
y: bounds.center_y() - size / 2.0,
|
y: bounds.center_y() - size / 2.0,
|
||||||
height: size,
|
height: size,
|
||||||
..bounds
|
..bounds
|
||||||
|
|
@ -627,8 +632,7 @@ pub fn draw<T, Renderer>(
|
||||||
let label = selected.map(ToString::to_string);
|
let label = selected.map(ToString::to_string);
|
||||||
|
|
||||||
if let Some(label) = label.as_deref().or(placeholder) {
|
if let Some(label) = label.as_deref().or(placeholder) {
|
||||||
let text_size =
|
let text_size = text_size.unwrap_or_else(|| renderer.default_size());
|
||||||
f32::from(text_size.unwrap_or_else(|| renderer.default_size()));
|
|
||||||
|
|
||||||
renderer.fill_text(Text {
|
renderer.fill_text(Text {
|
||||||
content: label,
|
content: label,
|
||||||
|
|
@ -640,9 +644,9 @@ pub fn draw<T, Renderer>(
|
||||||
style.placeholder_color
|
style.placeholder_color
|
||||||
},
|
},
|
||||||
bounds: Rectangle {
|
bounds: Rectangle {
|
||||||
x: bounds.x + f32::from(padding.left),
|
x: bounds.x + padding.left,
|
||||||
y: bounds.center_y() - text_size / 2.0,
|
y: bounds.center_y() - text_size / 2.0,
|
||||||
width: bounds.width - f32::from(padding.horizontal()),
|
width: bounds.width - padding.horizontal(),
|
||||||
height: text_size,
|
height: text_size,
|
||||||
},
|
},
|
||||||
horizontal_alignment: alignment::Horizontal::Left,
|
horizontal_alignment: alignment::Horizontal::Left,
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ where
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
/// The default height of a [`ProgressBar`].
|
/// The default height of a [`ProgressBar`].
|
||||||
pub const DEFAULT_HEIGHT: u16 = 30;
|
pub const DEFAULT_HEIGHT: f32 = 30.0;
|
||||||
|
|
||||||
/// Creates a new [`ProgressBar`].
|
/// Creates a new [`ProgressBar`].
|
||||||
///
|
///
|
||||||
|
|
@ -56,14 +56,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`ProgressBar`].
|
/// Sets the width of the [`ProgressBar`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`ProgressBar`].
|
/// Sets the height of the [`ProgressBar`].
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = Some(height);
|
self.height = Some(height.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn height(&self) -> Length {
|
fn height(&self) -> Length {
|
||||||
self.height.unwrap_or(Length::Units(Self::DEFAULT_HEIGHT))
|
self.height.unwrap_or(Length::Fixed(Self::DEFAULT_HEIGHT))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout(
|
fn layout(
|
||||||
|
|
@ -97,7 +97,7 @@ where
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
let limits = limits
|
let limits = limits
|
||||||
.width(self.width)
|
.width(self.width)
|
||||||
.height(self.height.unwrap_or(Length::Units(Self::DEFAULT_HEIGHT)));
|
.height(self.height.unwrap_or(Length::Fixed(Self::DEFAULT_HEIGHT)));
|
||||||
|
|
||||||
let size = limits.resolve(Size::ZERO);
|
let size = limits.resolve(Size::ZERO);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ use crate::text;
|
||||||
use crate::touch;
|
use crate::touch;
|
||||||
use crate::widget::{self, Row, Text, Tree};
|
use crate::widget::{self, Row, Text, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Alignment, Clipboard, Color, Element, Layout, Length, Point, Rectangle,
|
Alignment, Clipboard, Color, Element, Layout, Length, Pixels, Point,
|
||||||
Shell, Widget,
|
Rectangle, Shell, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use iced_style::radio::{Appearance, StyleSheet};
|
pub use iced_style::radio::{Appearance, StyleSheet};
|
||||||
|
|
@ -50,9 +50,9 @@ where
|
||||||
on_click: Message,
|
on_click: Message,
|
||||||
label: String,
|
label: String,
|
||||||
width: Length,
|
width: Length,
|
||||||
size: u16,
|
size: f32,
|
||||||
spacing: u16,
|
spacing: f32,
|
||||||
text_size: Option<u16>,
|
text_size: Option<f32>,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
@ -64,10 +64,10 @@ where
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
/// The default size of a [`Radio`] button.
|
/// The default size of a [`Radio`] button.
|
||||||
pub const DEFAULT_SIZE: u16 = 28;
|
pub const DEFAULT_SIZE: f32 = 28.0;
|
||||||
|
|
||||||
/// The default spacing of a [`Radio`] button.
|
/// The default spacing of a [`Radio`] button.
|
||||||
pub const DEFAULT_SPACING: u16 = 15;
|
pub const DEFAULT_SPACING: f32 = 15.0;
|
||||||
|
|
||||||
/// Creates a new [`Radio`] button.
|
/// Creates a new [`Radio`] button.
|
||||||
///
|
///
|
||||||
|
|
@ -101,26 +101,26 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the size of the [`Radio`] button.
|
/// Sets the size of the [`Radio`] button.
|
||||||
pub fn size(mut self, size: u16) -> Self {
|
pub fn size(mut self, size: impl Into<Pixels>) -> Self {
|
||||||
self.size = size;
|
self.size = size.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Radio`] button.
|
/// Sets the width of the [`Radio`] button.
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the spacing between the [`Radio`] button and the text.
|
/// Sets the spacing between the [`Radio`] button and the text.
|
||||||
pub fn spacing(mut self, spacing: u16) -> Self {
|
pub fn spacing(mut self, spacing: impl Into<Pixels>) -> Self {
|
||||||
self.spacing = spacing;
|
self.spacing = spacing.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the text size of the [`Radio`] button.
|
/// Sets the text size of the [`Radio`] button.
|
||||||
pub fn text_size(mut self, text_size: u16) -> Self {
|
pub fn text_size(mut self, text_size: impl Into<Pixels>) -> Self {
|
||||||
self.text_size = Some(text_size);
|
self.text_size = Some(text_size.into().0);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,11 +163,7 @@ where
|
||||||
.width(self.width)
|
.width(self.width)
|
||||||
.spacing(self.spacing)
|
.spacing(self.spacing)
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.push(
|
.push(Row::new().width(self.size).height(self.size))
|
||||||
Row::new()
|
|
||||||
.width(Length::Units(self.size))
|
|
||||||
.height(Length::Units(self.size)),
|
|
||||||
)
|
|
||||||
.push(Text::new(&self.label).width(self.width).size(
|
.push(Text::new(&self.label).width(self.width).size(
|
||||||
self.text_size.unwrap_or_else(|| renderer.default_size()),
|
self.text_size.unwrap_or_else(|| renderer.default_size()),
|
||||||
))
|
))
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@ use crate::overlay;
|
||||||
use crate::renderer;
|
use crate::renderer;
|
||||||
use crate::widget::{Operation, Tree};
|
use crate::widget::{Operation, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Alignment, Clipboard, Element, Length, Padding, Point, Rectangle, Shell,
|
Alignment, Clipboard, Element, Length, Padding, Pixels, Point, Rectangle,
|
||||||
Widget,
|
Shell, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A container that distributes its contents horizontally.
|
/// A container that distributes its contents horizontally.
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Row<'a, Message, Renderer> {
|
pub struct Row<'a, Message, Renderer> {
|
||||||
spacing: u16,
|
spacing: f32,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
|
|
@ -32,7 +32,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
|
||||||
children: Vec<Element<'a, Message, Renderer>>,
|
children: Vec<Element<'a, Message, Renderer>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Row {
|
Row {
|
||||||
spacing: 0,
|
spacing: 0.0,
|
||||||
padding: Padding::ZERO,
|
padding: Padding::ZERO,
|
||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
|
|
@ -46,8 +46,8 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
|
||||||
/// Custom margins per element do not exist in iced. You should use this
|
/// Custom margins per element do not exist in iced. You should use this
|
||||||
/// method instead! While less flexible, it helps you keep spacing between
|
/// method instead! While less flexible, it helps you keep spacing between
|
||||||
/// elements consistent.
|
/// elements consistent.
|
||||||
pub fn spacing(mut self, units: u16) -> Self {
|
pub fn spacing(mut self, amount: impl Into<Pixels>) -> Self {
|
||||||
self.spacing = units;
|
self.spacing = amount.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,14 +58,14 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Row`].
|
/// Sets the width of the [`Row`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`Row`].
|
/// Sets the height of the [`Row`].
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +124,7 @@ where
|
||||||
renderer,
|
renderer,
|
||||||
&limits,
|
&limits,
|
||||||
self.padding,
|
self.padding,
|
||||||
self.spacing as f32,
|
self.spacing,
|
||||||
self.align_items,
|
self.align_items,
|
||||||
&self.children,
|
&self.children,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
use crate::layout;
|
use crate::layout;
|
||||||
use crate::renderer;
|
use crate::renderer;
|
||||||
use crate::widget::Tree;
|
use crate::widget::Tree;
|
||||||
use crate::{Color, Element, Layout, Length, Point, Rectangle, Size, Widget};
|
use crate::{
|
||||||
|
Color, Element, Layout, Length, Pixels, Point, Rectangle, Size, Widget,
|
||||||
|
};
|
||||||
|
|
||||||
pub use iced_style::rule::{Appearance, FillMode, StyleSheet};
|
pub use iced_style::rule::{Appearance, FillMode, StyleSheet};
|
||||||
|
|
||||||
|
|
@ -25,19 +27,19 @@ where
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
/// Creates a horizontal [`Rule`] with the given height.
|
/// Creates a horizontal [`Rule`] with the given height.
|
||||||
pub fn horizontal(height: u16) -> Self {
|
pub fn horizontal(height: impl Into<Pixels>) -> Self {
|
||||||
Rule {
|
Rule {
|
||||||
width: Length::Fill,
|
width: Length::Fill,
|
||||||
height: Length::Units(height),
|
height: Length::Fixed(height.into().0),
|
||||||
is_horizontal: true,
|
is_horizontal: true,
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a vertical [`Rule`] with the given width.
|
/// Creates a vertical [`Rule`] with the given width.
|
||||||
pub fn vertical(width: u16) -> Self {
|
pub fn vertical(width: impl Into<Pixels>) -> Self {
|
||||||
Rule {
|
Rule {
|
||||||
width: Length::Units(width),
|
width: Length::Fixed(width.into().0),
|
||||||
height: Length::Fill,
|
height: Length::Fill,
|
||||||
is_horizontal: false,
|
is_horizontal: false,
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ use crate::widget;
|
||||||
use crate::widget::operation::{self, Operation};
|
use crate::widget::operation::{self, Operation};
|
||||||
use crate::widget::tree::{self, Tree};
|
use crate::widget::tree::{self, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Background, Clipboard, Color, Command, Element, Layout, Length, Point,
|
Background, Clipboard, Color, Command, Element, Layout, Length, Pixels,
|
||||||
Rectangle, Shell, Size, Vector, Widget,
|
Point, Rectangle, Shell, Size, Vector, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use iced_style::scrollable::StyleSheet;
|
pub use iced_style::scrollable::StyleSheet;
|
||||||
|
|
@ -66,8 +66,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`Scrollable`].
|
/// Sets the height of the [`Scrollable`].
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,17 +108,17 @@ where
|
||||||
/// Properties of a scrollbar within a [`Scrollable`].
|
/// Properties of a scrollbar within a [`Scrollable`].
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Properties {
|
pub struct Properties {
|
||||||
width: u16,
|
width: f32,
|
||||||
margin: u16,
|
margin: f32,
|
||||||
scroller_width: u16,
|
scroller_width: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Properties {
|
impl Default for Properties {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
width: 10,
|
width: 10.0,
|
||||||
margin: 0,
|
margin: 0.0,
|
||||||
scroller_width: 10,
|
scroller_width: 10.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -131,21 +131,21 @@ impl Properties {
|
||||||
|
|
||||||
/// Sets the scrollbar width of the [`Scrollable`] .
|
/// Sets the scrollbar width of the [`Scrollable`] .
|
||||||
/// Silently enforces a minimum width of 1.
|
/// Silently enforces a minimum width of 1.
|
||||||
pub fn width(mut self, width: u16) -> Self {
|
pub fn width(mut self, width: impl Into<Pixels>) -> Self {
|
||||||
self.width = width.max(1);
|
self.width = width.into().0.max(1.0);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the scrollbar margin of the [`Scrollable`] .
|
/// Sets the scrollbar margin of the [`Scrollable`] .
|
||||||
pub fn margin(mut self, margin: u16) -> Self {
|
pub fn margin(mut self, margin: impl Into<Pixels>) -> Self {
|
||||||
self.margin = margin;
|
self.margin = margin.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the scroller width of the [`Scrollable`] .
|
/// Sets the scroller width of the [`Scrollable`] .
|
||||||
/// Silently enforces a minimum width of 1.
|
/// Silently enforces a minimum width of 1.
|
||||||
pub fn scroller_width(mut self, scroller_width: u16) -> Self {
|
pub fn scroller_width(mut self, scroller_width: impl Into<Pixels>) -> Self {
|
||||||
self.scroller_width = scroller_width.max(1);
|
self.scroller_width = scroller_width.into().0.max(1.0);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -208,14 +208,17 @@ where
|
||||||
|
|
||||||
operation.scrollable(state, self.id.as_ref().map(|id| &id.0));
|
operation.scrollable(state, self.id.as_ref().map(|id| &id.0));
|
||||||
|
|
||||||
operation.container(None, &mut |operation| {
|
operation.container(
|
||||||
self.content.as_widget().operate(
|
self.id.as_ref().map(|id| &id.0),
|
||||||
&mut tree.children[0],
|
&mut |operation| {
|
||||||
layout.children().next().unwrap(),
|
self.content.as_widget().operate(
|
||||||
renderer,
|
&mut tree.children[0],
|
||||||
operation,
|
layout.children().next().unwrap(),
|
||||||
);
|
renderer,
|
||||||
});
|
operation,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(
|
fn on_event(
|
||||||
|
|
@ -395,11 +398,11 @@ pub fn layout<Renderer>(
|
||||||
layout_content: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node,
|
layout_content: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
let limits = limits
|
let limits = limits
|
||||||
.max_height(u32::MAX)
|
.max_height(f32::INFINITY)
|
||||||
.max_width(if horizontal_enabled {
|
.max_width(if horizontal_enabled {
|
||||||
u32::MAX
|
f32::INFINITY
|
||||||
} else {
|
} else {
|
||||||
limits.max().width as u32
|
limits.max().width
|
||||||
})
|
})
|
||||||
.width(width)
|
.width(width)
|
||||||
.height(height);
|
.height(height);
|
||||||
|
|
@ -1101,26 +1104,27 @@ impl Scrollbars {
|
||||||
|
|
||||||
// Adjust the height of the vertical scrollbar if the horizontal scrollbar
|
// Adjust the height of the vertical scrollbar if the horizontal scrollbar
|
||||||
// is present
|
// is present
|
||||||
let x_scrollbar_height = show_scrollbar_x.map_or(0.0, |h| {
|
let x_scrollbar_height = show_scrollbar_x
|
||||||
(h.width.max(h.scroller_width) + h.margin) as f32
|
.map_or(0.0, |h| h.width.max(h.scroller_width) + h.margin);
|
||||||
});
|
|
||||||
|
|
||||||
let total_scrollbar_width = width.max(scroller_width) + 2 * margin;
|
let total_scrollbar_width =
|
||||||
|
width.max(scroller_width) + 2.0 * margin;
|
||||||
|
|
||||||
// Total bounds of the scrollbar + margin + scroller width
|
// Total bounds of the scrollbar + margin + scroller width
|
||||||
let total_scrollbar_bounds = Rectangle {
|
let total_scrollbar_bounds = Rectangle {
|
||||||
x: bounds.x + bounds.width - total_scrollbar_width as f32,
|
x: bounds.x + bounds.width - total_scrollbar_width,
|
||||||
y: bounds.y,
|
y: bounds.y,
|
||||||
width: total_scrollbar_width as f32,
|
width: total_scrollbar_width,
|
||||||
height: (bounds.height - x_scrollbar_height).max(0.0),
|
height: (bounds.height - x_scrollbar_height).max(0.0),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Bounds of just the scrollbar
|
// Bounds of just the scrollbar
|
||||||
let scrollbar_bounds = Rectangle {
|
let scrollbar_bounds = Rectangle {
|
||||||
x: bounds.x + bounds.width
|
x: bounds.x + bounds.width
|
||||||
- f32::from(total_scrollbar_width / 2 + width / 2),
|
- total_scrollbar_width / 2.0
|
||||||
|
- width / 2.0,
|
||||||
y: bounds.y,
|
y: bounds.y,
|
||||||
width: width as f32,
|
width,
|
||||||
height: (bounds.height - x_scrollbar_height).max(0.0),
|
height: (bounds.height - x_scrollbar_height).max(0.0),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1131,10 +1135,11 @@ impl Scrollbars {
|
||||||
|
|
||||||
let scroller_bounds = Rectangle {
|
let scroller_bounds = Rectangle {
|
||||||
x: bounds.x + bounds.width
|
x: bounds.x + bounds.width
|
||||||
- f32::from(total_scrollbar_width / 2 + scroller_width / 2),
|
- total_scrollbar_width / 2.0
|
||||||
|
- scroller_width / 2.0,
|
||||||
y: (scrollbar_bounds.y + scroller_offset - x_scrollbar_height)
|
y: (scrollbar_bounds.y + scroller_offset - x_scrollbar_height)
|
||||||
.max(0.0),
|
.max(0.0),
|
||||||
width: scroller_width as f32,
|
width: scroller_width,
|
||||||
height: scroller_height,
|
height: scroller_height,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1159,27 +1164,28 @@ impl Scrollbars {
|
||||||
// Need to adjust the width of the horizontal scrollbar if the vertical scrollbar
|
// Need to adjust the width of the horizontal scrollbar if the vertical scrollbar
|
||||||
// is present
|
// is present
|
||||||
let scrollbar_y_width = y_scrollbar.map_or(0.0, |_| {
|
let scrollbar_y_width = y_scrollbar.map_or(0.0, |_| {
|
||||||
(vertical.width.max(vertical.scroller_width) + vertical.margin)
|
vertical.width.max(vertical.scroller_width) + vertical.margin
|
||||||
as f32
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let total_scrollbar_height = width.max(scroller_width) + 2 * margin;
|
let total_scrollbar_height =
|
||||||
|
width.max(scroller_width) + 2.0 * margin;
|
||||||
|
|
||||||
// Total bounds of the scrollbar + margin + scroller width
|
// Total bounds of the scrollbar + margin + scroller width
|
||||||
let total_scrollbar_bounds = Rectangle {
|
let total_scrollbar_bounds = Rectangle {
|
||||||
x: bounds.x,
|
x: bounds.x,
|
||||||
y: bounds.y + bounds.height - total_scrollbar_height as f32,
|
y: bounds.y + bounds.height - total_scrollbar_height,
|
||||||
width: (bounds.width - scrollbar_y_width).max(0.0),
|
width: (bounds.width - scrollbar_y_width).max(0.0),
|
||||||
height: total_scrollbar_height as f32,
|
height: total_scrollbar_height,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Bounds of just the scrollbar
|
// Bounds of just the scrollbar
|
||||||
let scrollbar_bounds = Rectangle {
|
let scrollbar_bounds = Rectangle {
|
||||||
x: bounds.x,
|
x: bounds.x,
|
||||||
y: bounds.y + bounds.height
|
y: bounds.y + bounds.height
|
||||||
- f32::from(total_scrollbar_height / 2 + width / 2),
|
- total_scrollbar_height / 2.0
|
||||||
|
- width / 2.0,
|
||||||
width: (bounds.width - scrollbar_y_width).max(0.0),
|
width: (bounds.width - scrollbar_y_width).max(0.0),
|
||||||
height: width as f32,
|
height: width,
|
||||||
};
|
};
|
||||||
|
|
||||||
let ratio = bounds.width / content_bounds.width;
|
let ratio = bounds.width / content_bounds.width;
|
||||||
|
|
@ -1191,11 +1197,10 @@ impl Scrollbars {
|
||||||
x: (scrollbar_bounds.x + scroller_offset - scrollbar_y_width)
|
x: (scrollbar_bounds.x + scroller_offset - scrollbar_y_width)
|
||||||
.max(0.0),
|
.max(0.0),
|
||||||
y: bounds.y + bounds.height
|
y: bounds.y + bounds.height
|
||||||
- f32::from(
|
- total_scrollbar_height / 2.0
|
||||||
total_scrollbar_height / 2 + scroller_width / 2,
|
- scroller_width / 2.0,
|
||||||
),
|
|
||||||
width: scroller_length,
|
width: scroller_length,
|
||||||
height: scroller_width as f32,
|
height: scroller_width,
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(Scrollbar {
|
Some(Scrollbar {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ use crate::renderer;
|
||||||
use crate::touch;
|
use crate::touch;
|
||||||
use crate::widget::tree::{self, Tree};
|
use crate::widget::tree::{self, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Background, Clipboard, Color, Element, Layout, Length, Point, Rectangle,
|
Background, Clipboard, Color, Element, Layout, Length, Pixels, Point,
|
||||||
Shell, Size, Widget,
|
Rectangle, Shell, Size, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
|
|
@ -54,7 +54,7 @@ where
|
||||||
on_change: Box<dyn Fn(T) -> Message + 'a>,
|
on_change: Box<dyn Fn(T) -> Message + 'a>,
|
||||||
on_release: Option<Message>,
|
on_release: Option<Message>,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: u16,
|
height: f32,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@ where
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
/// The default height of a [`Slider`].
|
/// The default height of a [`Slider`].
|
||||||
pub const DEFAULT_HEIGHT: u16 = 22;
|
pub const DEFAULT_HEIGHT: f32 = 22.0;
|
||||||
|
|
||||||
/// Creates a new [`Slider`].
|
/// Creates a new [`Slider`].
|
||||||
///
|
///
|
||||||
|
|
@ -116,14 +116,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Slider`].
|
/// Sets the width of the [`Slider`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`Slider`].
|
/// Sets the height of the [`Slider`].
|
||||||
pub fn height(mut self, height: u16) -> Self {
|
pub fn height(mut self, height: impl Into<Pixels>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,9 +172,7 @@ where
|
||||||
_renderer: &Renderer,
|
_renderer: &Renderer,
|
||||||
limits: &layout::Limits,
|
limits: &layout::Limits,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
let limits =
|
let limits = limits.width(self.width).height(self.height);
|
||||||
limits.width(self.width).height(Length::Units(self.height));
|
|
||||||
|
|
||||||
let size = limits.resolve(Size::ZERO);
|
let size = limits.resolve(Size::ZERO);
|
||||||
|
|
||||||
layout::Node::new(size)
|
layout::Node::new(size)
|
||||||
|
|
@ -423,8 +421,8 @@ pub fn draw<T, R>(
|
||||||
let handle_offset = if range_start >= range_end {
|
let handle_offset = if range_start >= range_end {
|
||||||
0.0
|
0.0
|
||||||
} else {
|
} else {
|
||||||
bounds.width * (value - range_start) / (range_end - range_start)
|
(bounds.width - handle_width) * (value - range_start)
|
||||||
- handle_width / 2.0
|
/ (range_end - range_start)
|
||||||
};
|
};
|
||||||
|
|
||||||
renderer.fill_quad(
|
renderer.fill_quad(
|
||||||
|
|
|
||||||
|
|
@ -15,23 +15,26 @@ pub struct Space {
|
||||||
|
|
||||||
impl Space {
|
impl Space {
|
||||||
/// Creates an amount of empty [`Space`] with the given width and height.
|
/// Creates an amount of empty [`Space`] with the given width and height.
|
||||||
pub fn new(width: Length, height: Length) -> Self {
|
pub fn new(width: impl Into<Length>, height: impl Into<Length>) -> Self {
|
||||||
Space { width, height }
|
Space {
|
||||||
|
width: width.into(),
|
||||||
|
height: height.into(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an amount of horizontal [`Space`].
|
/// Creates an amount of horizontal [`Space`].
|
||||||
pub fn with_width(width: Length) -> Self {
|
pub fn with_width(width: impl Into<Length>) -> Self {
|
||||||
Space {
|
Space {
|
||||||
width,
|
width: width.into(),
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an amount of vertical [`Space`].
|
/// Creates an amount of vertical [`Space`].
|
||||||
pub fn with_height(height: Length) -> Self {
|
pub fn with_height(height: impl Into<Length>) -> Self {
|
||||||
Space {
|
Space {
|
||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
height,
|
height: height.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,15 +56,15 @@ where
|
||||||
|
|
||||||
/// Sets the width of the [`Svg`].
|
/// Sets the width of the [`Svg`].
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`Svg`].
|
/// Sets the height of the [`Svg`].
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use crate::layout;
|
||||||
use crate::renderer;
|
use crate::renderer;
|
||||||
use crate::text;
|
use crate::text;
|
||||||
use crate::widget::Tree;
|
use crate::widget::Tree;
|
||||||
use crate::{Element, Layout, Length, Point, Rectangle, Size, Widget};
|
use crate::{Element, Layout, Length, Pixels, Point, Rectangle, Size, Widget};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ where
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
content: Cow<'a, str>,
|
content: Cow<'a, str>,
|
||||||
size: Option<u16>,
|
size: Option<f32>,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
horizontal_alignment: alignment::Horizontal,
|
horizontal_alignment: alignment::Horizontal,
|
||||||
|
|
@ -61,8 +61,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the size of the [`Text`].
|
/// Sets the size of the [`Text`].
|
||||||
pub fn size(mut self, size: u16) -> Self {
|
pub fn size(mut self, size: impl Into<Pixels>) -> Self {
|
||||||
self.size = Some(size);
|
self.size = Some(size.into().0);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,14 +84,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Text`] boundaries.
|
/// Sets the width of the [`Text`] boundaries.
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`Text`] boundaries.
|
/// Sets the height of the [`Text`] boundaries.
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,7 +185,7 @@ pub fn draw<Renderer>(
|
||||||
style: &renderer::Style,
|
style: &renderer::Style,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
content: &str,
|
content: &str,
|
||||||
size: Option<u16>,
|
size: Option<f32>,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
appearance: Appearance,
|
appearance: Appearance,
|
||||||
horizontal_alignment: alignment::Horizontal,
|
horizontal_alignment: alignment::Horizontal,
|
||||||
|
|
@ -209,7 +209,7 @@ pub fn draw<Renderer>(
|
||||||
|
|
||||||
renderer.fill_text(crate::text::Text {
|
renderer.fill_text(crate::text::Text {
|
||||||
content,
|
content,
|
||||||
size: f32::from(size.unwrap_or_else(|| renderer.default_size())),
|
size: size.unwrap_or_else(|| renderer.default_size()),
|
||||||
bounds: Rectangle { x, y, ..bounds },
|
bounds: Rectangle { x, y, ..bounds },
|
||||||
color: appearance.color.unwrap_or(style.text_color),
|
color: appearance.color.unwrap_or(style.text_color),
|
||||||
font,
|
font,
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ use crate::widget::operation::{self, Operation};
|
||||||
use crate::widget::tree::{self, Tree};
|
use crate::widget::tree::{self, Tree};
|
||||||
use crate::window;
|
use crate::window;
|
||||||
use crate::{
|
use crate::{
|
||||||
Clipboard, Color, Command, Element, Layout, Length, Padding, Point,
|
Clipboard, Color, Command, Element, Layout, Length, Padding, Pixels, Point,
|
||||||
Rectangle, Shell, Size, Vector, Widget,
|
Rectangle, Shell, Size, Vector, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ where
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
width: Length,
|
width: Length,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
size: Option<u16>,
|
size: Option<f32>,
|
||||||
on_change: Box<dyn Fn(String) -> Message + 'a>,
|
on_change: Box<dyn Fn(String) -> Message + 'a>,
|
||||||
on_paste: Option<Box<dyn Fn(String) -> Message + 'a>>,
|
on_paste: Option<Box<dyn Fn(String) -> Message + 'a>>,
|
||||||
on_submit: Option<Message>,
|
on_submit: Option<Message>,
|
||||||
|
|
@ -94,7 +94,7 @@ where
|
||||||
is_secure: false,
|
is_secure: false,
|
||||||
font: Default::default(),
|
font: Default::default(),
|
||||||
width: Length::Fill,
|
width: Length::Fill,
|
||||||
padding: Padding::new(5),
|
padding: Padding::new(5.0),
|
||||||
size: None,
|
size: None,
|
||||||
on_change: Box::new(on_change),
|
on_change: Box::new(on_change),
|
||||||
on_paste: None,
|
on_paste: None,
|
||||||
|
|
@ -133,8 +133,8 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
/// Sets the width of the [`TextInput`].
|
/// Sets the width of the [`TextInput`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,8 +145,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the text size of the [`TextInput`].
|
/// Sets the text size of the [`TextInput`].
|
||||||
pub fn size(mut self, size: u16) -> Self {
|
pub fn size(mut self, size: impl Into<Pixels>) -> Self {
|
||||||
self.size = Some(size);
|
self.size = Some(size.into().0);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -379,7 +379,7 @@ pub fn layout<Renderer>(
|
||||||
limits: &layout::Limits,
|
limits: &layout::Limits,
|
||||||
width: Length,
|
width: Length,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
size: Option<u16>,
|
size: Option<f32>,
|
||||||
) -> layout::Node
|
) -> layout::Node
|
||||||
where
|
where
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
|
|
@ -387,14 +387,10 @@ where
|
||||||
let text_size = size.unwrap_or_else(|| renderer.default_size());
|
let text_size = size.unwrap_or_else(|| renderer.default_size());
|
||||||
|
|
||||||
let padding = padding.fit(Size::ZERO, limits.max());
|
let padding = padding.fit(Size::ZERO, limits.max());
|
||||||
|
let limits = limits.width(width).pad(padding).height(text_size);
|
||||||
let limits = limits
|
|
||||||
.pad(padding)
|
|
||||||
.width(width)
|
|
||||||
.height(Length::Units(text_size));
|
|
||||||
|
|
||||||
let mut text = layout::Node::new(limits.resolve(Size::ZERO));
|
let mut text = layout::Node::new(limits.resolve(Size::ZERO));
|
||||||
text.move_to(Point::new(padding.left.into(), padding.top.into()));
|
text.move_to(Point::new(padding.left, padding.top));
|
||||||
|
|
||||||
layout::Node::with_children(text.size().pad(padding), vec![text])
|
layout::Node::with_children(text.size().pad(padding), vec![text])
|
||||||
}
|
}
|
||||||
|
|
@ -409,7 +405,7 @@ pub fn update<'a, Message, Renderer>(
|
||||||
clipboard: &mut dyn Clipboard,
|
clipboard: &mut dyn Clipboard,
|
||||||
shell: &mut Shell<'_, Message>,
|
shell: &mut Shell<'_, Message>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
size: Option<u16>,
|
size: Option<f32>,
|
||||||
font: &Renderer::Font,
|
font: &Renderer::Font,
|
||||||
is_secure: bool,
|
is_secure: bool,
|
||||||
on_change: &dyn Fn(String) -> Message,
|
on_change: &dyn Fn(String) -> Message,
|
||||||
|
|
@ -815,7 +811,7 @@ pub fn draw<Renderer>(
|
||||||
state: &State,
|
state: &State,
|
||||||
value: &Value,
|
value: &Value,
|
||||||
placeholder: &str,
|
placeholder: &str,
|
||||||
size: Option<u16>,
|
size: Option<f32>,
|
||||||
font: &Renderer::Font,
|
font: &Renderer::Font,
|
||||||
is_secure: bool,
|
is_secure: bool,
|
||||||
style: &<Renderer::Theme as StyleSheet>::Style,
|
style: &<Renderer::Theme as StyleSheet>::Style,
|
||||||
|
|
@ -969,7 +965,7 @@ pub fn draw<Renderer>(
|
||||||
width: f32::INFINITY,
|
width: f32::INFINITY,
|
||||||
..text_bounds
|
..text_bounds
|
||||||
},
|
},
|
||||||
size: f32::from(size),
|
size,
|
||||||
horizontal_alignment: alignment::Horizontal::Left,
|
horizontal_alignment: alignment::Horizontal::Left,
|
||||||
vertical_alignment: alignment::Vertical::Center,
|
vertical_alignment: alignment::Vertical::Center,
|
||||||
});
|
});
|
||||||
|
|
@ -1128,7 +1124,7 @@ fn offset<Renderer>(
|
||||||
renderer: &Renderer,
|
renderer: &Renderer,
|
||||||
text_bounds: Rectangle,
|
text_bounds: Rectangle,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
size: u16,
|
size: f32,
|
||||||
value: &Value,
|
value: &Value,
|
||||||
state: &State,
|
state: &State,
|
||||||
) -> f32
|
) -> f32
|
||||||
|
|
@ -1162,7 +1158,7 @@ fn measure_cursor_and_scroll_offset<Renderer>(
|
||||||
renderer: &Renderer,
|
renderer: &Renderer,
|
||||||
text_bounds: Rectangle,
|
text_bounds: Rectangle,
|
||||||
value: &Value,
|
value: &Value,
|
||||||
size: u16,
|
size: f32,
|
||||||
cursor_index: usize,
|
cursor_index: usize,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
) -> (f32, f32)
|
) -> (f32, f32)
|
||||||
|
|
@ -1185,7 +1181,7 @@ fn find_cursor_position<Renderer>(
|
||||||
renderer: &Renderer,
|
renderer: &Renderer,
|
||||||
text_bounds: Rectangle,
|
text_bounds: Rectangle,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
size: Option<u16>,
|
size: Option<f32>,
|
||||||
value: &Value,
|
value: &Value,
|
||||||
state: &State,
|
state: &State,
|
||||||
x: f32,
|
x: f32,
|
||||||
|
|
@ -1201,7 +1197,7 @@ where
|
||||||
renderer
|
renderer
|
||||||
.hit_test(
|
.hit_test(
|
||||||
&value.to_string(),
|
&value.to_string(),
|
||||||
size.into(),
|
size,
|
||||||
font,
|
font,
|
||||||
Size::INFINITY,
|
Size::INFINITY,
|
||||||
Point::new(x + offset, text_bounds.height / 2.0),
|
Point::new(x + offset, text_bounds.height / 2.0),
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ use crate::renderer;
|
||||||
use crate::text;
|
use crate::text;
|
||||||
use crate::widget::{self, Row, Text, Tree};
|
use crate::widget::{self, Row, Text, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Alignment, Clipboard, Element, Event, Layout, Length, Point, Rectangle,
|
Alignment, Clipboard, Element, Event, Layout, Length, Pixels, Point,
|
||||||
Shell, Widget,
|
Rectangle, Shell, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use iced_style::toggler::{Appearance, StyleSheet};
|
pub use iced_style::toggler::{Appearance, StyleSheet};
|
||||||
|
|
@ -38,10 +38,10 @@ where
|
||||||
on_toggle: Box<dyn Fn(bool) -> Message + 'a>,
|
on_toggle: Box<dyn Fn(bool) -> Message + 'a>,
|
||||||
label: Option<String>,
|
label: Option<String>,
|
||||||
width: Length,
|
width: Length,
|
||||||
size: u16,
|
size: f32,
|
||||||
text_size: Option<u16>,
|
text_size: Option<f32>,
|
||||||
text_alignment: alignment::Horizontal,
|
text_alignment: alignment::Horizontal,
|
||||||
spacing: u16,
|
spacing: f32,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +52,7 @@ where
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
/// The default size of a [`Toggler`].
|
/// The default size of a [`Toggler`].
|
||||||
pub const DEFAULT_SIZE: u16 = 20;
|
pub const DEFAULT_SIZE: f32 = 20.0;
|
||||||
|
|
||||||
/// Creates a new [`Toggler`].
|
/// Creates a new [`Toggler`].
|
||||||
///
|
///
|
||||||
|
|
@ -78,27 +78,27 @@ where
|
||||||
size: Self::DEFAULT_SIZE,
|
size: Self::DEFAULT_SIZE,
|
||||||
text_size: None,
|
text_size: None,
|
||||||
text_alignment: alignment::Horizontal::Left,
|
text_alignment: alignment::Horizontal::Left,
|
||||||
spacing: 0,
|
spacing: 0.0,
|
||||||
font: Renderer::Font::default(),
|
font: Renderer::Font::default(),
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the size of the [`Toggler`].
|
/// Sets the size of the [`Toggler`].
|
||||||
pub fn size(mut self, size: u16) -> Self {
|
pub fn size(mut self, size: impl Into<Pixels>) -> Self {
|
||||||
self.size = size;
|
self.size = size.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`Toggler`].
|
/// Sets the width of the [`Toggler`].
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the text size o the [`Toggler`].
|
/// Sets the text size o the [`Toggler`].
|
||||||
pub fn text_size(mut self, text_size: u16) -> Self {
|
pub fn text_size(mut self, text_size: impl Into<Pixels>) -> Self {
|
||||||
self.text_size = Some(text_size);
|
self.text_size = Some(text_size.into().0);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,8 +109,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the spacing between the [`Toggler`] and the text.
|
/// Sets the spacing between the [`Toggler`] and the text.
|
||||||
pub fn spacing(mut self, spacing: u16) -> Self {
|
pub fn spacing(mut self, spacing: impl Into<Pixels>) -> Self {
|
||||||
self.spacing = spacing;
|
self.spacing = spacing.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,11 +169,7 @@ where
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
row = row.push(
|
row = row.push(Row::new().width(2.0 * self.size).height(self.size));
|
||||||
Row::new()
|
|
||||||
.width(Length::Units(2 * self.size))
|
|
||||||
.height(Length::Units(self.size)),
|
|
||||||
);
|
|
||||||
|
|
||||||
row.layout(renderer, limits)
|
row.layout(renderer, limits)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ use crate::widget::container;
|
||||||
use crate::widget::overlay;
|
use crate::widget::overlay;
|
||||||
use crate::widget::{Text, Tree};
|
use crate::widget::{Text, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
Clipboard, Element, Event, Layout, Length, Padding, Point, Rectangle,
|
Clipboard, Element, Event, Layout, Length, Padding, Pixels, Point,
|
||||||
Shell, Size, Vector, Widget,
|
Rectangle, Shell, Size, Vector, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
@ -25,8 +25,8 @@ where
|
||||||
content: Element<'a, Message, Renderer>,
|
content: Element<'a, Message, Renderer>,
|
||||||
tooltip: Text<'a, Renderer>,
|
tooltip: Text<'a, Renderer>,
|
||||||
position: Position,
|
position: Position,
|
||||||
gap: u16,
|
gap: f32,
|
||||||
padding: u16,
|
padding: f32,
|
||||||
snap_within_viewport: bool,
|
snap_within_viewport: bool,
|
||||||
style: <Renderer::Theme as container::StyleSheet>::Style,
|
style: <Renderer::Theme as container::StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
@ -37,7 +37,7 @@ where
|
||||||
Renderer::Theme: container::StyleSheet + widget::text::StyleSheet,
|
Renderer::Theme: container::StyleSheet + widget::text::StyleSheet,
|
||||||
{
|
{
|
||||||
/// The default padding of a [`Tooltip`] drawn by this renderer.
|
/// The default padding of a [`Tooltip`] drawn by this renderer.
|
||||||
const DEFAULT_PADDING: u16 = 5;
|
const DEFAULT_PADDING: f32 = 5.0;
|
||||||
|
|
||||||
/// Creates a new [`Tooltip`].
|
/// Creates a new [`Tooltip`].
|
||||||
///
|
///
|
||||||
|
|
@ -51,7 +51,7 @@ where
|
||||||
content: content.into(),
|
content: content.into(),
|
||||||
tooltip: Text::new(tooltip),
|
tooltip: Text::new(tooltip),
|
||||||
position,
|
position,
|
||||||
gap: 0,
|
gap: 0.0,
|
||||||
padding: Self::DEFAULT_PADDING,
|
padding: Self::DEFAULT_PADDING,
|
||||||
snap_within_viewport: true,
|
snap_within_viewport: true,
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
|
|
@ -59,7 +59,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the size of the text of the [`Tooltip`].
|
/// Sets the size of the text of the [`Tooltip`].
|
||||||
pub fn size(mut self, size: u16) -> Self {
|
pub fn size(mut self, size: impl Into<Pixels>) -> Self {
|
||||||
self.tooltip = self.tooltip.size(size);
|
self.tooltip = self.tooltip.size(size);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
@ -73,14 +73,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the gap between the content and its [`Tooltip`].
|
/// Sets the gap between the content and its [`Tooltip`].
|
||||||
pub fn gap(mut self, gap: u16) -> Self {
|
pub fn gap(mut self, gap: impl Into<Pixels>) -> Self {
|
||||||
self.gap = gap;
|
self.gap = gap.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the padding of the [`Tooltip`].
|
/// Sets the padding of the [`Tooltip`].
|
||||||
pub fn padding(mut self, padding: u16) -> Self {
|
pub fn padding(mut self, padding: impl Into<Pixels>) -> Self {
|
||||||
self.padding = padding;
|
self.padding = padding.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -272,8 +272,8 @@ pub fn draw<Renderer>(
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
viewport: &Rectangle,
|
viewport: &Rectangle,
|
||||||
position: Position,
|
position: Position,
|
||||||
gap: u16,
|
gap: f32,
|
||||||
padding: u16,
|
padding: f32,
|
||||||
snap_within_viewport: bool,
|
snap_within_viewport: bool,
|
||||||
style: &<Renderer::Theme as container::StyleSheet>::Style,
|
style: &<Renderer::Theme as container::StyleSheet>::Style,
|
||||||
layout_text: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node,
|
layout_text: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node,
|
||||||
|
|
@ -293,7 +293,6 @@ pub fn draw<Renderer>(
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
|
|
||||||
if bounds.contains(cursor_position) {
|
if bounds.contains(cursor_position) {
|
||||||
let gap = f32::from(gap);
|
|
||||||
let style = theme.appearance(style);
|
let style = theme.appearance(style);
|
||||||
|
|
||||||
let defaults = renderer::Style {
|
let defaults = renderer::Style {
|
||||||
|
|
@ -311,7 +310,6 @@ pub fn draw<Renderer>(
|
||||||
.pad(Padding::new(padding)),
|
.pad(Padding::new(padding)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let padding = f32::from(padding);
|
|
||||||
let text_bounds = text_layout.bounds();
|
let text_bounds = text_layout.bounds();
|
||||||
let x_center = bounds.x + (bounds.width - text_bounds.width) / 2.0;
|
let x_center = bounds.x + (bounds.width - text_bounds.width) / 2.0;
|
||||||
let y_center = bounds.y + (bounds.height - text_bounds.height) / 2.0;
|
let y_center = bounds.y + (bounds.height - text_bounds.height) / 2.0;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use crate::event::{self, Event};
|
||||||
use crate::widget::tree::{self, Tree};
|
use crate::widget::tree::{self, Tree};
|
||||||
use crate::{
|
use crate::{
|
||||||
layout, mouse, renderer, touch, Background, Clipboard, Color, Element,
|
layout, mouse, renderer, touch, Background, Clipboard, Color, Element,
|
||||||
Layout, Length, Point, Rectangle, Shell, Size, Widget,
|
Layout, Length, Pixels, Point, Rectangle, Shell, Size, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An vertical bar and a handle that selects a single value from a range of
|
/// An vertical bar and a handle that selects a single value from a range of
|
||||||
|
|
@ -47,7 +47,7 @@ where
|
||||||
value: T,
|
value: T,
|
||||||
on_change: Box<dyn Fn(T) -> Message + 'a>,
|
on_change: Box<dyn Fn(T) -> Message + 'a>,
|
||||||
on_release: Option<Message>,
|
on_release: Option<Message>,
|
||||||
width: u16,
|
width: f32,
|
||||||
height: Length,
|
height: Length,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
@ -60,7 +60,7 @@ where
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
/// The default width of a [`VerticalSlider`].
|
/// The default width of a [`VerticalSlider`].
|
||||||
pub const DEFAULT_WIDTH: u16 = 22;
|
pub const DEFAULT_WIDTH: f32 = 22.0;
|
||||||
|
|
||||||
/// Creates a new [`VerticalSlider`].
|
/// Creates a new [`VerticalSlider`].
|
||||||
///
|
///
|
||||||
|
|
@ -110,14 +110,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`VerticalSlider`].
|
/// Sets the width of the [`VerticalSlider`].
|
||||||
pub fn width(mut self, width: u16) -> Self {
|
pub fn width(mut self, width: impl Into<Pixels>) -> Self {
|
||||||
self.width = width;
|
self.width = width.into().0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`VerticalSlider`].
|
/// Sets the height of the [`VerticalSlider`].
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||||
self.height = height;
|
self.height = height.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,9 +166,7 @@ where
|
||||||
_renderer: &Renderer,
|
_renderer: &Renderer,
|
||||||
limits: &layout::Limits,
|
limits: &layout::Limits,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
let limits =
|
let limits = limits.width(self.width).height(self.height);
|
||||||
limits.width(Length::Units(self.width)).height(self.height);
|
|
||||||
|
|
||||||
let size = limits.resolve(Size::ZERO);
|
let size = limits.resolve(Size::ZERO);
|
||||||
|
|
||||||
layout::Node::new(size)
|
layout::Node::new(size)
|
||||||
|
|
@ -418,8 +416,8 @@ pub fn draw<T, R>(
|
||||||
let handle_offset = if range_start >= range_end {
|
let handle_offset = if range_start >= range_end {
|
||||||
0.0
|
0.0
|
||||||
} else {
|
} else {
|
||||||
bounds.height * (value - range_end) / (range_start - range_end)
|
(bounds.height - handle_width) * (value - range_end)
|
||||||
- handle_width / 2.0
|
/ (range_start - range_end)
|
||||||
};
|
};
|
||||||
|
|
||||||
renderer.fill_quad(
|
renderer.fill_quad(
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,14 @@ pub enum Action<T> {
|
||||||
///
|
///
|
||||||
/// - **Web / Wayland:** Unsupported.
|
/// - **Web / Wayland:** Unsupported.
|
||||||
GainFocus,
|
GainFocus,
|
||||||
|
/// Change whether or not the window will always be on top of other windows.
|
||||||
|
///
|
||||||
|
/// ## Platform-specific
|
||||||
|
///
|
||||||
|
/// - **Web / Wayland:** Unsupported.
|
||||||
|
ChangeAlwaysOnTop(bool),
|
||||||
|
/// Fetch an identifier unique to the window.
|
||||||
|
FetchId(Box<dyn FnOnce(u64) -> T + 'static>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Action<T> {
|
impl<T> Action<T> {
|
||||||
|
|
@ -85,8 +93,8 @@ impl<T> Action<T> {
|
||||||
Self::Close => Action::Close,
|
Self::Close => Action::Close,
|
||||||
Self::Drag => Action::Drag,
|
Self::Drag => Action::Drag,
|
||||||
Self::Resize { width, height } => Action::Resize { width, height },
|
Self::Resize { width, height } => Action::Resize { width, height },
|
||||||
Self::Maximize(bool) => Action::Maximize(bool),
|
Self::Maximize(maximized) => Action::Maximize(maximized),
|
||||||
Self::Minimize(bool) => Action::Minimize(bool),
|
Self::Minimize(minimized) => Action::Minimize(minimized),
|
||||||
Self::Move { x, y } => Action::Move { x, y },
|
Self::Move { x, y } => Action::Move { x, y },
|
||||||
Self::ChangeMode(mode) => Action::ChangeMode(mode),
|
Self::ChangeMode(mode) => Action::ChangeMode(mode),
|
||||||
Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))),
|
Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))),
|
||||||
|
|
@ -96,6 +104,10 @@ impl<T> Action<T> {
|
||||||
Action::RequestUserAttention(attention_type)
|
Action::RequestUserAttention(attention_type)
|
||||||
}
|
}
|
||||||
Self::GainFocus => Action::GainFocus,
|
Self::GainFocus => Action::GainFocus,
|
||||||
|
Self::ChangeAlwaysOnTop(on_top) => {
|
||||||
|
Action::ChangeAlwaysOnTop(on_top)
|
||||||
|
}
|
||||||
|
Self::FetchId(o) => Action::FetchId(Box::new(move |s| f(o(s)))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -109,8 +121,12 @@ impl<T> fmt::Debug for Action<T> {
|
||||||
f,
|
f,
|
||||||
"Action::Resize {{ widget: {width}, height: {height} }}"
|
"Action::Resize {{ widget: {width}, height: {height} }}"
|
||||||
),
|
),
|
||||||
Self::Maximize(value) => write!(f, "Action::Maximize({value})"),
|
Self::Maximize(maximized) => {
|
||||||
Self::Minimize(value) => write!(f, "Action::Minimize({value}"),
|
write!(f, "Action::Maximize({maximized})")
|
||||||
|
}
|
||||||
|
Self::Minimize(minimized) => {
|
||||||
|
write!(f, "Action::Minimize({minimized}")
|
||||||
|
}
|
||||||
Self::Move { x, y } => {
|
Self::Move { x, y } => {
|
||||||
write!(f, "Action::Move {{ x: {x}, y: {y} }}")
|
write!(f, "Action::Move {{ x: {x}, y: {y} }}")
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +138,10 @@ impl<T> fmt::Debug for Action<T> {
|
||||||
write!(f, "Action::RequestUserAttention")
|
write!(f, "Action::RequestUserAttention")
|
||||||
}
|
}
|
||||||
Self::GainFocus => write!(f, "Action::GainFocus"),
|
Self::GainFocus => write!(f, "Action::GainFocus"),
|
||||||
|
Self::ChangeAlwaysOnTop(on_top) => {
|
||||||
|
write!(f, "Action::AlwaysOnTop({on_top})")
|
||||||
|
}
|
||||||
|
Self::FetchId(_) => write!(f, "Action::FetchId"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,15 +39,15 @@ pub use iced_native::application::{Appearance, StyleSheet};
|
||||||
/// to listen to time.
|
/// to listen to time.
|
||||||
/// - [`todos`], a todos tracker inspired by [TodoMVC].
|
/// - [`todos`], a todos tracker inspired by [TodoMVC].
|
||||||
///
|
///
|
||||||
/// [The repository has a bunch of examples]: https://github.com/iced-rs/iced/tree/0.7/examples
|
/// [The repository has a bunch of examples]: https://github.com/iced-rs/iced/tree/0.8/examples
|
||||||
/// [`clock`]: https://github.com/iced-rs/iced/tree/0.7/examples/clock
|
/// [`clock`]: https://github.com/iced-rs/iced/tree/0.8/examples/clock
|
||||||
/// [`download_progress`]: https://github.com/iced-rs/iced/tree/0.7/examples/download_progress
|
/// [`download_progress`]: https://github.com/iced-rs/iced/tree/0.8/examples/download_progress
|
||||||
/// [`events`]: https://github.com/iced-rs/iced/tree/0.7/examples/events
|
/// [`events`]: https://github.com/iced-rs/iced/tree/0.8/examples/events
|
||||||
/// [`game_of_life`]: https://github.com/iced-rs/iced/tree/0.7/examples/game_of_life
|
/// [`game_of_life`]: https://github.com/iced-rs/iced/tree/0.8/examples/game_of_life
|
||||||
/// [`pokedex`]: https://github.com/iced-rs/iced/tree/0.7/examples/pokedex
|
/// [`pokedex`]: https://github.com/iced-rs/iced/tree/0.8/examples/pokedex
|
||||||
/// [`solar_system`]: https://github.com/iced-rs/iced/tree/0.7/examples/solar_system
|
/// [`solar_system`]: https://github.com/iced-rs/iced/tree/0.8/examples/solar_system
|
||||||
/// [`stopwatch`]: https://github.com/iced-rs/iced/tree/0.7/examples/stopwatch
|
/// [`stopwatch`]: https://github.com/iced-rs/iced/tree/0.8/examples/stopwatch
|
||||||
/// [`todos`]: https://github.com/iced-rs/iced/tree/0.7/examples/todos
|
/// [`todos`]: https://github.com/iced-rs/iced/tree/0.8/examples/todos
|
||||||
/// [`Sandbox`]: crate::Sandbox
|
/// [`Sandbox`]: crate::Sandbox
|
||||||
/// [`Canvas`]: crate::widget::Canvas
|
/// [`Canvas`]: crate::widget::Canvas
|
||||||
/// [PokéAPI]: https://pokeapi.co/
|
/// [PokéAPI]: https://pokeapi.co/
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,13 @@
|
||||||
//! [scrollables]: https://gfycat.com/perkybaggybaboon-rust-gui
|
//! [scrollables]: https://gfycat.com/perkybaggybaboon-rust-gui
|
||||||
//! [Debug overlay with performance metrics]: https://gfycat.com/incredibledarlingbee
|
//! [Debug overlay with performance metrics]: https://gfycat.com/incredibledarlingbee
|
||||||
//! [Modular ecosystem]: https://github.com/iced-rs/iced/blob/master/ECOSYSTEM.md
|
//! [Modular ecosystem]: https://github.com/iced-rs/iced/blob/master/ECOSYSTEM.md
|
||||||
//! [renderer-agnostic native runtime]: https://github.com/iced-rs/iced/tree/0.7/native
|
//! [renderer-agnostic native runtime]: https://github.com/iced-rs/iced/tree/0.8/native
|
||||||
//! [`wgpu`]: https://github.com/gfx-rs/wgpu-rs
|
//! [`wgpu`]: https://github.com/gfx-rs/wgpu-rs
|
||||||
//! [built-in renderer]: https://github.com/iced-rs/iced/tree/0.7/wgpu
|
//! [built-in renderer]: https://github.com/iced-rs/iced/tree/0.8/wgpu
|
||||||
//! [windowing shell]: https://github.com/iced-rs/iced/tree/0.7/winit
|
//! [windowing shell]: https://github.com/iced-rs/iced/tree/0.8/winit
|
||||||
//! [`dodrio`]: https://github.com/fitzgen/dodrio
|
//! [`dodrio`]: https://github.com/fitzgen/dodrio
|
||||||
//! [web runtime]: https://github.com/iced-rs/iced_web
|
//! [web runtime]: https://github.com/iced-rs/iced_web
|
||||||
//! [examples]: https://github.com/iced-rs/iced/tree/0.7/examples
|
//! [examples]: https://github.com/iced-rs/iced/tree/0.8/examples
|
||||||
//! [repository]: https://github.com/iced-rs/iced
|
//! [repository]: https://github.com/iced-rs/iced
|
||||||
//!
|
//!
|
||||||
//! # Overview
|
//! # Overview
|
||||||
|
|
|
||||||
|
|
@ -34,19 +34,19 @@ use crate::{Application, Command, Element, Error, Settings, Subscription};
|
||||||
/// - [`tour`], a simple UI tour that can run both on native platforms and the
|
/// - [`tour`], a simple UI tour that can run both on native platforms and the
|
||||||
/// web!
|
/// web!
|
||||||
///
|
///
|
||||||
/// [The repository has a bunch of examples]: https://github.com/iced-rs/iced/tree/0.7/examples
|
/// [The repository has a bunch of examples]: https://github.com/iced-rs/iced/tree/0.8/examples
|
||||||
/// [`bezier_tool`]: https://github.com/iced-rs/iced/tree/0.7/examples/bezier_tool
|
/// [`bezier_tool`]: https://github.com/iced-rs/iced/tree/0.8/examples/bezier_tool
|
||||||
/// [`counter`]: https://github.com/iced-rs/iced/tree/0.7/examples/counter
|
/// [`counter`]: https://github.com/iced-rs/iced/tree/0.8/examples/counter
|
||||||
/// [`custom_widget`]: https://github.com/iced-rs/iced/tree/0.7/examples/custom_widget
|
/// [`custom_widget`]: https://github.com/iced-rs/iced/tree/0.8/examples/custom_widget
|
||||||
/// [`geometry`]: https://github.com/iced-rs/iced/tree/0.7/examples/geometry
|
/// [`geometry`]: https://github.com/iced-rs/iced/tree/0.8/examples/geometry
|
||||||
/// [`pane_grid`]: https://github.com/iced-rs/iced/tree/0.7/examples/pane_grid
|
/// [`pane_grid`]: https://github.com/iced-rs/iced/tree/0.8/examples/pane_grid
|
||||||
/// [`progress_bar`]: https://github.com/iced-rs/iced/tree/0.7/examples/progress_bar
|
/// [`progress_bar`]: https://github.com/iced-rs/iced/tree/0.8/examples/progress_bar
|
||||||
/// [`styling`]: https://github.com/iced-rs/iced/tree/0.7/examples/styling
|
/// [`styling`]: https://github.com/iced-rs/iced/tree/0.8/examples/styling
|
||||||
/// [`svg`]: https://github.com/iced-rs/iced/tree/0.7/examples/svg
|
/// [`svg`]: https://github.com/iced-rs/iced/tree/0.8/examples/svg
|
||||||
/// [`tour`]: https://github.com/iced-rs/iced/tree/0.7/examples/tour
|
/// [`tour`]: https://github.com/iced-rs/iced/tree/0.8/examples/tour
|
||||||
/// [`Canvas widget`]: crate::widget::Canvas
|
/// [`Canvas widget`]: crate::widget::Canvas
|
||||||
/// [the overview]: index.html#overview
|
/// [the overview]: index.html#overview
|
||||||
/// [`iced_wgpu`]: https://github.com/iced-rs/iced/tree/0.7/wgpu
|
/// [`iced_wgpu`]: https://github.com/iced-rs/iced/tree/0.8/wgpu
|
||||||
/// [`Svg` widget]: crate::widget::Svg
|
/// [`Svg` widget]: crate::widget::Svg
|
||||||
/// [Ghostscript Tiger]: https://commons.wikimedia.org/wiki/File:Ghostscript_Tiger.svg
|
/// [Ghostscript Tiger]: https://commons.wikimedia.org/wiki/File:Ghostscript_Tiger.svg
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ pub struct Settings<Flags> {
|
||||||
|
|
||||||
/// The text size that will be used by default.
|
/// The text size that will be used by default.
|
||||||
///
|
///
|
||||||
/// The default value is 20.
|
/// The default value is `20.0`.
|
||||||
pub default_text_size: u16,
|
pub default_text_size: f32,
|
||||||
|
|
||||||
/// If enabled, spread text workload in multiple threads when multiple cores
|
/// If enabled, spread text workload in multiple threads when multiple cores
|
||||||
/// are available.
|
/// are available.
|
||||||
|
|
@ -97,7 +97,7 @@ where
|
||||||
window: Default::default(),
|
window: Default::default(),
|
||||||
flags: Default::default(),
|
flags: Default::default(),
|
||||||
default_font: Default::default(),
|
default_font: Default::default(),
|
||||||
default_text_size: 20,
|
default_text_size: 20.0,
|
||||||
text_multithreading: false,
|
text_multithreading: false,
|
||||||
antialiasing: false,
|
antialiasing: false,
|
||||||
exit_on_close_request: true,
|
exit_on_close_request: true,
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ pub mod button {
|
||||||
|
|
||||||
pub mod checkbox {
|
pub mod checkbox {
|
||||||
//! Show toggle controls using checkboxes.
|
//! Show toggle controls using checkboxes.
|
||||||
pub use iced_native::widget::checkbox::{Appearance, StyleSheet};
|
pub use iced_native::widget::checkbox::{Appearance, Icon, StyleSheet};
|
||||||
|
|
||||||
/// A box that can be checked.
|
/// A box that can be checked.
|
||||||
pub type Checkbox<'a, Message, Renderer = crate::Renderer> =
|
pub type Checkbox<'a, Message, Renderer = crate::Renderer> =
|
||||||
|
|
@ -56,7 +56,7 @@ pub mod pane_grid {
|
||||||
//! The [`pane_grid` example] showcases how to use a [`PaneGrid`] with resizing,
|
//! The [`pane_grid` example] showcases how to use a [`PaneGrid`] with resizing,
|
||||||
//! drag and drop, and hotkey support.
|
//! drag and drop, and hotkey support.
|
||||||
//!
|
//!
|
||||||
//! [`pane_grid` example]: https://github.com/iced-rs/iced/tree/0.7/examples/pane_grid
|
//! [`pane_grid` example]: https://github.com/iced-rs/iced/tree/0.8/examples/pane_grid
|
||||||
pub use iced_native::widget::pane_grid::{
|
pub use iced_native::widget::pane_grid::{
|
||||||
Axis, Configuration, Direction, DragEvent, Line, Node, Pane,
|
Axis, Configuration, Direction, DragEvent, Line, Node, Pane,
|
||||||
ResizeEvent, Split, State, StyleSheet,
|
ResizeEvent, Split, State, StyleSheet,
|
||||||
|
|
@ -80,7 +80,9 @@ pub mod pane_grid {
|
||||||
|
|
||||||
pub mod pick_list {
|
pub mod pick_list {
|
||||||
//! Display a dropdown list of selectable values.
|
//! Display a dropdown list of selectable values.
|
||||||
pub use iced_native::widget::pick_list::{Appearance, Handle, StyleSheet};
|
pub use iced_native::widget::pick_list::{
|
||||||
|
Appearance, Handle, Icon, StyleSheet,
|
||||||
|
};
|
||||||
|
|
||||||
/// A widget allowing the selection of a single value from a list of options.
|
/// A widget allowing the selection of a single value from a list of options.
|
||||||
pub type PickList<'a, T, Message, Renderer = crate::Renderer> =
|
pub type PickList<'a, T, Message, Renderer = crate::Renderer> =
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced_style"
|
name = "iced_style"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "The default set of styles of Iced"
|
description = "The default set of styles of Iced"
|
||||||
|
|
@ -11,7 +11,7 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"]
|
||||||
categories = ["gui"]
|
categories = ["gui"]
|
||||||
|
|
||||||
[dependencies.iced_core]
|
[dependencies.iced_core]
|
||||||
version = "0.7"
|
version = "0.8"
|
||||||
path = "../core"
|
path = "../core"
|
||||||
features = ["palette"]
|
features = ["palette"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ use iced_core::{Background, Color};
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
/// The [`Background`] of the checkbox.
|
/// The [`Background`] of the checkbox.
|
||||||
pub background: Background,
|
pub background: Background,
|
||||||
/// The checkmark [`Color`] of the checkbox.
|
/// The icon [`Color`] of the checkbox.
|
||||||
pub checkmark_color: Color,
|
pub icon_color: Color,
|
||||||
/// The border radius of the checkbox.
|
/// The border radius of the checkbox.
|
||||||
pub border_radius: f32,
|
pub border_radius: f32,
|
||||||
/// The border width of the checkbox.
|
/// The border width of the checkbox.
|
||||||
|
|
|
||||||
|
|
@ -320,7 +320,7 @@ impl checkbox::StyleSheet for Theme {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn checkbox_appearance(
|
fn checkbox_appearance(
|
||||||
checkmark_color: Color,
|
icon_color: Color,
|
||||||
base: palette::Pair,
|
base: palette::Pair,
|
||||||
accent: palette::Pair,
|
accent: palette::Pair,
|
||||||
is_checked: bool,
|
is_checked: bool,
|
||||||
|
|
@ -331,7 +331,7 @@ fn checkbox_appearance(
|
||||||
} else {
|
} else {
|
||||||
base.color
|
base.color
|
||||||
}),
|
}),
|
||||||
checkmark_color,
|
icon_color,
|
||||||
border_radius: 2.0,
|
border_radius: 2.0,
|
||||||
border_width: 1.0,
|
border_width: 1.0,
|
||||||
border_color: accent.color,
|
border_color: accent.color,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced_wgpu"
|
name = "iced_wgpu"
|
||||||
version = "0.8.0"
|
version = "0.9.0"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A wgpu renderer for Iced"
|
description = "A wgpu renderer for Iced"
|
||||||
|
|
@ -42,11 +42,11 @@ version = "1.9"
|
||||||
features = ["derive"]
|
features = ["derive"]
|
||||||
|
|
||||||
[dependencies.iced_native]
|
[dependencies.iced_native]
|
||||||
version = "0.8"
|
version = "0.9"
|
||||||
path = "../native"
|
path = "../native"
|
||||||
|
|
||||||
[dependencies.iced_graphics]
|
[dependencies.iced_graphics]
|
||||||
version = "0.6"
|
version = "0.7"
|
||||||
path = "../graphics"
|
path = "../graphics"
|
||||||
features = ["font-fallback", "font-icons"]
|
features = ["font-fallback", "font-icons"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ Currently, `iced_wgpu` supports the following primitives:
|
||||||
Add `iced_wgpu` as a dependency in your `Cargo.toml`:
|
Add `iced_wgpu` as a dependency in your `Cargo.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
iced_wgpu = "0.8"
|
iced_wgpu = "0.9"
|
||||||
```
|
```
|
||||||
|
|
||||||
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ pub struct Backend {
|
||||||
#[cfg(any(feature = "image", feature = "svg"))]
|
#[cfg(any(feature = "image", feature = "svg"))]
|
||||||
image_pipeline: image::Pipeline,
|
image_pipeline: image::Pipeline,
|
||||||
|
|
||||||
default_text_size: u16,
|
default_text_size: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Backend {
|
impl Backend {
|
||||||
|
|
@ -265,7 +265,7 @@ impl backend::Text for Backend {
|
||||||
const CHECKMARK_ICON: char = font::CHECKMARK_ICON;
|
const CHECKMARK_ICON: char = font::CHECKMARK_ICON;
|
||||||
const ARROW_DOWN_ICON: char = font::ARROW_DOWN_ICON;
|
const ARROW_DOWN_ICON: char = font::ARROW_DOWN_ICON;
|
||||||
|
|
||||||
fn default_size(&self) -> u16 {
|
fn default_size(&self) -> f32 {
|
||||||
self.default_text_size
|
self.default_text_size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
//! - Meshes of triangles, useful to draw geometry freely.
|
//! - Meshes of triangles, useful to draw geometry freely.
|
||||||
//!
|
//!
|
||||||
//! [Iced]: https://github.com/iced-rs/iced
|
//! [Iced]: https://github.com/iced-rs/iced
|
||||||
//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.7/native
|
//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native
|
||||||
//! [`wgpu`]: https://github.com/gfx-rs/wgpu-rs
|
//! [`wgpu`]: https://github.com/gfx-rs/wgpu-rs
|
||||||
//! [WebGPU API]: https://gpuweb.github.io/gpuweb/
|
//! [WebGPU API]: https://gpuweb.github.io/gpuweb/
|
||||||
//! [`wgpu_glyph`]: https://github.com/hecrj/wgpu_glyph
|
//! [`wgpu_glyph`]: https://github.com/hecrj/wgpu_glyph
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ pub use crate::Antialiasing;
|
||||||
/// The settings of a [`Backend`].
|
/// The settings of a [`Backend`].
|
||||||
///
|
///
|
||||||
/// [`Backend`]: crate::Backend
|
/// [`Backend`]: crate::Backend
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
/// The present mode of the [`Backend`].
|
/// The present mode of the [`Backend`].
|
||||||
///
|
///
|
||||||
|
|
@ -21,8 +21,8 @@ pub struct Settings {
|
||||||
|
|
||||||
/// The default size of text.
|
/// The default size of text.
|
||||||
///
|
///
|
||||||
/// By default, it will be set to 20.
|
/// By default, it will be set to `16.0`.
|
||||||
pub default_text_size: u16,
|
pub default_text_size: f32,
|
||||||
|
|
||||||
/// If enabled, spread text workload in multiple threads when multiple cores
|
/// If enabled, spread text workload in multiple threads when multiple cores
|
||||||
/// are available.
|
/// are available.
|
||||||
|
|
@ -66,7 +66,7 @@ impl Default for Settings {
|
||||||
present_mode: wgpu::PresentMode::AutoVsync,
|
present_mode: wgpu::PresentMode::AutoVsync,
|
||||||
internal_backend: wgpu::Backends::all(),
|
internal_backend: wgpu::Backends::all(),
|
||||||
default_font: None,
|
default_font: None,
|
||||||
default_text_size: 20,
|
default_text_size: 20.0,
|
||||||
text_multithreading: false,
|
text_multithreading: false,
|
||||||
antialiasing: None,
|
antialiasing: None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced_winit"
|
name = "iced_winit"
|
||||||
version = "0.7.0"
|
version = "0.8.0"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A winit runtime for Iced"
|
description = "A winit runtime for Iced"
|
||||||
|
|
@ -28,15 +28,15 @@ git = "https://github.com/iced-rs/winit.git"
|
||||||
rev = "940457522e9fb9f5dac228b0ecfafe0138b4048c"
|
rev = "940457522e9fb9f5dac228b0ecfafe0138b4048c"
|
||||||
|
|
||||||
[dependencies.iced_native]
|
[dependencies.iced_native]
|
||||||
version = "0.8"
|
version = "0.9"
|
||||||
path = "../native"
|
path = "../native"
|
||||||
|
|
||||||
[dependencies.iced_graphics]
|
[dependencies.iced_graphics]
|
||||||
version = "0.6"
|
version = "0.7"
|
||||||
path = "../graphics"
|
path = "../graphics"
|
||||||
|
|
||||||
[dependencies.iced_futures]
|
[dependencies.iced_futures]
|
||||||
version = "0.5"
|
version = "0.6"
|
||||||
path = "../futures"
|
path = "../futures"
|
||||||
|
|
||||||
[dependencies.tracing]
|
[dependencies.tracing]
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ It exposes a renderer-agnostic `Application` trait that can be implemented and t
|
||||||
Add `iced_winit` as a dependency in your `Cargo.toml`:
|
Add `iced_winit` as a dependency in your `Cargo.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
iced_winit = "0.7"
|
iced_winit = "0.8"
|
||||||
```
|
```
|
||||||
|
|
||||||
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
__Iced moves fast and the `master` branch can contain breaking changes!__ If
|
||||||
|
|
|
||||||
|
|
@ -147,11 +147,15 @@ where
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
let target = settings.window.platform_specific.target.clone();
|
let target = settings.window.platform_specific.target.clone();
|
||||||
|
|
||||||
let builder = settings.window.into_builder(
|
let should_be_visible = settings.window.visible;
|
||||||
&application.title(),
|
let builder = settings
|
||||||
event_loop.primary_monitor(),
|
.window
|
||||||
settings.id,
|
.into_builder(
|
||||||
);
|
&application.title(),
|
||||||
|
event_loop.primary_monitor(),
|
||||||
|
settings.id,
|
||||||
|
)
|
||||||
|
.with_visible(false);
|
||||||
|
|
||||||
log::info!("Window builder: {:#?}", builder);
|
log::info!("Window builder: {:#?}", builder);
|
||||||
|
|
||||||
|
|
@ -202,6 +206,7 @@ where
|
||||||
control_sender,
|
control_sender,
|
||||||
init_command,
|
init_command,
|
||||||
window,
|
window,
|
||||||
|
should_be_visible,
|
||||||
settings.exit_on_close_request,
|
settings.exit_on_close_request,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -268,6 +273,7 @@ async fn run_instance<A, E, C>(
|
||||||
mut control_sender: mpsc::UnboundedSender<winit::event_loop::ControlFlow>,
|
mut control_sender: mpsc::UnboundedSender<winit::event_loop::ControlFlow>,
|
||||||
init_command: Command<A::Message>,
|
init_command: Command<A::Message>,
|
||||||
window: winit::window::Window,
|
window: winit::window::Window,
|
||||||
|
should_be_visible: bool,
|
||||||
exit_on_close_request: bool,
|
exit_on_close_request: bool,
|
||||||
) where
|
) where
|
||||||
A: Application + 'static,
|
A: Application + 'static,
|
||||||
|
|
@ -295,6 +301,10 @@ async fn run_instance<A, E, C>(
|
||||||
physical_size.height,
|
physical_size.height,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if should_be_visible {
|
||||||
|
window.set_visible(true);
|
||||||
|
}
|
||||||
|
|
||||||
run_command(
|
run_command(
|
||||||
&application,
|
&application,
|
||||||
&mut cache,
|
&mut cache,
|
||||||
|
|
@ -737,11 +747,11 @@ pub fn run_command<A, E>(
|
||||||
height,
|
height,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
window::Action::Maximize(value) => {
|
window::Action::Maximize(maximized) => {
|
||||||
window.set_maximized(value);
|
window.set_maximized(maximized);
|
||||||
}
|
}
|
||||||
window::Action::Minimize(value) => {
|
window::Action::Minimize(minimized) => {
|
||||||
window.set_minimized(value);
|
window.set_minimized(minimized);
|
||||||
}
|
}
|
||||||
window::Action::Move { x, y } => {
|
window::Action::Move { x, y } => {
|
||||||
window.set_outer_position(winit::dpi::LogicalPosition {
|
window.set_outer_position(winit::dpi::LogicalPosition {
|
||||||
|
|
@ -771,13 +781,24 @@ pub fn run_command<A, E>(
|
||||||
window.set_maximized(!window.is_maximized())
|
window.set_maximized(!window.is_maximized())
|
||||||
}
|
}
|
||||||
window::Action::ToggleDecorations => {
|
window::Action::ToggleDecorations => {
|
||||||
window.set_decorations(!window.is_decorated())
|
window.set_decorations(!window.is_decorated());
|
||||||
}
|
}
|
||||||
window::Action::RequestUserAttention(user_attention) => window
|
window::Action::RequestUserAttention(user_attention) => {
|
||||||
.request_user_attention(
|
window.request_user_attention(
|
||||||
user_attention.map(conversion::user_attention),
|
user_attention.map(conversion::user_attention),
|
||||||
),
|
);
|
||||||
window::Action::GainFocus => window.focus_window(),
|
}
|
||||||
|
window::Action::GainFocus => {
|
||||||
|
window.focus_window();
|
||||||
|
}
|
||||||
|
window::Action::ChangeAlwaysOnTop(on_top) => {
|
||||||
|
window.set_always_on_top(on_top);
|
||||||
|
}
|
||||||
|
window::Action::FetchId(tag) => {
|
||||||
|
proxy
|
||||||
|
.send_event(tag(window.id().into()))
|
||||||
|
.expect("Send message to event loop");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
command::Action::System(action) => match action {
|
command::Action::System(action) => match action {
|
||||||
system::Action::QueryInformation(_tag) => {
|
system::Action::QueryInformation(_tag) => {
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue