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 committed Aug 20, 2024
1 parent dce7351 commit 4fa2a38
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 235 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he
});
```

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

### Breaking

- **core**: Removed `Overlay::new_with_handle` and `OverlayCloseHandle`. (#pr @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)

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 4fa2a38

Please sign in to comment.