nuit_bridge_adwaita/
lib.rs1#![feature(reentrant_lock)]
2
3mod node_widget;
4
5use std::sync::{Arc, ReentrantLock};
6
7use adw::{gtk::{Box, Orientation}, prelude::*, Application, ApplicationWindow, HeaderBar};
8use node_widget::NodeWidget;
9use nuit_core::{clone, Root, View};
10
11pub fn run_app<T>(root: Root<T>) where T: View + 'static {
13 let root = Arc::new(ReentrantLock::new(root));
14 let app = Application::builder()
15 .application_id("com.example.NuitApp")
16 .build();
17
18 app.connect_activate(move |app| {
19 let node = Root::render(&root.lock());
20 let node_widget = NodeWidget::root(node, clone!(root => move |id_path, event| {
21 root.lock().fire_event(id_path, event);
22 }));
23
24 root.lock().set_update_callback(clone!(root, node_widget => move |_update| {
25 node_widget.update(Root::render(&mut root.lock()));
26 }));
27
28 let content = Box::new(Orientation::Vertical, 0);
29 content.append(&HeaderBar::new());
30 content.append(&node_widget);
31
32 let window = ApplicationWindow::builder()
33 .application(app)
34 .title("Nuit App")
35 .default_width(640)
36 .default_height(480)
37 .content(&content)
38 .build();
39 window.present();
40 });
41
42 app.run();
43}