mirror of
https://github.com/Zenithsiz/zsw.git
synced 2026-02-03 17:52:15 +00:00
Improved metrics tab window selector.
This commit is contained in:
parent
e6227c4bca
commit
f740040bc0
@ -81,6 +81,14 @@ impl Metrics {
|
||||
.map(|(&window_id, frame_times)| (window_id, frame_times.times.iter().copied().collect()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Returns all window ids from the metrics
|
||||
pub fn window_ids<C>(&self) -> C
|
||||
where
|
||||
C: FromIterator<WindowId>,
|
||||
{
|
||||
self.inner.lock().frame_times.keys().copied().collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// Render frame times
|
||||
|
||||
@ -5,23 +5,20 @@ use {
|
||||
crate::metrics::{Metrics, RenderFrameTime},
|
||||
core::time::Duration,
|
||||
egui::Widget,
|
||||
std::collections::HashMap,
|
||||
std::collections::{BTreeSet, HashMap},
|
||||
winit::window::WindowId,
|
||||
};
|
||||
|
||||
/// Draws the metrics tab
|
||||
#[expect(clippy::too_many_lines, reason = "TODO: Split it up")]
|
||||
pub fn draw_metrics_tab(ui: &mut egui::Ui, metrics: &Metrics) {
|
||||
// Get the window, otherwise we have nothing to render
|
||||
let Some(window_id) = self::render_window_select(ui, metrics) else {
|
||||
ui.weak("No window selected");
|
||||
return;
|
||||
};
|
||||
|
||||
let render_frame_times = metrics.render_frame_times();
|
||||
|
||||
// Use the first window as the current window if we hadn't selected one yet
|
||||
let cur_window_id = super::get_data::<Option<WindowId>>(ui, "metrics-tab-cur-window");
|
||||
let mut cur_window_id = cur_window_id.lock();
|
||||
if cur_window_id.is_none() &&
|
||||
let Some((&window_id, _)) = render_frame_times.first_key_value()
|
||||
{
|
||||
*cur_window_id = Some(window_id);
|
||||
}
|
||||
|
||||
// TODO: Turn this into some enum between histogram / time
|
||||
let is_histogram = super::get_data::<bool>(ui, "metrics-tab-histogram");
|
||||
@ -32,18 +29,8 @@ pub fn draw_metrics_tab(ui: &mut egui::Ui, metrics: &Metrics) {
|
||||
|
||||
let stack_charts = super::get_data_with_default::<bool>(ui, "metrics-tab-chart-stacks", || true);
|
||||
let mut stack_charts = stack_charts.lock();
|
||||
egui::ScrollArea::horizontal().show(ui, |ui| {
|
||||
egui::ComboBox::from_id_salt("Window")
|
||||
.selected_text(format!("{cur_window_id:?}"))
|
||||
.show_ui(ui, |ui| {
|
||||
// TODO: Get windows through another way?
|
||||
for &window_id in render_frame_times.keys() {
|
||||
ui.selectable_value(&mut *cur_window_id, Some(window_id), format!("{window_id:?}"));
|
||||
}
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
let Some(window_id) = *cur_window_id else { return };
|
||||
let mut is_paused = metrics.render_frame_times_is_paused(window_id);
|
||||
if ui.toggle_value(&mut is_paused, "Pause").changed() {
|
||||
metrics.render_frame_times_pause(window_id, is_paused);
|
||||
@ -74,9 +61,7 @@ pub fn draw_metrics_tab(ui: &mut egui::Ui, metrics: &Metrics) {
|
||||
},
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let Some(window_id) = *cur_window_id else { return };
|
||||
let Some(render_frame_times) = render_frame_times.get(&window_id) else {
|
||||
return;
|
||||
};
|
||||
@ -142,6 +127,31 @@ pub fn draw_metrics_tab(ui: &mut egui::Ui, metrics: &Metrics) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Renders the window select and returns the selected one
|
||||
pub fn render_window_select(ui: &mut egui::Ui, metrics: &Metrics) -> Option<WindowId> {
|
||||
let cur_window_id = super::get_data::<Option<WindowId>>(ui, "metrics-tab-cur-window");
|
||||
let mut cur_window_id = cur_window_id.lock();
|
||||
|
||||
let windows = metrics.window_ids::<BTreeSet<_>>();
|
||||
|
||||
// If we don't have a current window, use the first one available (if any)
|
||||
if cur_window_id.is_none() &&
|
||||
let Some(&window_id) = windows.first()
|
||||
{
|
||||
*cur_window_id = Some(window_id);
|
||||
}
|
||||
|
||||
egui::ComboBox::from_id_salt("metrics-tab-window-selector")
|
||||
.selected_text(cur_window_id.map_or("None".to_owned(), |id| format!("{id:?}")))
|
||||
.show_ui(ui, |ui| {
|
||||
for window_id in windows {
|
||||
ui.selectable_value(&mut *cur_window_id, Some(window_id), format!("{window_id:?}"));
|
||||
}
|
||||
});
|
||||
|
||||
*cur_window_id
|
||||
}
|
||||
|
||||
/// Returns the duration with index `idx`
|
||||
pub fn render_frame_time(frame_time: &RenderFrameTime, idx: usize) -> Duration {
|
||||
match idx {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user