Cleanup header and side panel layout

This commit is contained in:
Piotr Siuszko 2023-03-07 18:01:30 +01:00
parent b0bc59200b
commit 5a0f12c57e
4 changed files with 95 additions and 120 deletions

View File

@ -441,15 +441,6 @@ dependencies = [
"vec_map", "vec_map",
] ]
[[package]]
name = "catppuccin-egui"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e508ad60790f1336e5ab24da9b809826e7ea9171281cc70e894f514f37791317"
dependencies = [
"egui",
]
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.73" version = "1.0.73"
@ -1320,6 +1311,15 @@ dependencies = [
"png", "png",
] ]
[[package]]
name = "inline_tweak"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7033e97b20277cc0d043226d1940fa7719ff08d2305d1fc7421e53066d00eb4b"
dependencies = [
"lazy_static",
]
[[package]] [[package]]
name = "instant" name = "instant"
version = "0.1.12" version = "0.1.12"
@ -2024,11 +2024,11 @@ dependencies = [
name = "rusty_hub_egui" name = "rusty_hub_egui"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"catppuccin-egui",
"confy", "confy",
"eframe", "eframe",
"egui_extras", "egui_extras",
"image", "image",
"inline_tweak",
"poll-promise", "poll-promise",
"rfd", "rfd",
"unity_hub_lib", "unity_hub_lib",

View File

@ -22,7 +22,7 @@ egui_extras = "0.21.0"
unity_hub_lib = { path="../unity_hub_lib" } unity_hub_lib = { path="../unity_hub_lib" }
image = { version = "0.24.0", default-features = false, features = ["png"] } image = { version = "0.24.0", default-features = false, features = ["png"] }
rfd = "0.11.1" rfd = "0.11.1"
catppuccin-egui = "2.0" inline_tweak = "1.0.8"
poll-promise = "0.2.0" poll-promise = "0.2.0"
[target.'cfg(windows)'.build-dependencies] [target.'cfg(windows)'.build-dependencies]

View File

@ -2,3 +2,6 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE"); pub const HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");
pub const APP_NAME: &str = "Rusty Unity Hub"; pub const APP_NAME: &str = "Rusty Unity Hub";
pub const VERTICAL_SPACING: f32 = 8.0; pub const VERTICAL_SPACING: f32 = 8.0;
pub const TOP_BUTTON_WIDTH: f32 = 150.0;
pub const TOP_SIDE_MARGIN: f32 = 10.0;

View File

@ -1,15 +1,16 @@
use crate::{ use crate::{
consts::HOMEPAGE, consts::HOMEPAGE,
consts::{APP_NAME, VERSION, VERTICAL_SPACING}, consts::{APP_NAME, TOP_BUTTON_WIDTH, VERSION, VERTICAL_SPACING, TOP_SIDE_MARGIN},
window_tab::WindowTab, window_tab::WindowTab,
}; };
use eframe::{ use eframe::{
egui::{self, Layout, Ui}, egui::{self, Layout, Ui, accesskit::TextAlign},
epaint::{Color32, FontId}, epaint::{Color32, FontId, FontFamily},
}; };
use egui_extras::{Column, TableBuilder}; use egui_extras::{Column, TableBuilder};
use rfd::FileDialog; use rfd::FileDialog;
use unity_hub_lib::{consts::FILE_MANAGER, hub::Hub}; use unity_hub_lib::{consts::FILE_MANAGER, hub::Hub};
use inline_tweak::*;
pub struct HubClient { pub struct HubClient {
hub: Hub, hub: Hub,
@ -338,16 +339,12 @@ impl HubClient {
} }
fn draw_editors_header(&mut self, _ctx: &egui::Context, ui: &mut Ui) { fn draw_editors_header(&mut self, _ctx: &egui::Context, ui: &mut Ui) {
let text_height = egui::TextStyle::Body.resolve(ui.style()).size * 3.0;
let table = build_header_table(ui);
table.body(|body| {
body.rows(text_height, 1, |_, mut row| {
row.col(|ui| {
add_header(ui); add_header(ui);
});
row.col(|ui| {
if ui if ui
.button("🖴 Add new path") .add_sized(
[TOP_BUTTON_WIDTH, 20.0],
egui::Button::new("🖴 Add new path"),
)
.on_hover_text("Add new editor search path") .on_hover_text("Add new editor search path")
.clicked() .clicked()
{ {
@ -360,22 +357,16 @@ impl HubClient {
self.save_config(true); self.save_config(true);
} }
} }
}); ui.allocate_space(egui::vec2(TOP_SIDE_MARGIN, 10.0));
});
});
} }
fn draw_project_header(&mut self, _ctx: &egui::Context, ui: &mut Ui) { fn draw_project_header(&mut self, _ctx: &egui::Context, ui: &mut Ui) {
let text_height = egui::TextStyle::Body.resolve(ui.style()).size * 3.0;
let table = build_header_table(ui);
table.body(|body| {
body.rows(text_height, 1, |_, mut row| {
row.col(|ui| {
add_header(ui); add_header(ui);
});
row.col(|ui| {
if ui if ui
.button("🔭 Scan for projects") .add_sized(
[TOP_BUTTON_WIDTH, 20.0],
egui::Button::new("🔭 Scan for projects"),
)
.on_hover_text("Scan selected folder for projects") .on_hover_text("Scan selected folder for projects")
.clicked() .clicked()
{ {
@ -383,8 +374,7 @@ impl HubClient {
if let Some(dir) = directory { if let Some(dir) = directory {
let amount = self.hub.search_for_projects_at_path(&dir); let amount = self.hub.search_for_projects_at_path(&dir);
let mut message = let mut message = rfd::MessageDialog::new().set_title("Search ended");
rfd::MessageDialog::new().set_title("Search ended");
match amount { match amount {
0 => { 0 => {
@ -394,41 +384,36 @@ impl HubClient {
} }
1 => message = message.set_description("Project founded!"), 1 => message = message.set_description("Project founded!"),
_ => { _ => {
message = message.set_description(&format!( message = message.set_description(&format!("Founded {} projects.", amount))
"Founded {} projects.",
amount
))
} }
} }
message.show(); message.show();
self.save_config(true); self.save_config(true);
} }
} }
}); ui.allocate_space(egui::vec2(TOP_SIDE_MARGIN, 10.0));
});
});
} }
fn tab_button(&self, ui: &mut Ui, tab: &WindowTab, text: &str) -> bool {
let button_size = tweak!(36.0);
let font_size = tweak!(16.0);
let button_size = egui::vec2(ui.available_width(), button_size);
let rich_text = if &self.current_tab == tab { egui::RichText::new(text).strong() } else { egui::RichText::new(text).weak() }.font(FontId::new(font_size, FontFamily::Proportional));
ui.add_sized(button_size, egui::Label::new(rich_text).wrap(false).sense(egui::Sense::click()))
.clicked()
}
fn draw_side_panel(&mut self, ui: &mut Ui) { fn draw_side_panel(&mut self, ui: &mut Ui) {
ui.with_layout( ui.with_layout(
Layout::top_down_justified(eframe::emath::Align::Min), Layout::top_down(eframe::emath::Align::Min),
|ui| { |ui| {
ui.add_space(VERTICAL_SPACING); if self.tab_button(ui, &WindowTab::Projects, tweak!("📦 Projects"))
let button = egui::Button::new(egui::RichText::new("📦 Projects").heading())
.frame(&self.current_tab == &WindowTab::Projects);
if ui
.add_enabled(&self.current_tab != &WindowTab::Projects, button)
.clicked()
{ {
self.current_tab = WindowTab::Projects; self.current_tab = WindowTab::Projects;
} }
ui.add_space(VERTICAL_SPACING); if self.tab_button(ui, &WindowTab::Editors, tweak!("🛠 Editors"))
if ui
.add_enabled(
&self.current_tab != &WindowTab::Editors,
egui::Button::new(egui::RichText::new("🛠 Editors").heading())
.frame(&self.current_tab == &WindowTab::Editors),
)
.clicked()
{ {
self.current_tab = WindowTab::Editors; self.current_tab = WindowTab::Editors;
} }
@ -437,26 +422,14 @@ impl HubClient {
} }
} }
fn build_header_table(ui: &mut Ui) -> TableBuilder {
let table = TableBuilder::new(ui)
.striped(false)
.vscroll(false)
.cell_layout(egui::Layout::left_to_right(egui::Align::Center))
.column(Column::remainder())
.column(Column::initial(150.0).at_most(200.0))
.resizable(false);
table
}
fn add_header(ui: &mut Ui) { fn add_header(ui: &mut Ui) {
ui.with_layout( let header_height = tweak!(45.0);
Layout::top_down_justified(eframe::emath::Align::Min), let text =
|ui| { egui::RichText::new(APP_NAME).font(FontId::new(26.0, FontFamily::Name("semibold".into()))).strong();
use eframe::epaint::FontFamily; ui.allocate_space(egui::vec2(TOP_SIDE_MARGIN, header_height));
let text = egui::RichText::new(APP_NAME).font(FontId::new(26.0, FontFamily::Name("semibold".into())));
ui.add(egui::Label::new(text)); ui.add(egui::Label::new(text));
}, let available_width = ui.available_width() - TOP_BUTTON_WIDTH - TOP_SIDE_MARGIN - TOP_SIDE_MARGIN;
); ui.allocate_space(egui::vec2(available_width, header_height));
} }
impl eframe::App for HubClient { impl eframe::App for HubClient {
@ -465,15 +438,14 @@ impl eframe::App for HubClient {
.frame(egui::Frame::canvas(&ctx.style())) .frame(egui::Frame::canvas(&ctx.style()))
.show(ctx, |ui| { .show(ctx, |ui| {
ui.with_layout( ui.with_layout(
egui::Layout::left_to_right(egui::Align::Center).with_cross_justify(true), egui::Layout::left_to_right(egui::Align::Center).with_cross_align(eframe::emath::Align::Center),
|ui| { |ui| {
ui.add_space(14.0);
match self.current_tab { match self.current_tab {
WindowTab::Projects => self.draw_project_header(&ctx, ui), WindowTab::Projects => self.draw_project_header(&ctx, ui),
WindowTab::Editors => self.draw_editors_header(&ctx, ui), WindowTab::Editors => self.draw_editors_header(&ctx, ui),
}; };
ui.add_space(14.0); },
}); );
}); });
egui::SidePanel::left("dsadsa") egui::SidePanel::left("dsadsa")