Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaults for View trait methods #147

Merged
merged 1 commit into from
Nov 5, 2023
Merged

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Nov 5, 2023

This adds default methods to the View trait which generally work with views with or without children. This is quite helpful in reducing code duplication across view impls. It also serves as a reference for new view implementations.

for_each_child and for_each_child_mut are added to View to iterate over children without allocation. The children and children_mut methods can probably be removed, but I haven't looked carefully at their uses yet.

@Zoxc Zoxc changed the title Add default for View trait methods Add defaults for View trait methods Nov 5, 2023
Copy link

codecov bot commented Nov 5, 2023

Codecov Report

Merging #147 (a0e54ca) into main (c4cd0d1) will increase coverage by 0.21%.
The diff coverage is 0.00%.

@@           Coverage Diff            @@
##            main    #147      +/-   ##
========================================
+ Coverage   4.99%   5.20%   +0.21%     
========================================
  Files         56      56              
  Lines      11328   10868     -460     
========================================
  Hits         566     566              
+ Misses     10762   10302     -460     
Files Coverage Δ
src/views/empty.rs 0.00% <ø> (ø)
src/views/img.rs 0.00% <ø> (ø)
src/views/label.rs 0.00% <ø> (ø)
src/views/rich_text.rs 0.00% <ø> (ø)
src/views/svg.rs 0.00% <ø> (ø)
src/views/text_input.rs 8.30% <ø> (+0.14%) ⬆️
src/views/clip.rs 0.00% <0.00%> (ø)
src/views/container.rs 0.00% <0.00%> (ø)
src/views/container_box.rs 0.00% <0.00%> (ø)
src/views/drag_resize_window_area.rs 0.00% <0.00%> (ø)
... and 9 more

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

fn event(&mut self, cx: &mut EventCx, id_path: Option<&[Id]>, event: Event) -> bool {
let mut handled = false;
self.for_each_child_mut(&mut |child| {
handled |= cx.view_event(child, id_path, event.clone());
Copy link
Contributor

@dzhou121 dzhou121 Nov 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll probably need to break out if the event is handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning true breaks the loop here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right

@dzhou121 dzhou121 merged commit 41e8ce2 into lapce:main Nov 5, 2023
9 checks passed
@Zoxc Zoxc deleted the view-child-defaults branch November 5, 2023 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants