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

Update ScrollView to let content is FnOnce. #65

Merged
merged 3 commits into from
Jul 24, 2024
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
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
Loading