1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
use crate::app::MyApp;
use crate::windows::dir_window::ui_dir_windows;
use eframe::egui::MenuBar;
use eframe::egui::TopBottomPanel;
use eframe::egui::Window;
#[expect(unused)] // TODO(EGUI-TRACING)
use egui_toast::Toast;
#[expect(unused)] // TODO(EGUI-TRACING)
use egui_toast::ToastKind;
#[expect(unused)] // TODO(EGUI-TRACING)
use egui_toast::ToastOptions;
#[expect(unused)] // TODO(EGUI-TRACING)
use tracing::Level;
impl MyApp {
pub fn draw_app(&mut self, ctx: &eframe::egui::Context) {
let app = self;
// Top menu bar with About and Logs
TopBottomPanel::top("top_panel").show(ctx, |ui| {
MenuBar::new().ui(ui, |ui| {
// Logs toggle button
if ui
.button(if app.logs_visible {
"Logs (on)"
} else {
"Logs"
})
.clicked()
{
app.logs_visible = !app.logs_visible;
}
// About button
if ui.button("About").clicked() {
app.about_open = !app.about_open;
}
// Right-align Quit (if desired) placeholder
ui.with_layout(
eframe::egui::Layout::right_to_left(eframe::egui::Align::Center),
|ui| {
if ui.button("Quit").clicked() {
ctx.send_viewport_cmd(eframe::egui::ViewportCommand::Close);
}
},
);
});
});
// Draw existing windows as tiles in the central panel
eframe::egui::CentralPanel::default().show(ctx, |ui| {
// Compute app pointer first, then borrow the behavior.
let app_ptr = app as *mut _;
let behavior = &mut app.tiles_behavior;
behavior.set_app(app_ptr);
app.tiles.ui(behavior, ui);
behavior.clear_app();
// Handle pending behavior requests that must be done outside of the tree UI pass
use egui_tiles::Tile;
use egui_tiles::Container;
// Add requested Home tabs
let add_count = behavior.take_pending_new_home_tabs();
if add_count > 0 {
for _ in 0..add_count {
let new_pane = app.tiles.tiles.insert_pane(crate::tiles::Pane::Home);
if let Some(root) = app.tiles.root && let Some(Tile::Container(Container::Tabs(tabs))) = app.tiles.tiles.get_mut(root) {
tabs.add_child(new_pane);
tabs.set_active(new_pane);
}
}
}
// Open a resources tab if requested
if behavior.take_pending_open_resources_tab() {
let new_pane = app.tiles.tiles.insert_pane(crate::tiles::Pane::Resources);
if let Some(root) = app.tiles.root && let Some(Tile::Container(Container::Tabs(tabs))) = app.tiles.tiles.get_mut(root) {
tabs.add_child(new_pane);
tabs.set_active(new_pane);
}
}
// Ensure there is at least one Home tab if requested
if behavior.take_ensure_home_tab() {
if app.tiles.root.is_none() {
let home = app.tiles.tiles.insert_pane(crate::tiles::Pane::Home);
let root = app.tiles.tiles.insert_tab_tile(vec![home]);
app.tiles.root = Some(root);
} else if let Some(root) = app.tiles.root {
// Check empty using an immutable borrow first to avoid double mutable borrows.
let need_home = matches!(app.tiles.tiles.get(root), Some(Tile::Container(Container::Tabs(tabs))) if tabs.children.is_empty());
if need_home {
let new_child = app.tiles.tiles.insert_pane(crate::tiles::Pane::Home);
if let Some(Tile::Container(Container::Tabs(tabs_mut))) = app.tiles.tiles.get_mut(root) {
tabs_mut.add_child(new_child);
tabs_mut.set_active(new_child);
}
}
}
}
});
// Keep directory pop-out windows for now
ui_dir_windows(app, ctx);
// About window
if app.about_open {
Window::new("About")
.resizable(false)
.collapsible(false)
.anchor(eframe::egui::Align2::CENTER_CENTER, [0.0, 0.0])
.open(&mut app.about_open)
.show(ctx, |ui| {
ui.vertical_centered(|ui| {
ui.heading("cloud_terrastodon_ui_egui");
ui.add_space(10.0);
ui.label(app.app_info.to_string());
ui.add_space(10.0);
ui.label("UI for the Cloud Terrastodon project.");
ui.add_space(10.0);
ui.hyperlink_to("GitHub", "https://github.com/TeamDman/cloud-terrastodon");
});
});
}
// TODO(EGUI-TRACING)
// Logs window (egui_tracing widget)
// if app.logs_visible {
// Window::new("Logs")
// .default_size([800.0, 400.0])
// .open(&mut app.logs_visible)
// .show(ctx, |ui| {
// let collector = cloud_terrastodon_tracing::event_collector();
// ui.add(egui_tracing::Logs::new(collector));
// });
// }
// TODO(EGUI-TRACING)
// Process new tracing events and create toasts for INFO and ERROR levels
// let collector = cloud_terrastodon_tracing::event_collector();
// let events = collector.events();
// let new_events = &events[app.last_seen_event_count..];
// for event in new_events {
// let kind = match event.level {
// Level::INFO => Some(ToastKind::Info),
// Level::ERROR => Some(ToastKind::Error),
// _ => None,
// };
// if let Some(kind) = kind {
// let message = event
// .fields
// .get("message")
// .map_or("", std::string::String::as_str)
// .to_string();
// app.toasts.add(
// Toast::default().kind(kind).text(message).options(
// ToastOptions::default()
// .duration_in_seconds(5.0)
// .show_progress(true)
// .show_icon(true),
// ),
// );
// }
// }
// app.last_seen_event_count = events.len();
// Show toasts
app.toasts.show(ctx);
}
}