From 4edf1e34276eb435d7bba5de3b361ceb605ce3fc Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 24 Jul 2024 11:38:30 +0800 Subject: [PATCH] Update ScrollView to let `content` is FnOnce. (#65) --- .github/workflows/ci.yml | 7 +++---- crates/ui/src/scroll/scroll_view.rs | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28a249b3..7acc6b1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/crates/ui/src/scroll/scroll_view.rs b/crates/ui/src/scroll/scroll_view.rs index fba771b0..bb955d03 100644 --- a/crates/ui/src/scroll/scroll_view.rs +++ b/crates/ui/src/scroll/scroll_view.rs @@ -17,7 +17,7 @@ pub struct ScrollView { id: ElementId, view: AnyView, axix: ScrollbarAxis, - content: Option AnyElement + 'static>>, + content: Option AnyElement + 'static>>, } impl ScrollView { @@ -52,7 +52,7 @@ impl ScrollView { #[must_use] pub fn content(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();