Skip to content

Commit ffede84

Browse files
committed
feat: panelize tables
1 parent aa30678 commit ffede84

File tree

2 files changed

+30
-54
lines changed

2 files changed

+30
-54
lines changed

src/app.rs

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,18 @@ use std::{
66

77
#[cfg(not(target_arch = "wasm32"))]
88
use anyhow::{bail, Context};
9-
use egui_extras::{Column, Size, StripBuilder, TableBuilder};
9+
use egui_extras::{Column, TableBuilder};
1010
use log::info;
1111

1212
use self::{data::Data, data_display_options::DataDisplayOptions};
1313

1414
mod data;
1515
mod data_display_options;
1616

17-
const SPACE_BETWEEN_TABLES: f32 = 10.;
18-
19-
// TODO 3: Replace current setup with using resizable panels https://github.com/emilk/egui/blob/34db001db14940c948eb03d3fe87f2af2c45daba/crates/egui_demo_lib/src/demo/panels.rs#L26
20-
2117
#[derive(serde::Deserialize, serde::Serialize)]
2218
#[serde(default)] // if we add new fields, give them default values when deserializing old state
2319
pub struct LogViewerApp {
2420
data: Option<Data>,
25-
main_table_screen_proportion: f32,
2621
data_display_options: DataDisplayOptions,
2722
start_open_path: Arc<Mutex<Option<PathBuf>>>,
2823
last_filename: Arc<Mutex<Option<PathBuf>>>,
@@ -36,7 +31,6 @@ impl Default for LogViewerApp {
3631
fn default() -> Self {
3732
Self {
3833
data: Default::default(),
39-
main_table_screen_proportion: 0.5,
4034
data_display_options: Default::default(),
4135
start_open_path: Default::default(),
4236
loading_status: Default::default(),
@@ -330,12 +324,6 @@ impl LogViewerApp {
330324

331325
fn ui_options(&mut self, ui: &mut egui::Ui) {
332326
ui.collapsing("Options", |ui| {
333-
ui.add(
334-
egui::DragValue::new(&mut self.main_table_screen_proportion)
335-
.speed(0.01)
336-
.clamp_range(0.2..=0.85)
337-
.prefix("Main Area Proportion Percentage "),
338-
);
339327
ui.checkbox(&mut self.show_last_filename, "Show last filename");
340328
});
341329
}
@@ -472,51 +460,39 @@ impl eframe::App for LogViewerApp {
472460
self.ui_help(ui);
473461
ui.separator();
474462

475-
egui::ScrollArea::vertical()
476-
.id_source("scroll for overflow")
477-
.show(ui, |ui| {
478-
StripBuilder::new(ui)
479-
.size(Size::relative(self.main_table_screen_proportion)) // for the log lines
480-
.size(Size::exact(SPACE_BETWEEN_TABLES)) // for the log lines
481-
.size(Size::remainder()) // for the details area
482-
.vertical(|mut strip| {
483-
strip.cell(|ui| {
484-
egui::ScrollArea::horizontal().id_source("log lines").show(
485-
ui,
486-
|ui| {
487-
ui.push_id("table log lines", |ui| self.show_log_lines(ui));
488-
},
489-
);
490-
});
491-
strip.cell(|ui| {
492-
expanding_content(ui);
493-
});
494-
strip.cell(|ui| {
495-
egui::ScrollArea::horizontal()
496-
.id_source("details area")
497-
.show(ui, |ui| {
498-
ui.push_id("table details", |ui| self.show_log_details(ui));
499-
});
500-
});
463+
const MIN_LOG_LINES_SIZE: f32 = 100.0;
464+
let max_details_height = ui.available_height() - MIN_LOG_LINES_SIZE;
465+
466+
egui::TopBottomPanel::bottom("details_panel")
467+
.resizable(true)
468+
.default_height(200.)
469+
.max_height(max_details_height)
470+
.min_height(60.)
471+
.show_inside(ui, |ui| {
472+
ui.vertical_centered(|ui| {
473+
ui.heading("Details");
474+
});
475+
egui::ScrollArea::horizontal()
476+
.id_source("details area")
477+
.show(ui, |ui| {
478+
ui.push_id("table details", |ui| self.show_log_details(ui));
501479
});
480+
if ui.available_height() > 0.0 {
481+
ui.allocate_space(ui.available_size());
482+
}
502483
});
484+
485+
egui::CentralPanel::default().show_inside(ui, |ui| {
486+
egui::ScrollArea::horizontal()
487+
.id_source("log lines")
488+
.show(ui, |ui| {
489+
ui.push_id("table log lines", |ui| self.show_log_lines(ui));
490+
});
491+
});
503492
});
504493
}
505494
}
506495

507-
fn expanding_content(ui: &mut egui::Ui) {
508-
// Taken from https://github.com/emilk/egui/blob/15370bbea0b468cf719a75cc6d1e39eb00c420d8/crates/egui_demo_lib/src/demo/table_demo.rs#L276
509-
let width = ui.available_width();
510-
let height = ui.available_height();
511-
let (rect, response) = ui.allocate_exact_size(egui::vec2(width, height), egui::Sense::hover());
512-
response.on_hover_text("See options to change size");
513-
ui.painter().hline(
514-
rect.x_range(),
515-
rect.center().y,
516-
(2.0, ui.visuals().text_color()),
517-
);
518-
}
519-
520496
pub fn calculate_hash<T: Hash + ?Sized>(t: &T) -> u64 {
521497
let mut s = DefaultHasher::new();
522498
t.hash(&mut s);

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ async fn main() -> eframe::Result<()> {
99

1010
let native_options = eframe::NativeOptions {
1111
viewport: egui::ViewportBuilder::default()
12-
.with_inner_size([400.0, 300.0])
13-
.with_min_inner_size([300.0, 220.0])
12+
.with_inner_size([800.0, 600.0])
13+
.with_min_inner_size([400.0, 400.0])
1414
.with_icon(
1515
eframe::icon_data::from_png_bytes(&include_bytes!("../assets/icon-256.png")[..])
1616
.unwrap(),

0 commit comments

Comments
 (0)