Skip to content

Commit

Permalink
Update ScrollView to let content is FnOnce. (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee authored Jul 24, 2024
1 parent e0103d1 commit 4edf1e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
Expand All @@ -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
6 changes: 3 additions & 3 deletions crates/ui/src/scroll/scroll_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4edf1e3

Please sign in to comment.