[librsvg] Node.foreach_child(): New function.
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Node.foreach_child(): New function.
- Date: Tue, 19 Dec 2017 23:35:28 +0000 (UTC)
commit 30978e89f85bdd25fd96d1c12d4467d7fd2914d7
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 19 14:32:44 2017 -0600
Node.foreach_child(): New function.
Implement rsvg_node_foreach_child() in terms of that, and also
Node.draw_children().
rust/src/node.rs | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/rust/src/node.rs b/rust/src/node.rs
index b4b4b44..38cbeff 100644
--- a/rust/src/node.rs
+++ b/rust/src/node.rs
@@ -3,8 +3,7 @@ use ::glib_sys;
use ::glib::translate::*;
use ::libc;
-use std::rc::Rc;
-use std::rc::Weak;
+use std::rc::{Rc, Weak};
use std::cell::RefCell;
use std::ptr;
@@ -208,18 +207,31 @@ impl Node {
drawing_ctx::push_discrete_layer (draw_ctx);
}
- for child in &*self.children.borrow () {
+ self.foreach_child(|child| {
let boxed_child = box_node (child.clone ());
drawing_ctx::draw_node_from_stack (draw_ctx, boxed_child, 0);
rsvg_node_unref (boxed_child);
- }
+
+ true
+ });
if dominate != -1 {
drawing_ctx::pop_discrete_layer (draw_ctx);
}
}
+
+ pub fn foreach_child<F>(&self, f: F)
+ where F: Fn(Rc<Node>) -> bool
+ {
+ for c in &*self.children.borrow() {
+ let next = f(c.clone());
+ if !next {
+ break;
+ }
+ }
+ }
}
// Sigh, rsvg_state_free() is only available if we are being linked into
@@ -383,17 +395,15 @@ pub extern fn rsvg_node_foreach_child (raw_node: *const RsvgNode, func: NodeFore
assert! (!raw_node.is_null ());
let node: &RsvgNode = unsafe { & *raw_node };
- for child in &*node.children.borrow () {
+ node.foreach_child(|child| {
let boxed_child = box_node (child.clone ());
let next: bool = unsafe { from_glib (func (boxed_child, data)) };
rsvg_node_unref (boxed_child);
- if !next {
- break;
- }
- }
+ next
+ });
}
#[no_mangle]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]