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

Uncomment AnyView and update it to use ChangeFlags #16

Merged
merged 1 commit into from
Dec 2, 2022
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 src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

// pub mod adapt;
// pub mod any_view;
pub mod any_view;
// pub mod async_list;
pub mod button;
// pub mod layout_observer;
Expand Down
20 changes: 13 additions & 7 deletions src/view/any_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ use std::{
ops::{Deref, DerefMut},
};

use crate::{event::EventResult, id::Id, widget::AnyWidget};
use crate::{
event::EventResult,
id::Id,
widget::{AnyWidget, ChangeFlags},
};

use super::{Cx, View};

Expand All @@ -41,7 +45,7 @@ pub trait AnyView<T, A = ()> {
id: &mut Id,
state: &mut Box<dyn Any + Send>,
element: &mut Box<dyn AnyWidget>,
) -> bool;
) -> ChangeFlags;

fn dyn_event(
&self,
Expand Down Expand Up @@ -73,25 +77,27 @@ where
id: &mut Id,
state: &mut Box<dyn Any + Send>,
element: &mut Box<dyn AnyWidget>,
) -> bool {
) -> ChangeFlags {
if let Some(prev) = prev.as_any().downcast_ref() {
if let Some(state) = state.downcast_mut() {
if let Some(element) = element.deref_mut().as_any_mut().downcast_mut() {
self.rebuild(cx, prev, id, state, element)
} else {
println!("downcast of element failed in dyn_rebuild");
false
ChangeFlags::empty()
}
} else {
println!("downcast of state failed in dyn_rebuild");
false
ChangeFlags::empty()
}
} else {
let (new_id, new_state, new_element) = self.build(cx);
*id = new_id;
*state = Box::new(new_state);
*element = Box::new(new_element);
true

// Everything about the new view could be different, so return all the flags
ChangeFlags::all()
}
}

Expand Down Expand Up @@ -127,7 +133,7 @@ impl<T, A> View<T, A> for Box<dyn AnyView<T, A> + Send> {
id: &mut Id,
state: &mut Self::State,
element: &mut Self::Element,
) -> bool {
) -> ChangeFlags {
self.deref()
.dyn_rebuild(cx, prev.deref(), id, state, element)
}
Expand Down