something something strip

This commit is contained in:
Ponj 2024-05-06 21:45:01 +02:00
parent a9224ae3fc
commit 13b6effb91
Signed by: p6nj
GPG Key ID: CEAB625B75A836B2
1 changed files with 43 additions and 26 deletions

View File

@ -1,8 +1,8 @@
use std::path::PathBuf;
use derive_new::new;
use eframe::egui::{Sense, Ui, WidgetText};
use egui_extras::{Column, TableBuilder};
use eframe::egui::{ScrollArea, Sense, TextStyle, Ui, WidgetText};
use egui_extras::{Column, Size, StripBuilder, TableBuilder};
use rfd::FileDialog;
use strum::{AsRefStr, EnumIter, IntoEnumIterator};
@ -58,33 +58,50 @@ impl egui_dock::TabViewer for TabViewer {
ui.heading(tab.kind.as_ref());
match tab.kind {
TabKind::Input => {
TableBuilder::new(ui)
.sense(Sense::click())
.column(Column::remainder())
.body(|body| {
body.rows(18.0, self.input_files.len(), |mut row| {
let index = row.index();
row.col(|ui| {
ui.label(
&self
.input_files
.get(index)
.map(|buf| {
buf.to_str().unwrap_or("[invalid UTF-8]").to_string()
})
.unwrap_or("???".to_string()),
);
let button_size = TextStyle::Button.resolve(ui.style()).size;
StripBuilder::new(ui)
.size(Size::remainder().at_least(20.0)) // for the table
.size(Size::remainder().at_most(button_size * 4.0)) // for the add and clear buttons
.vertical(|mut strip| {
strip.cell(|ui| {
ScrollArea::horizontal().show(ui, |ui| {
TableBuilder::new(ui)
.striped(true)
.sense(Sense::click())
.column(Column::remainder())
.body(|body| {
body.rows(18.0, self.input_files.len(), |mut row| {
let index = row.index();
row.col(|ui| {
ui.label(
&self
.input_files
.get(index)
.map(|buf| {
buf.to_str()
.unwrap_or("[invalid UTF-8]")
.to_string()
})
.unwrap_or("???".to_string()),
);
});
});
})
});
});
strip.cell(|ui| {
ui.vertical_centered_justified(|ui| {
if ui.button("Clear").clicked() {
self.input_files.clear();
}
if ui.button("Add").clicked() {
if let Some(mut paths) = FileDialog::new().pick_files() {
self.input_files.append(&mut paths);
}
}
});
});
});
if ui.button("Clear").clicked() {
self.input_files.clear();
}
if ui.button("Add").clicked() {
if let Some(mut paths) = FileDialog::new().pick_files() {
self.input_files.append(&mut paths);
}
}
// https://github.com/emilk/egui/blob/master/examples/file_dialog/src/main.rs
}
TabKind::Decode => todo!(),