Skip to content

Commit

Permalink
feat(core): 🎸 Added Overlay::of to allow querying the overlay in ev…
Browse files Browse the repository at this point in the history
…ent callbacks

BREAKING CHANGE: 🧨 Removed `Overlay::new_with_handle`, `OverlayCloseHandle` and
`OverlayStyle`
  • Loading branch information
M-Adoo authored and rchangelog[bot] committed Aug 20, 2024
1 parent 81df5bb commit e4448cd
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 240 deletions.
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he

### Features

- **core**: Support for modifying the theme at runtime. (#pr @M-Adoo)
- **core**: Support for modifying the theme at runtime. (#618 @M-Adoo)
<img src="./static/theme-switch.gif" style="transform:scale(0.5);"/>

The code:
Expand All @@ -53,7 +53,7 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he
App::run(w);
```

- **core**: Added `Provider` widget to share data between sub-tree. (#pr @M-Adoo)
- **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! {
@SizedBox {
Expand All @@ -75,12 +75,14 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he
});
```

- **core**: Added `WidgetCtx::query`, `WidgetCtx::query_write`, `WidgetCtx::query_of_widget` and `WidgetCtx::query_write_of_widget`. (#pr @M-Adoo)
- **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)

### Breaking

- **core**: Removed `Overlay::new_with_handle` and `OverlayCloseHandle`. (#618 @M-Adoo)
- **core**: `GenWidget::gen_widget` no longer requires a `&mut BuildCtx` parameter. (#616 @M-Adoo)
- **core**: Removed `FullTheme` and `InheritTheme`, now only using `Theme`. Any part of the theme, such as `Palette`, can be directly used to overwrite its corresponding theme component. (#pr @M-Adoo)
- **core**: Removed `FullTheme` and `InheritTheme`, now only using `Theme`. Any part of the theme, such as `Palette`, can be directly used to overwrite its corresponding theme component. (#618 @M-Adoo)

## [0.4.0-alpha.5] - 2024-08-14

Expand Down Expand Up @@ -115,7 +117,7 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he

### Breaking

- Removed `WidgetCtx::query_widget_type` and `WidgetCtx::query_type` (#pr @M-Adoo)
- Removed `WidgetCtx::query_widget_type` and `WidgetCtx::query_type` (#618 @M-Adoo)
- Removed `ChildFrom` and `FromAnother` traits (#612 @M-Adoo)
- Removed `SingleParent` and `MultiParent` traits. (#612 @M-Adoo)
- Removed `PairChild` and `PairWithChild` traits. User can use a generic type instead. (#612 @M-Adoo)
Expand Down
1 change: 1 addition & 0 deletions core/src/builtin_widgets/global_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl<W> FatObj<W> {
/// Anchor the widget's horizontal position by placing its left edge right to
/// the left edge of the specified widget (`wid`) with the given relative
/// pixel value (`relative`).
// Todo: Should we control the subscription in the inner part?
pub fn left_align_to(
&mut self, wid: &LazyWidgetId, offset: f32, ctx: &BuildCtx,
) -> impl Subscription {
Expand Down
2 changes: 1 addition & 1 deletion core/src/builtin_widgets/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub enum Brightness {
///
/// Every descendant widget of the theme can query it or its parts.
///
/// ```
/// ```no_run
/// use ribir::prelude::*;
///
/// let w = fn_widget! {
Expand Down
10 changes: 10 additions & 0 deletions core/src/context/widget_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub trait WidgetCtx {
fn widget_id(&self) -> WidgetId;
/// Return parent of widget of this context.
fn parent(&self) -> Option<WidgetId>;
// Determine if the current widget in the context is an ancestor of `w`.
fn ancestor_of(&self, w: WidgetId) -> bool;
// Determine if the current widget in the context is an successor of `w`.
fn successor_of(&self, w: WidgetId) -> bool;
/// Return parent of widget `w`.
fn widget_parent(&self, w: WidgetId) -> Option<WidgetId>;
/// Return the single child of `widget`.
Expand Down Expand Up @@ -98,6 +102,12 @@ impl<T: WidgetCtxImpl> WidgetCtx for T {
#[inline]
fn parent(&self) -> Option<WidgetId> { self.id().parent(self.tree()) }

#[inline]
fn ancestor_of(&self, w: WidgetId) -> bool { self.id().ancestor_of(w, self.tree()) }

#[inline]
fn successor_of(&self, w: WidgetId) -> bool { w.ancestor_of(self.id(), self.tree()) }

#[inline]
fn widget_parent(&self, w: WidgetId) -> Option<WidgetId> { w.parent(self.tree()) }

Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub mod prelude {
#[doc(no_inline)]
pub use crate::events::*;
#[doc(no_inline)]
pub use crate::overlay::{Overlay, OverlayCloseHandle};
pub use crate::overlay::Overlay;
#[doc(no_inline)]
pub use crate::pipe::{BoxPipe, FinalChain, MapPipe, ModifiesPipe, Pipe};
#[doc(no_inline)]
Expand Down
Loading

0 comments on commit e4448cd

Please sign in to comment.