Merge branch 'master' into virtual-widgets
This commit is contained in:
commit
c35496d80f
58 changed files with 446 additions and 909 deletions
|
|
@ -7,12 +7,11 @@ use iced_native::mouse;
|
|||
use iced_native::overlay;
|
||||
use iced_native::renderer;
|
||||
use iced_native::{
|
||||
Clipboard, Element, Hasher, Length, Point, Rectangle, Shell, Size, Widget,
|
||||
Clipboard, Element, Length, Point, Rectangle, Shell, Size, Widget,
|
||||
};
|
||||
|
||||
use ouroboros::self_referencing;
|
||||
use std::cell::RefCell;
|
||||
use std::hash::Hash;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// A reusable, custom widget that uses The Elm Architecture.
|
||||
|
|
@ -217,12 +216,6 @@ where
|
|||
});
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.with_element(|element| {
|
||||
element.hash_layout(state);
|
||||
});
|
||||
}
|
||||
|
||||
fn mouse_interaction(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
|
|
@ -371,18 +364,6 @@ where
|
|||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher, position: Point) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
(position.x as u32).hash(state);
|
||||
(position.y as u32).hash(state);
|
||||
|
||||
self.with_overlay_maybe(|overlay| {
|
||||
overlay.hash_layout(state);
|
||||
});
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
&mut self,
|
||||
event: iced_native::Event,
|
||||
|
|
|
|||
|
|
@ -4,13 +4,12 @@ use iced_native::layout::{self, Layout};
|
|||
use iced_native::mouse;
|
||||
use iced_native::overlay;
|
||||
use iced_native::renderer;
|
||||
use iced_native::{Clipboard, Hasher, Length, Point, Rectangle, Shell, Size};
|
||||
use iced_native::{Clipboard, Length, Point, Rectangle, Shell, Size};
|
||||
use iced_pure::widget::tree::{self, Tree};
|
||||
use iced_pure::{Element, Widget};
|
||||
|
||||
use ouroboros::self_referencing;
|
||||
use std::cell::{Ref, RefCell};
|
||||
use std::hash::Hash;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// A reusable, custom widget that uses The Elm Architecture.
|
||||
|
|
@ -250,12 +249,6 @@ where
|
|||
});
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
self.with_element(|element| {
|
||||
element.as_widget().hash_layout(state);
|
||||
});
|
||||
}
|
||||
|
||||
fn mouse_interaction(
|
||||
&self,
|
||||
tree: &Tree,
|
||||
|
|
@ -409,18 +402,6 @@ where
|
|||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher, position: Point) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
(position.x as u32).hash(state);
|
||||
(position.y as u32).hash(state);
|
||||
|
||||
self.with_overlay_maybe(|overlay| {
|
||||
overlay.hash_layout(state);
|
||||
});
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
&mut self,
|
||||
event: iced_native::Event,
|
||||
|
|
|
|||
|
|
@ -8,11 +8,10 @@ use iced_native::overlay;
|
|||
use iced_native::renderer;
|
||||
use iced_native::window;
|
||||
use iced_native::{
|
||||
Clipboard, Element, Hasher, Length, Point, Rectangle, Shell, Size, Widget,
|
||||
Clipboard, Element, Length, Point, Rectangle, Shell, Size, Widget,
|
||||
};
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::hash::{Hash, Hasher as _};
|
||||
use std::ops::Deref;
|
||||
|
||||
/// The state of a [`Responsive`] widget.
|
||||
|
|
@ -20,7 +19,6 @@ use std::ops::Deref;
|
|||
pub struct State {
|
||||
last_size: Option<Size>,
|
||||
last_layout: layout::Node,
|
||||
last_layout_hash: u64,
|
||||
}
|
||||
|
||||
impl State {
|
||||
|
|
@ -76,8 +74,6 @@ where
|
|||
Length::Fill
|
||||
}
|
||||
|
||||
fn hash_layout(&self, _hasher: &mut Hasher) {}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
_renderer: &Renderer,
|
||||
|
|
@ -178,7 +174,7 @@ where
|
|||
let content_layout = state.layout(layout);
|
||||
|
||||
match content {
|
||||
Content::Pending(_) => false,
|
||||
Content::Pending(_) => None,
|
||||
Content::Ready(cache) => {
|
||||
*cache = Some(
|
||||
CacheBuilder {
|
||||
|
|
@ -190,14 +186,19 @@ where
|
|||
.build(),
|
||||
);
|
||||
|
||||
cache.as_ref().unwrap().borrow_overlay().is_some()
|
||||
cache
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.borrow_overlay()
|
||||
.as_ref()
|
||||
.map(|overlay| overlay.position())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
has_overlay.then(|| {
|
||||
has_overlay.map(|position| {
|
||||
overlay::Element::new(
|
||||
layout.position(),
|
||||
position,
|
||||
Box::new(Overlay { instance: self }),
|
||||
)
|
||||
})
|
||||
|
|
@ -265,26 +266,13 @@ where
|
|||
let element =
|
||||
view.take().unwrap()(state.last_size.unwrap_or(Size::ZERO));
|
||||
|
||||
let new_layout_hash = {
|
||||
let mut hasher = Hasher::default();
|
||||
element.hash_layout(&mut hasher);
|
||||
|
||||
hasher.finish()
|
||||
};
|
||||
|
||||
if state.last_size != Some(state.last_layout.size())
|
||||
|| new_layout_hash != state.last_layout_hash
|
||||
{
|
||||
state.last_layout = element.layout(
|
||||
renderer.deref(),
|
||||
&layout::Limits::new(
|
||||
Size::ZERO,
|
||||
state.last_size.unwrap_or(Size::ZERO),
|
||||
),
|
||||
);
|
||||
|
||||
state.last_layout_hash = new_layout_hash;
|
||||
}
|
||||
state.last_layout = element.layout(
|
||||
renderer.deref(),
|
||||
&layout::Limits::new(
|
||||
Size::ZERO,
|
||||
state.last_size.unwrap_or(Size::ZERO),
|
||||
),
|
||||
);
|
||||
|
||||
*self = Content::Ready(Some(
|
||||
CacheBuilder {
|
||||
|
|
@ -395,18 +383,6 @@ where
|
|||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher, position: Point) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
(position.x as u32).hash(state);
|
||||
(position.y as u32).hash(state);
|
||||
|
||||
self.with_overlay_maybe(|overlay| {
|
||||
overlay.hash_layout(state);
|
||||
});
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
&mut self,
|
||||
event: iced_native::Event,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue