Update ScrollView to let content is FnOnce. (#65)

This commit is contained in:
Jason Lee 2024-07-24 11:38:30 +08:00 committed by GitHub
parent e0103d1d58
commit 4edf1e3427
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 7 deletions

View file

@ -16,6 +16,8 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Install system dependencies - name: Install system dependencies
run: script/bootstrap run: script/bootstrap
- name: Machete
uses: bnjbvr/cargo-machete@main
- name: Setup | Cache Cargo - name: Setup | Cache Cargo
uses: actions/cache@v3.0.11 uses: actions/cache@v3.0.11
with: with:
@ -27,9 +29,6 @@ jobs:
target/ target/
key: ubuntu-test-cargo-${{ hashFiles('**/Cargo.lock') }} key: ubuntu-test-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Lint - name: Lint
run: | run: cargo clippy
cargo install cargo-machete
cargo machete
cargo clippy
- name: Build test - name: Build test
run: cargo build run: cargo build

View file

@ -17,7 +17,7 @@ pub struct ScrollView {
id: ElementId, id: ElementId,
view: AnyView, view: AnyView,
axix: ScrollbarAxis, axix: ScrollbarAxis,
content: Option<Box<dyn Fn(&mut WindowContext) -> AnyElement + 'static>>, content: Option<Box<dyn FnOnce(&mut WindowContext) -> AnyElement + 'static>>,
} }
impl ScrollView { impl ScrollView {
@ -52,7 +52,7 @@ impl ScrollView {
#[must_use] #[must_use]
pub fn content<F, E>(mut self, builder: F) -> Self pub fn content<F, E>(mut self, builder: F) -> Self
where where
F: Fn(&mut WindowContext) -> E + 'static, F: FnOnce(&mut WindowContext) -> E + 'static,
E: IntoElement, E: IntoElement,
{ {
self.content = Some(Box::new(move |cx| builder(cx).into_any_element())); 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 view = self.view.clone();
let scroll_id = self.id.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| { self.with_element_state(id.unwrap(), cx, |_, element_state, cx| {
let handle = element_state.handle.clone(); let handle = element_state.handle.clone();