use eframe::egui::{Align, Context, Layout, ScrollArea, Ui};
use egui_extras::{Column, TableBody, TableBuilder};
use open_timeline_gui_core::{Draw, body_text_height, widget_x_spacing};
#[derive(Debug)]
pub struct AppInfoGui {}
impl AppInfoGui {
pub fn new() -> Self {
Self {}
}
}
impl Draw for AppInfoGui {
fn draw(&mut self, _ctx: &Context, ui: &mut Ui) {
let row_height = body_text_height(ui);
let spacing = widget_x_spacing(ui);
let available_width = ui.available_width();
let left_col_width = 150.0;
let right_col_width = available_width - left_col_width - spacing;
let right_col_width = right_col_width.max(0.0);
ScrollArea::vertical().show(ui, |ui| {
TableBuilder::new(ui)
.id_salt("stats_table_body")
.striped(true)
.column(Column::exact(left_col_width))
.column(Column::exact(right_col_width))
.body(|mut body| {
draw_info_line(&mut body, row_height, "Name", |ui| {
ui.label("OpenTimeline");
});
draw_info_line(&mut body, row_height, "Version", |ui| {
ui.label(env!("CARGO_PKG_VERSION"));
});
draw_info_line(&mut body, row_height, "Website", |ui| {
ui.hyperlink("https://www.open-timeline.org");
});
draw_info_line(&mut body, row_height, "Report Issues", |ui| {
ui.scope(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
ui.label("Email us or report on Github at ");
ui.hyperlink("https://github.com/harryhudson/open-timeline/issues");
});
});
draw_info_line(&mut body, row_height, "Email", |ui| {
ui.label("all@open-timeline.org");
});
draw_info_line(&mut body, row_height, "Operating System", |ui| {
let os = match std::env::consts::OS {
"windows" => "Windows",
"macos" => "macOS",
"linux" => "Linux",
other => other,
};
ui.label(os);
});
draw_info_line(&mut body, row_height, "Architecture", |ui| {
let arch = match std::env::consts::ARCH {
"x86_64" => "x86_64",
"aarch64" => "arm64",
other => other,
};
ui.label(arch);
});
draw_info_line(&mut body, row_height, "License", |ui| {
ui.label(
"GNU General Public License v3.0 or later (SPDX: GPL-3.0-or-later)",
);
});
draw_info_line(&mut body, row_height, "Source Code", |ui| {
ui.hyperlink("https://github.com/harryhudson/open-timeline");
});
draw_info_line(&mut body, row_height, "Copyright ©", |ui| {
ui.label("Harry Hudson");
});
});
});
}
}
pub fn draw_info_line<F>(body: &mut TableBody, row_height: f32, name: &str, value: F)
where
F: FnOnce(&mut Ui),
{
body.row(row_height, |mut row| {
row.col(|ui| {
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
open_timeline_gui_core::Label::strong(ui, name);
});
});
row.col(|ui| {
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
value(ui);
});
});
});
}