Skip to content

Commit

Permalink
Merge branch 'master' into dev/system-information
Browse files Browse the repository at this point in the history
  • Loading branch information
derezzedex committed May 10, 2022
2 parents 27fdc70 + d4ed8af commit b440df9
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 19 deletions.
7 changes: 5 additions & 2 deletions .github/ISSUE_TEMPLATE/BUG-REPORT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ body:
id: version
attributes:
label: Version
description: What version of iced are you using?
description: |
We only offer support for the `0.4` release on crates.io and the `master` branch on this repository. Which version are you using? Please make sure you are using the latest patch available (e.g. run `cargo update`).
If you are using an older release, please upgrade to `0.4` before filing an issue.
options:
- master
- 0.3.0
- 0.4
validations:
required: true
- type: dropdown
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ Add `iced` as a dependency in your `Cargo.toml`:
iced = "0.4"
```

If your project is using a Rust edition older than 2021, then you will need to
set `resolver = "2"` in the `[package]` section as well.

__Iced moves fast and the `master` branch can contain breaking changes!__ If
you want to learn about a specific release, check out [the release list].

Expand Down
2 changes: 1 addition & 1 deletion pure/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iced_pure"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
description = "Pure widgets for Iced"
license = "MIT"
Expand Down
18 changes: 18 additions & 0 deletions pure/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use iced_native::mouse;
use iced_native::renderer;
use iced_native::{Clipboard, Length, Point, Rectangle, Shell};

use std::borrow::Borrow;

/// A generic [`Widget`].
///
/// It is useful to build composable user interfaces that do not leak
Expand Down Expand Up @@ -321,3 +323,19 @@ where
.map(move |overlay| overlay.map(mapper))
}
}

impl<'a, Message, Renderer> Borrow<dyn Widget<Message, Renderer> + 'a>
for Element<'a, Message, Renderer>
{
fn borrow(&self) -> &(dyn Widget<Message, Renderer> + 'a) {
self.widget.borrow()
}
}

impl<'a, Message, Renderer> Borrow<dyn Widget<Message, Renderer> + 'a>
for &Element<'a, Message, Renderer>
{
fn borrow(&self) -> &(dyn Widget<Message, Renderer> + 'a) {
self.widget.borrow()
}
}
2 changes: 1 addition & 1 deletion pure/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub fn horizontal_rule<'a>(height: u16) -> widget::Rule<'a> {
///
/// [`Rule`]: widget::Rule
pub fn vertical_rule<'a>(width: u16) -> widget::Rule<'a> {
widget::Rule::horizontal(width)
widget::Rule::vertical(width)
}

/// Creates a new [`ProgressBar`].
Expand Down
3 changes: 1 addition & 2 deletions pure/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@
#![forbid(unsafe_code)]
#![forbid(rust_2018_idioms)]

pub mod flex;
pub mod helpers;
pub mod overlay;
pub mod widget;

pub(crate) mod flex;

mod element;

pub use element::Element;
Expand Down
33 changes: 20 additions & 13 deletions pure/src/widget/tree.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Store internal widget state in a state tree to ensure continuity.
use crate::Element;
use crate::Widget;

use std::any::{self, Any};
use std::borrow::Borrow;

/// A persistent state widget tree.
///
Expand All @@ -28,13 +29,15 @@ impl Tree {
}

/// Creates a new [`Tree`] for the provided [`Element`].
pub fn new<Message, Renderer>(
element: &Element<'_, Message, Renderer>,
pub fn new<'a, Message, Renderer>(
widget: impl Borrow<dyn Widget<Message, Renderer> + 'a>,
) -> Self {
let widget = widget.borrow();

Self {
tag: element.as_widget().tag(),
state: element.as_widget().state(),
children: element.as_widget().children(),
tag: widget.tag(),
state: widget.state(),
children: widget.children(),
}
}

Expand All @@ -46,23 +49,27 @@ impl Tree {
/// Otherwise, the whole [`Tree`] is recreated.
///
/// [`Widget::diff`]: crate::Widget::diff
pub fn diff<Message, Renderer>(
pub fn diff<'a, Message, Renderer>(
&mut self,
new: &Element<'_, Message, Renderer>,
new: impl Borrow<dyn Widget<Message, Renderer> + 'a>,
) {
if self.tag == new.as_widget().tag() {
new.as_widget().diff(self)
if self.tag == new.borrow().tag() {
new.borrow().diff(self)
} else {
*self = Self::new(new);
}
}

/// Reconciliates the children of the tree with the provided list of [`Element`].
pub fn diff_children<Message, Renderer>(
pub fn diff_children<'a, Message, Renderer>(
&mut self,
new_children: &[Element<'_, Message, Renderer>],
new_children: &[impl Borrow<dyn Widget<Message, Renderer> + 'a>],
) {
self.diff_children_custom(new_children, Self::diff, Self::new)
self.diff_children_custom(
new_children,
|tree, widget| tree.diff(widget.borrow()),
|widget| Self::new(widget.borrow()),
)
}

/// Reconciliates the children of the tree with the provided list of [`Element`] using custom
Expand Down

0 comments on commit b440df9

Please sign in to comment.