Skip to content

Commit

Permalink
feat(core): 🎸 overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
wjian23 authored and M-Adoo committed Mar 5, 2024
1 parent 72fce42 commit 43994c6
Show file tree
Hide file tree
Showing 19 changed files with 455 additions and 50 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he

## [@Unreleased] - @ReleaseDate

### Features

- Support the overlay (@wjian23).

This enhancement simplifies the creation of overlay widgets. It streamlines the addition of any widget to an overlay and offers a more user-friendly API for overlay management

## [0.2.0-alpha.4] - 2024-02-27

### Fixed
Expand All @@ -41,7 +47,6 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he

- fix broken links and format the example code (#526 @M-Adoo)


## [0.1.0-beta.7](https://github.com/RibirX/Ribir/compare/ribir-v0.1.0-alpha.0...ribir-v0.1.0-beta.7) - 2024-02-02

🎉🎉🎉 The first version of Ribir.
Expand Down
2 changes: 2 additions & 0 deletions core/src/builtin_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pub mod global_anchor;
pub use global_anchor::*;
mod mix_builtin;
pub use mix_builtin::*;
pub mod container;
pub use container::*;

use crate::{
prelude::*,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ribir_core::prelude::*;
use crate::prelude::*;

/// Widget with fixed size as a container for its child.
#[derive(Declare, Query, SingleChild)]
Expand Down Expand Up @@ -26,7 +26,7 @@ impl Render for Container {
#[cfg(test)]
mod tests {
use super::*;
use ribir_core::test_helper::*;
use crate::test_helper::*;
use ribir_dev_helper::*;
use ribir_geom::Size;

Expand Down
2 changes: 1 addition & 1 deletion core/src/builtin_widgets/focus_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mod tests {

let wnd = TestWindow::new(widget);
let tree = wnd.widget_tree.borrow();
let id = tree.root();
let id = tree.content_root();
let node = id.get(&tree.arena).unwrap();
let mut cnt = 0;
node.query_type_inside_first(|b: &MixBuiltin| {
Expand Down
4 changes: 2 additions & 2 deletions core/src/builtin_widgets/focus_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod tests {

focus_mgr.refresh_focus(arena);

let id0 = tree.root().first_child(arena).unwrap();
let id0 = tree.content_root().first_child(arena).unwrap();
let scope = id0.next_sibling(arena).unwrap();
let scope_id1 = scope.first_child(arena).unwrap();
let scope_id2 = scope_id1.next_sibling(arena).unwrap();
Expand Down Expand Up @@ -126,7 +126,7 @@ mod tests {
focus_mgr.refresh_focus(&widget_tree.arena);

let arena = &widget_tree.arena;
let id0 = widget_tree.root().first_child(arena).unwrap();
let id0 = widget_tree.content_root().first_child(arena).unwrap();
let scope = id0.next_sibling(arena).unwrap();
let id1 = scope.next_sibling(arena).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion core/src/builtin_widgets/global_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::rc::Rc;
#[derive(Declare, Query, Default)]
pub struct GlobalAnchor {
#[declare(builtin, default)]
global_anchor: Anchor,
pub global_anchor: Anchor,
}

impl ComposeChild for GlobalAnchor {
Expand Down
7 changes: 1 addition & 6 deletions core/src/context/build_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ impl<'a> BuildCtx<'a> {

/// Dispose the whole subtree of `id`, include `id` itself.
pub(crate) fn dispose_subtree(&self, id: WidgetId) {
let mut tree = self.tree.borrow_mut();
let parent = id.parent(&tree.arena);
tree.detach(id);
tree
.window()
.add_delay_event(DelayEvent::Disposed { id, parent });
id.dispose_subtree(&mut self.tree.borrow_mut());
}

pub(crate) fn mark_dirty(&self, id: WidgetId) { self.tree.borrow_mut().mark_dirty(id); }
Expand Down
14 changes: 7 additions & 7 deletions core/src/events/focus_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,13 @@ impl FocusManager {

// bubble focus out
if let Some(old) = old {
let ancestor = node.and_then(|w| w.common_ancestors(old, &tree.arena).next());
let ancestor = node.and_then(|w| w.lowest_common_ancestor(old, &tree.arena));
wnd.add_delay_event(DelayEvent::FocusOut { bottom: old, up: ancestor });
};

if let Some(new) = node {
wnd.add_delay_event(DelayEvent::Focus(new));
let ancestor = old.and_then(|o| o.common_ancestors(new, &tree.arena).next());
let ancestor = old.and_then(|o| o.lowest_common_ancestor(new, &tree.arena));
wnd.add_delay_event(DelayEvent::FocusIn { bottom: new, up: ancestor });
}

Expand Down Expand Up @@ -570,7 +570,7 @@ mod tests {

focus_mgr.refresh_focus(&tree.arena);

let id = tree.root().first_child(&tree.arena);
let id = tree.content_root().first_child(&tree.arena);
assert!(id.is_some());
assert_eq!(focus_mgr.focusing(), id);
}
Expand All @@ -592,7 +592,7 @@ mod tests {
let tree = wnd.widget_tree.borrow();

let id = tree
.root()
.content_root()
.first_child(&tree.arena)
.and_then(|p| p.next_sibling(&tree.arena));
assert!(id.is_some());
Expand Down Expand Up @@ -623,7 +623,7 @@ mod tests {

focus_mgr.refresh_focus(arena);

let negative = widget_tree.root().first_child(arena).unwrap();
let negative = widget_tree.content_root().first_child(arena).unwrap();
let id0 = negative.next_sibling(arena).unwrap();
let id1 = id0.next_sibling(arena).unwrap();
let id2 = id1.next_sibling(arena).unwrap();
Expand Down Expand Up @@ -713,7 +713,7 @@ mod tests {
let log = widget.log.clone();
let mut wnd = TestWindow::new(fn_widget!(widget));
let tree = wnd.widget_tree.borrow();
let parent = tree.root();
let parent = tree.content_root();
let child = parent.first_child(&tree.arena).unwrap();
drop(tree);

Expand Down Expand Up @@ -813,7 +813,7 @@ mod tests {
let mut focus_mgr = wnd.focus_mgr.borrow_mut();
let tree = wnd.widget_tree.borrow();

let first_box = tree.root().first_child(&tree.arena);
let first_box = tree.content_root().first_child(&tree.arena);
let focus_scope = first_box.unwrap().next_sibling(&tree.arena);
focus_mgr.request_focus_to(focus_scope);

Expand Down
3 changes: 3 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod widget;
pub mod widget_children;
pub mod window;
pub use rxrust;
pub mod overlay;

pub mod prelude {
pub use crate::animation::*;
Expand All @@ -37,6 +38,8 @@ pub mod prelude {
#[doc(no_inline)]
pub use crate::events::*;
#[doc(no_inline)]
pub use crate::overlay::{Overlay, OverlayCloseHandle};
#[doc(no_inline)]
pub use crate::pipe::{BoxPipe, FinalChain, MapPipe, ModifiesPipe, Pipe};
#[doc(no_inline)]
pub use crate::state::*;
Expand Down
Loading

0 comments on commit 43994c6

Please sign in to comment.