-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is also added to `variable_clocks` as needed. This could also be added to `mason`, but I see a worrying amount of lag if I do... I could do with some help tracking this down.
- Loading branch information
Showing
4 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,6 @@ pub use prose::*; | |
|
||
mod textbox; | ||
pub use textbox::*; | ||
|
||
mod portal; | ||
pub use portal::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2024 the Xilem Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::marker::PhantomData; | ||
|
||
use masonry::widget; | ||
use xilem_core::{Mut, ViewMarker}; | ||
|
||
use crate::{Pod, View, ViewCtx, ViewId, WidgetView}; | ||
|
||
/// A view which puts `child` into a scrollable region. | ||
/// | ||
/// This corresponds to the Masonry [`Portal`](masonry::widget::Portal) widget. | ||
pub fn portal<Child, State, Action>(child: Child) -> Portal<Child, State, Action> | ||
where | ||
Child: WidgetView<State, Action>, | ||
{ | ||
Portal { | ||
child, | ||
phantom: PhantomData, | ||
} | ||
} | ||
|
||
pub struct Portal<V, State, Action> { | ||
child: V, | ||
phantom: PhantomData<(State, Action)>, | ||
} | ||
|
||
impl<V, State, Action> ViewMarker for Portal<V, State, Action> {} | ||
impl<Child, State, Action> View<State, Action, ViewCtx> for Portal<Child, State, Action> | ||
where | ||
Child: WidgetView<State, Action>, | ||
State: 'static, | ||
Action: 'static, | ||
{ | ||
type Element = Pod<widget::Portal<Child::Widget>>; | ||
type ViewState = Child::ViewState; | ||
|
||
fn build(&self, ctx: &mut ViewCtx) -> (Self::Element, Self::ViewState) { | ||
// The Portal `View` doesn't get any messages directly (yet - scroll events?), so doesn't need to | ||
// use ctx.with_id. | ||
let (child, child_state) = self.child.build(ctx); | ||
let widget_pod = Pod::new(widget::Portal::new_pod(child.inner)); | ||
(widget_pod, child_state) | ||
} | ||
|
||
fn rebuild<'el>( | ||
&self, | ||
prev: &Self, | ||
view_state: &mut Self::ViewState, | ||
ctx: &mut ViewCtx, | ||
mut element: Mut<'el, Self::Element>, | ||
) -> Mut<'el, Self::Element> { | ||
let child_element = element.child_mut(); | ||
self.child | ||
.rebuild(&prev.child, view_state, ctx, child_element); | ||
element | ||
} | ||
|
||
fn teardown( | ||
&self, | ||
view_state: &mut Self::ViewState, | ||
ctx: &mut ViewCtx, | ||
mut element: Mut<'_, Self::Element>, | ||
) { | ||
let child_element = element.child_mut(); | ||
self.child.teardown(view_state, ctx, child_element); | ||
} | ||
|
||
fn message( | ||
&self, | ||
view_state: &mut Self::ViewState, | ||
id_path: &[ViewId], | ||
message: xilem_core::DynMessage, | ||
app_state: &mut State, | ||
) -> crate::MessageResult<Action> { | ||
self.child.message(view_state, id_path, message, app_state) | ||
} | ||
} |