Update ScrollView to let content is FnOnce. (#65)
This commit is contained in:
parent
e0103d1d58
commit
4edf1e3427
2 changed files with 6 additions and 7 deletions
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
|
|
@ -16,6 +16,8 @@ jobs:
|
|||
- uses: actions/checkout@v4
|
||||
- name: Install system dependencies
|
||||
run: script/bootstrap
|
||||
- name: Machete
|
||||
uses: bnjbvr/cargo-machete@main
|
||||
- name: Setup | Cache Cargo
|
||||
uses: actions/cache@v3.0.11
|
||||
with:
|
||||
|
|
@ -27,9 +29,6 @@ jobs:
|
|||
target/
|
||||
key: ubuntu-test-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
- name: Lint
|
||||
run: |
|
||||
cargo install cargo-machete
|
||||
cargo machete
|
||||
cargo clippy
|
||||
run: cargo clippy
|
||||
- name: Build test
|
||||
run: cargo build
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub struct ScrollView {
|
|||
id: ElementId,
|
||||
view: AnyView,
|
||||
axix: ScrollbarAxis,
|
||||
content: Option<Box<dyn Fn(&mut WindowContext) -> AnyElement + 'static>>,
|
||||
content: Option<Box<dyn FnOnce(&mut WindowContext) -> AnyElement + 'static>>,
|
||||
}
|
||||
|
||||
impl ScrollView {
|
||||
|
|
@ -52,7 +52,7 @@ impl ScrollView {
|
|||
#[must_use]
|
||||
pub fn content<F, E>(mut self, builder: F) -> Self
|
||||
where
|
||||
F: Fn(&mut WindowContext) -> E + 'static,
|
||||
F: FnOnce(&mut WindowContext) -> E + 'static,
|
||||
E: IntoElement,
|
||||
{
|
||||
self.content = Some(Box::new(move |cx| builder(cx).into_any_element()));
|
||||
|
|
@ -125,7 +125,7 @@ impl Element for ScrollView {
|
|||
let view = self.view.clone();
|
||||
|
||||
let scroll_id = self.id.clone();
|
||||
let content = self.content.as_ref().map(|c| c(cx));
|
||||
let content = self.content.take().map(|c| c(cx));
|
||||
|
||||
self.with_element_state(id.unwrap(), cx, |_, element_state, cx| {
|
||||
let handle = element_state.handle.clone();
|
||||
|
|
|
|||
Loading…
Reference in a new issue