// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
///|
struct NoOpHandler {}
///|
impl @consumer.ChangeHandler for NoOpHandler with fn node_added(_, _) {
()
}
///|
impl @consumer.ChangeHandler for NoOpHandler with fn node_updated(_, _, _) {
()
}
///|
impl @consumer.ChangeHandler for NoOpHandler with fn focus_moved(_, _, _) {
()
}
///|
impl @consumer.ChangeHandler for NoOpHandler with fn node_removed(_, _) {
()
}
///|
fn main {
let subtree_id = @lib.TreeId({ high: 0UL, low: 1UL, })
let update = @lib.TreeUpdate(@lib.TreeId::root(), NodeId(0UL))
let root = @lib.Node(Window)
root.set_children([NodeId(1UL)])
update.push_node(NodeId(0UL), root)
let graft = @lib.Node(GenericContainer)
graft.set_tree_id(subtree_id)
update.push_node(NodeId(1UL), graft)
update.set_tree(TreeInfo(NodeId(0UL)))
let tree = @consumer.Tree(update, false)
let subtree_update = @lib.TreeUpdate(subtree_id, NodeId(0UL))
let document = @lib.Node(Document)
document.set_children([NodeId(1UL)])
let button = @lib.Node(Button)
button.set_label("OK")
subtree_update.push_node(NodeId(0UL), document)
subtree_update.push_node(NodeId(1UL), button)
subtree_update.set_tree(TreeInfo(NodeId(0UL)))
tree.update_and_process_changes(subtree_update, NoOpHandler::{ })
let root_node = tree.state().root()
let filtered_children = root_node.filtered_children(@consumer.common_filter)
println("root.filtered_children(common_filter):")
for node in filtered_children {
println("- " + node.role().to_string())
}
if root_node.filtered_children(@consumer.common_filter).next()
is Some(document_node) {
let doc_children = document_node.filtered_children(@consumer.common_filter)
println("document.filtered_children(common_filter):")
for node in doc_children {
println(
"- " +
node.role().to_string() +
" label=" +
node.label().unwrap_or(""),
)
}
}
}