Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #64

Merged
merged 9 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/document.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Generate documentation
run: |
RUSTDOCFLAGS="--cfg docsrs" \
cargo doc --no-deps --all-features \
cargo doc --no-deps --features "winit" \
-p iced_core \
-p iced_style \
-p iced_futures \
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ jobs:
- uses: hecrj/setup-rust-action@v1
with:
components: clippy

- uses: actions/checkout@master
- name: Install dependencies
run: |
export DEBIAN_FRONTED=noninteractive
sudo apt-get -qq update
sudo apt-get install -y libxkbcommon-dev libwayland-dev
- name: Check lints
run: cargo clippy --workspace --all-features --all-targets --no-deps -- -D warnings
run: |
cargo clippy --no-default-features --features "winit" --all-targets
cargo clippy --no-default-features --features "wayland wgpu svg canvas qr_code lazy debug tokio palette web-colors system a11y"
27 changes: 20 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,24 @@ jobs:
run: |
export DEBIAN_FRONTED=noninteractive
sudo apt-get -qq update
sudo apt-get install -y libxkbcommon-dev
sudo apt-get install -y libxkbcommon-dev libwayland-dev
- name: Run tests
run: |
cargo test --verbose --workspace
cargo test --verbose --workspace --all-features
cargo test --verbose --features "winit wgpu svg canvas qr_code lazy debug tokio palette web-colors system a11y"
cargo test -p iced_accessibility
cargo test -p iced_core
cargo test -p iced_futures
cargo test -p iced_graphics
cargo test -p iced_renderer
cargo test -p iced_runtime
cargo test -p iced_tiny_skia
cargo test -p iced_widget
cargo test -p iced_wgpu
- name: test wayland
if: matrix.os == 'ubuntu-latest'
run: |
cargo test --verbose --features "wayland wgpu svg canvas qr_code lazy debug tokio palette web-colors system a11y"
cargo test -p iced_sctk

web:
runs-on: ubuntu-latest
Expand All @@ -32,10 +45,10 @@ jobs:
targets: wasm32-unknown-unknown
- uses: actions/checkout@master
- name: Run checks
run: cargo check --package iced --target wasm32-unknown-unknown --no-default-features --features "winit tiny-skia"
run: cargo check --package iced --target wasm32-unknown-unknown --no-default-features --features "winit"
- name: Check compilation of `tour` example
run: cargo build --package tour --target wasm32-unknown-unknown --no-default-features --features "winit tiny-skia"
run: cargo build --package tour --target wasm32-unknown-unknown
- name: Check compilation of `todos` example
run: cargo build --package todos --target wasm32-unknown-unknown --no-default-features --features "winit tiny-skia"
run: cargo build --package todos --target wasm32-unknown-unknown
- name: Check compilation of `integration` example
run: cargo build --package integration --target wasm32-unknown-unknown --no-default-features --features "winit tiny-skia"
run: cargo build --package integration --target wasm32-unknown-unknown
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

Many thanks to...
- @wash2

## [0.10.0] - 2023-07-28
### Added
- Text shaping, font fallback, and `iced_wgpu` overhaul. [#1697](https://github.com/iced-rs/iced/pull/1697)
Expand Down
6 changes: 3 additions & 3 deletions accessibility/src/a11y_tree.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{A11yId, A11yNode};
use crate::{A11yId, A11yNode, IdEq};

#[derive(Debug, Clone, Default)]
/// Accessible tree of nodes
Expand Down Expand Up @@ -64,8 +64,8 @@ impl A11yTree {
}

pub fn contains(&self, id: &A11yId) -> bool {
self.root.iter().any(|n| n.id() == id)
|| self.children.iter().any(|n| n.id() == id)
self.root.iter().any(|n| IdEq::eq(n.id(), id))
|| self.children.iter().any(|n| IdEq::eq(n.id(), id))
}
}

Expand Down
42 changes: 37 additions & 5 deletions accessibility/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::hash::Hash;
use std::sync::atomic::{self, AtomicU64};
use std::{borrow, num::NonZeroU128};

#[derive(Debug, Clone, PartialEq, Hash, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum A11yId {
Window(NonZeroU128),
Widget(Id),
Expand Down Expand Up @@ -33,6 +33,17 @@ impl From<Id> for A11yId {
}
}

impl IdEq for A11yId {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(A11yId::Widget(self_), A11yId::Widget(other)) => {
IdEq::eq(self_, other)
}
_ => self == other,
}
}
}

impl From<accesskit::NodeId> for A11yId {
fn from(value: accesskit::NodeId) -> Self {
let val = u128::from(value.0);
Expand All @@ -58,7 +69,7 @@ static NEXT_ID: AtomicU64 = AtomicU64::new(1);
static NEXT_WINDOW_ID: AtomicU64 = AtomicU64::new(1);

/// The identifier of a generic widget.
#[derive(Debug, Clone, PartialEq, Hash, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Id(pub Internal);

impl Id {
Expand Down Expand Up @@ -86,6 +97,11 @@ impl Id {
}
}

impl IdEq for Id {
fn eq(&self, other: &Self) -> bool {
IdEq::eq(&self.0, &other.0)
}
}
// Not meant to be used directly
impl From<u64> for Id {
fn from(value: u64) -> Self {
Expand All @@ -94,9 +110,9 @@ impl From<u64> for Id {
}

// Not meant to be used directly
impl Into<NonZeroU128> for Id {
fn into(self) -> NonZeroU128 {
match &self.0 {
impl From<Id> for NonZeroU128 {
fn from(val: Id) -> NonZeroU128 {
match &val.0 {
Internal::Unique(id) => NonZeroU128::try_from(*id as u128).unwrap(),
Internal::Custom(id, _) => {
NonZeroU128::try_from(*id as u128).unwrap()
Expand Down Expand Up @@ -146,6 +162,22 @@ pub enum Internal {
}

impl PartialEq for Internal {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Unique(l0), Self::Unique(r0)) => l0 == r0,
(Self::Custom(_, l1), Self::Custom(_, r1)) => l1 == r1,
(Self::Set(l0), Self::Set(r0)) => l0 == r0,
_ => false,
}
}
}

/// Similar to PartialEq, but only intended for use when comparing Ids
pub trait IdEq {
fn eq(&self, other: &Self) -> bool;
}

impl IdEq for Internal {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Unique(l0), Self::Unique(r0)) => l0 == r0,
Expand Down
2 changes: 1 addition & 1 deletion accessibility/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use accesskit::NodeClassSet;

use crate::A11yId;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct A11yNode {
node: accesskit::NodeBuilder,
id: A11yId,
Expand Down
2 changes: 1 addition & 1 deletion accessibility/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::Cow;

use crate::A11yId;

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq)]
pub enum Description<'a> {
Text(Cow<'a, str>),
Id(Vec<A11yId>),
Expand Down
37 changes: 31 additions & 6 deletions core/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ impl Id {
}

// Not meant to be used directly
#[cfg(feature = "a11y")]
impl From<u64> for Id {
fn from(value: u64) -> Self {
Self(Internal::Unique(value))
}
}

// Not meant to be used directly
#[cfg(feature = "a11y")]
impl Into<NonZeroU128> for Id {
fn into(self) -> NonZeroU128 {
match &self.0 {
impl From<Id> for NonZeroU128 {
fn from(id: Id) -> NonZeroU128 {
match &id.0 {
Internal::Unique(id) => NonZeroU128::try_from(*id as u128).unwrap(),
Internal::Custom(id, _) => {
NonZeroU128::try_from(*id as u128).unwrap()
Expand Down Expand Up @@ -83,7 +81,7 @@ pub fn window_node_id() -> NonZeroU128 {
}

// TODO refactor to make panic impossible?
#[derive(Debug, Clone, Eq, Hash)]
#[derive(Debug, Clone, Eq)]
/// Internal representation of an [`Id`].
pub enum Internal {
/// a unique id
Expand All @@ -98,6 +96,23 @@ pub enum Internal {
}

impl PartialEq for Internal {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Unique(l0), Self::Unique(r0)) => l0 == r0,
(Self::Custom(_, l1), Self::Custom(_, r1)) => l1 == r1,
(Self::Set(l0), Self::Set(r0)) => l0 == r0,
_ => false,
}
}
}

/// Similar to PartialEq, but only intended for use when comparing Ids
pub trait IdEq {
/// Compare two Ids for equality based on their number or name
fn eq(&self, other: &Self) -> bool;
}

impl IdEq for Internal {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Unique(l0), Self::Unique(r0)) => l0 == r0,
Expand All @@ -116,6 +131,16 @@ impl PartialEq for Internal {
}
}

impl std::hash::Hash for Internal {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
match self {
Self::Unique(id) => id.hash(state),
Self::Custom(name, _) => name.hash(state),
Self::Set(ids) => ids.hash(state),
}
}
}

#[cfg(test)]
mod tests {
use super::Id;
Expand Down
3 changes: 2 additions & 1 deletion core/src/widget/operation/focusable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Operate on widgets that can be focused.
use crate::id::IdEq;
use crate::widget::operation::{Operation, Outcome};
use crate::widget::Id;
use crate::Rectangle;
Expand Down Expand Up @@ -34,7 +35,7 @@ pub fn focus<T>(target: Id) -> impl Operation<T> {
impl<T> Operation<T> for Focus {
fn focusable(&mut self, state: &mut dyn Focusable, id: Option<&Id>) {
match id {
Some(id) if id == &self.target => {
Some(id) if IdEq::eq(&id.0, &self.target.0) => {
state.focus();
}
_ => {
Expand Down
2 changes: 1 addition & 1 deletion core/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ where
}

fn id(&self) -> Option<crate::widget::Id> {
Some(self.id.clone().into())
Some(self.id.clone())
}

fn set_id(&mut self, id: crate::widget::Id) {
Expand Down
16 changes: 10 additions & 6 deletions core/src/widget/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ impl Tree {

let children_len = self.children.len();
let (mut id_map, mut id_list): (
HashMap<Id, &mut Tree>,
HashMap<String, &mut Tree>,
Vec<&mut Tree>,
) = self.children.iter_mut().fold(
(HashMap::new(), Vec::with_capacity(children_len)),
|(mut id_map, mut id_list), c| {
if let Some(id) = c.id.as_ref() {
if matches!(id.0, Internal::Custom(_, _)) {
let _ = id_map.insert(id.clone(), c);
if let Internal::Custom(_, ref name) = id.0 {
let _ = id_map.insert(name.to_string(), c);
} else {
id_list.push(c);
}
Expand All @@ -147,9 +147,13 @@ impl Tree {

let mut child_state_i = 0;
for (new, new_id) in new_children.iter_mut().zip(new_ids.iter()) {
let child_state = if let Some(c) =
new_id.as_ref().and_then(|id| id_map.remove(id))
{
let child_state = if let Some(c) = new_id.as_ref().and_then(|id| {
if let Internal::Custom(_, ref name) = id.0 {
id_map.remove(name.as_ref())
} else {
None
}
}) {
c
} else if child_state_i < id_list.len() {
let c = &mut id_list[child_state_i];
Expand Down
1 change: 1 addition & 0 deletions examples/integration/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
&renderer::Style {
text_color: Color::WHITE,
scale_factor: viewport.scale_factor(),
icon_color: Color::WHITE,
},
&mut clipboard,
&mut debug,
Expand Down
2 changes: 1 addition & 1 deletion examples/slider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
publish = false

[dependencies]
iced = { path = "../.." }
iced = { path = "../..", features = ["winit"] }
2 changes: 1 addition & 1 deletion examples/todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
publish = false

[dependencies]
iced = { path = "../..", features = ["async-std", "debug"] }
iced = { path = "../..", features = ["async-std", "debug", "winit"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
once_cell = "1.15"
Expand Down
2 changes: 1 addition & 1 deletion examples/tour/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
publish = false

[dependencies]
iced = { path = "../..", features = ["image", "debug"] }
iced = { path = "../..", features = ["image", "debug", "winit"] }
env_logger = "0.10.0"
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<T> Action<T> {
match self {
Action::LayerSurface { builder, .. } => Action::LayerSurface {
builder,
_phantom: PhantomData::default(),
_phantom: PhantomData,
},
Action::Size { id, width, height } => {
Action::Size { id, width, height }
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/command/platform_specific/wayland/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<T> Action<T> {
match self {
Action::Popup { popup, .. } => Action::Popup {
popup,
_phantom: PhantomData::default(),
_phantom: PhantomData,
},
Action::Destroy { id } => Action::Destroy { id },
Action::Grab { id } => Action::Grab { id },
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/command/platform_specific/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl<T> Action<T> {
match self {
Action::Window { builder, .. } => Action::Window {
builder,
_phantom: PhantomData::default(),
_phantom: PhantomData,
},
Action::Size { id, width, height } => {
Action::Size { id, width, height }
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/user_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ where
let event_statuses = events
.iter()
.cloned()
.zip(overlay_statuses.into_iter())
.zip(overlay_statuses)
.map(|(event, overlay_status)| {
if matches!(overlay_status, event::Status::Captured) {
return overlay_status;
Expand Down
Loading
Loading