Skip to content

Commit

Permalink
refactor(core): 💡 make providers accessible in all contexts and enhan…
Browse files Browse the repository at this point in the history
…ce their efficiency
  • Loading branch information
M-Adoo committed Jan 9, 2025
1 parent 95ea963 commit 8d490cb
Show file tree
Hide file tree
Showing 61 changed files with 1,978 additions and 1,660 deletions.
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he

### Features

- **macros**: Added the `part_reader!` macro to generate a partial reader from a reference of a reader. (#pr @M-Adoo)
- **macros**: Added the `part_reader!` macro to generate a partial reader from a reference of a reader. (#688 @M-Adoo)
- **macros**: The `simple_declare` now supports the `stateless` meta attribute, `#[simple_declare(stateless)]`. (#688 @M-Adoo)

## [0.4.0-alpha.22] - 2025-01-08

Expand Down Expand Up @@ -100,7 +101,6 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he
- **core**: Added the `named_svgs` module to enable sharing SVGs using string keys, replacing the need for `IconTheme`. (#658 @M-Adoo)
- **core**: The `keyframes!` macro has been introduced to manage the intermediate steps of animation states. (#653 @M-Adoo)
- **core**: Added `QueryId` as a replacement for `TypeId` to facilitate querying types by Provider across different binaries. (#656 @M-Adoo)
- **core**: Added `OverrideClass` to override a single class within a subtree. (#657 @M-Adoo)
- **widgets**: Added `LinearProgress` and `SpinnerProgress` widgets along with their respective material themes. (#630 @wjian23 @M-Adoo)
- **painter**: SVG now supports switching the default color, allowing for icon color changes. (#661 @M-Adoo)

Expand Down Expand Up @@ -285,7 +285,12 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he
- **core**: Added `Provider` widget to share data between sub-tree. (#618 @M-Adoo)

```rust
Provider::new(Box::new(State::value(0i32))).with_child(fn_widget! {
let state = Stateful::value(0132);
providers!{
providers: smallvec![
Provider::new(state.clone_writer()),
Provider::value_of_state(state)
],
@SizedBox {
size: Size::new(1.,1.),
on_tap: |e| {
Expand All @@ -302,9 +307,8 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he
}
}
}
});
}
```

- **core**: Added `Overlay::of` to allow querying the overlay in event callbacks. (#618 @M-Adoo)
- **core**: Added `WidgetCtx::query`, `WidgetCtx::query_write`, `WidgetCtx::query_of_widget` and `WidgetCtx::query_write_of_widget`. (#618 @M-Adoo)

Expand Down
7 changes: 1 addition & 6 deletions core/src/animation/stagger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,7 @@ mod tests {
let c_stagger = stagger.clone_writer();
let w = fn_widget! {
let mut mock_box = @MockBox { size: Size::new(100., 100.) };
$stagger.write().push_state(
mock_box
.get_opacity_widget()
.map_writer(|w| PartData::from_ref_mut(&mut w.opacity)),
0.,
);
$stagger.write().push_state(part_writer!(&mut mock_box.opacity),0.);
stagger.run();

mock_box
Expand Down
10 changes: 7 additions & 3 deletions core/src/builtin_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ mod mix_builtin;
pub use mix_builtin::*;
pub mod container;
pub use container::*;
mod provider;
pub use provider::*;
mod class;
pub use class::*;
mod constrained_box;
Expand All @@ -82,6 +80,8 @@ mod text;
pub use text::*;
mod tooltips;
pub use tooltips::*;
mod providers;
pub use providers::*;

use crate::prelude::*;

Expand Down Expand Up @@ -409,7 +409,11 @@ impl<T> FatObj<T> {
/// doesn't exist, a new one will be created.
pub fn get_text_style_widget(&mut self) -> &State<TextStyleWidget> {
self.text_style.get_or_insert_with(|| {
State::value(TextStyleWidget { text_style: BuildCtx::get().text_style().clone() })
State::value(TextStyleWidget {
text_style: Provider::of::<TextStyle>(BuildCtx::get())
.unwrap()
.clone(),
})
})
}

Expand Down
Loading

0 comments on commit 8d490cb

Please sign in to comment.