Update layout
This commit is contained in:
parent
cad032d4af
commit
f5e5267530
|
|
@ -565,6 +565,15 @@ dependencies = [
|
|||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "egui_extras"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f698f685bb0ad39e87109e2f695ded0bccde77d5d40bbf7590cb5561c1e3039d"
|
||||
dependencies = [
|
||||
"egui",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "egui_glow"
|
||||
version = "0.19.0"
|
||||
|
|
@ -1600,6 +1609,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"confy",
|
||||
"eframe",
|
||||
"egui_extras",
|
||||
"image",
|
||||
"rfd",
|
||||
"rusty_hub",
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
name = "rusty_hub_egui"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
homepage = "https://github.com/Leinnan/rusty_hub"
|
||||
|
||||
[profile.release]
|
||||
opt-level = 'z'
|
||||
|
|
@ -16,6 +17,7 @@ opt-level = 2
|
|||
[dependencies]
|
||||
confy = "^0.5.0"
|
||||
eframe = "0.19.0"
|
||||
egui_extras = "0.19.0"
|
||||
rusty_hub = { path="../rusty_hub" }
|
||||
image = { version = "0.24.0", default-features = false, features = ["png"] }
|
||||
rfd = "0.10.0"
|
||||
|
|
@ -1,13 +1,18 @@
|
|||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
extern crate confy;
|
||||
use eframe::{
|
||||
egui::{self, Ui},
|
||||
egui::{self, Layout, Ui},
|
||||
epaint::Color32,
|
||||
IconData, NativeOptions,
|
||||
};
|
||||
use egui_extras::{Size, TableBuilder};
|
||||
use rfd::FileDialog;
|
||||
use rusty_hub::hub::Hub;
|
||||
use std::io::Cursor;
|
||||
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
const HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");
|
||||
|
||||
fn main() {
|
||||
let img = image::io::Reader::new(Cursor::new(include_bytes!("../static/hub.png")))
|
||||
.with_guessed_format()
|
||||
|
|
@ -26,6 +31,7 @@ fn main() {
|
|||
fullscreen: false,
|
||||
drag_and_drop_support: false,
|
||||
initial_window_size: Some(egui::vec2(820.0, 400.0)),
|
||||
min_window_size: Some(egui::vec2(420.0, 400.0)),
|
||||
icon_data: Some(icon),
|
||||
..NativeOptions::default()
|
||||
};
|
||||
|
|
@ -36,35 +42,7 @@ fn main() {
|
|||
);
|
||||
}
|
||||
|
||||
fn setup_custom_fonts(ctx: &egui::Context) {
|
||||
// Start with the default fonts (we will be adding to them rather than replacing them).
|
||||
let mut fonts = egui::FontDefinitions::default();
|
||||
|
||||
// Install my own font (maybe supporting non-latin characters).
|
||||
// .ttf and .otf files supported.
|
||||
fonts.font_data.insert(
|
||||
"my_font".to_owned(),
|
||||
egui::FontData::from_static(include_bytes!("../static/FiraCode-VF.ttf")),
|
||||
);
|
||||
|
||||
// Put my font first (highest priority) for proportional text:
|
||||
fonts
|
||||
.families
|
||||
.entry(egui::FontFamily::Proportional)
|
||||
.or_default()
|
||||
.insert(0, "my_font".to_owned());
|
||||
|
||||
// Put my font as last fallback for monospace:
|
||||
fonts
|
||||
.families
|
||||
.entry(egui::FontFamily::Monospace)
|
||||
.or_default()
|
||||
.push("my_font".to_owned());
|
||||
|
||||
// Tell egui to use these fonts:
|
||||
ctx.set_fonts(fonts);
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum WindowTab {
|
||||
Projects,
|
||||
Editors,
|
||||
|
|
@ -76,7 +54,6 @@ struct MyApp {
|
|||
|
||||
impl MyApp {
|
||||
fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||
//setup_custom_fonts(&cc.egui_ctx);
|
||||
Self {
|
||||
hub: confy::load("lwa_unity_hub", "config").unwrap(),
|
||||
current_tab: WindowTab::Projects,
|
||||
|
|
@ -101,10 +78,15 @@ impl MyApp {
|
|||
.num_columns(3)
|
||||
.show(ui, |ui| {
|
||||
match self.current_tab {
|
||||
WindowTab::Projects => self.draw_project(&ctx, ui),
|
||||
WindowTab::Projects => (),
|
||||
WindowTab::Editors => self.draw_editors(&ctx, ui),
|
||||
};
|
||||
});
|
||||
|
||||
match self.current_tab {
|
||||
WindowTab::Projects => self.draw_project(&ctx, ui),
|
||||
WindowTab::Editors => (),
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -146,31 +128,78 @@ impl MyApp {
|
|||
}
|
||||
}
|
||||
fn draw_project(&mut self, _ctx: &egui::Context, ui: &mut Ui) {
|
||||
let mut index: usize = 0;
|
||||
for project in &self.hub.projects {
|
||||
ui.scope(|ui| {
|
||||
ui.set_enabled(self.hub.editor_for_project(project).is_some());
|
||||
let text_height = egui::TextStyle::Body.resolve(ui.style()).size * 2.0;
|
||||
|
||||
let table = TableBuilder::new(ui)
|
||||
.striped(true)
|
||||
.cell_layout(egui::Layout::left_to_right(egui::Align::Center))
|
||||
.column(Size::initial(150.0).at_least(150.0))
|
||||
.column(Size::initial(90.0).at_least(40.0))
|
||||
.column(Size::remainder().at_least(260.0))
|
||||
.resizable(true);
|
||||
|
||||
table
|
||||
.header(20.0, |mut header| {
|
||||
header.col(|ui| {
|
||||
ui.heading("Name");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.heading("Version");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.heading("Directory");
|
||||
});
|
||||
})
|
||||
.body(|body| {
|
||||
body.rows(
|
||||
text_height,
|
||||
self.hub.projects.len(),
|
||||
|row_index, mut row| {
|
||||
let project = &self.hub.projects[row_index];
|
||||
let editor_for_project_exists =
|
||||
self.hub.editor_for_project(project).is_some();
|
||||
row.col(|ui| {
|
||||
ui.set_enabled(editor_for_project_exists);
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
if ui
|
||||
.button(format!("Open {}", &project.title))
|
||||
.on_disabled_hover_text(format!("Select different Unity version"))
|
||||
.button(format!("{}", &project.title))
|
||||
.on_disabled_hover_text(format!(
|
||||
"Select different Unity version"
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
self.hub.run_project_nr(index);
|
||||
self.hub.run_project_nr(row_index);
|
||||
}
|
||||
});
|
||||
ui.set_enabled(true);
|
||||
});
|
||||
|
||||
row.col(|ui| {
|
||||
ui.with_layout(
|
||||
Layout::top_down_justified(eframe::emath::Align::Center),
|
||||
|ui| {
|
||||
let mut text = egui::RichText::new(&project.version);
|
||||
if !editor_for_project_exists {
|
||||
text = text.color(Color32::RED);
|
||||
}
|
||||
let version_response =
|
||||
ui.add(egui::Label::new(&project.version).sense(egui::Sense::click()));
|
||||
ui.add(egui::Label::new(text).sense(egui::Sense::click()));
|
||||
version_response.context_menu(|ui| {
|
||||
for editor in &self.hub.config.editors_configurations {
|
||||
if ui.button(format!("Open in {}", &editor.version)).clicked() {
|
||||
if ui
|
||||
.button(format!("Open in {}", &editor.version))
|
||||
.clicked()
|
||||
{
|
||||
Hub::run_project(&editor, &project);
|
||||
ui.close_menu();
|
||||
}
|
||||
}
|
||||
});
|
||||
let path_response = ui.add(egui::Label::new(&project.path).sense(egui::Sense::click()));
|
||||
},
|
||||
);
|
||||
});
|
||||
row.col(|ui| {
|
||||
let path_response =
|
||||
ui.add(egui::Label::new(&project.path).sense(egui::Sense::click()));
|
||||
path_response.context_menu(|ui| {
|
||||
if ui.button("Open directory").clicked() {
|
||||
use std::process::Command;
|
||||
|
|
@ -178,28 +207,53 @@ impl MyApp {
|
|||
ui.close_menu();
|
||||
}
|
||||
});
|
||||
ui.end_row();
|
||||
index = index + 1;
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::TopBottomPanel::top("topPanel").show(ctx, |ui| {
|
||||
ui.label("Rusty Unity Hub");
|
||||
ui.add_space(5.0);
|
||||
let text = egui::RichText::new(" Rusty Unity Hub").heading().strong();
|
||||
ui.add(egui::Label::new(text));
|
||||
ui.add_space(5.0);
|
||||
});
|
||||
egui::SidePanel::left("dsadsa").show(ctx, |ui| {
|
||||
ui.set_height(25.0);
|
||||
ui.add_space(14.0);
|
||||
if ui.button("Projects").clicked() {
|
||||
egui::SidePanel::left("dsadsa")
|
||||
.resizable(false)
|
||||
.show(ctx, |ui| {
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
ui.add_space(5.0);
|
||||
|
||||
let button =
|
||||
egui::Button::new(egui::RichText::new("Projects").heading()).frame(false);
|
||||
if ui
|
||||
.add_enabled(&self.current_tab != &WindowTab::Projects, button)
|
||||
.clicked()
|
||||
{
|
||||
self.current_tab = WindowTab::Projects;
|
||||
}
|
||||
ui.add_space(14.0);
|
||||
if ui.button("Editors").clicked() {
|
||||
ui.add_space(5.0);
|
||||
if ui
|
||||
.add_enabled(
|
||||
&self.current_tab != &WindowTab::Editors,
|
||||
egui::Button::new(egui::RichText::new("Editors").heading())
|
||||
.frame(false),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.current_tab = WindowTab::Editors;
|
||||
}
|
||||
});
|
||||
});
|
||||
self.draw_central_panel(&ctx);
|
||||
egui::TopBottomPanel::bottom("bottomPanel").show(ctx, |ui| {
|
||||
ui.with_layout(Layout::top_down(eframe::emath::Align::Max), |ui| {
|
||||
ui.hyperlink_to(format!("v {}", VERSION), HOMEPAGE)
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue