diff --git a/egui/Cargo.toml b/egui/Cargo.toml index 8291b68..d845f4d 100644 --- a/egui/Cargo.toml +++ b/egui/Cargo.toml @@ -8,3 +8,4 @@ edition = "2021" [dependencies] eframe = "0.25.0" catppuccin-egui = "4.0" +devmode-shared = { path = "../shared" } diff --git a/egui/src/main.rs b/egui/src/main.rs index c3fec9d..7a2b121 100644 --- a/egui/src/main.rs +++ b/egui/src/main.rs @@ -1,7 +1,7 @@ mod panels; use eframe::{ - egui::{CentralPanel, TopBottomPanel}, + egui::{CentralPanel, Frame, TopBottomPanel}, epaint::vec2, run_native, App, NativeOptions, }; @@ -26,12 +26,31 @@ enum Panel { Preferences, } +#[derive(Debug, Default, PartialEq, Clone)] +pub struct Repository { + name: String, + url: String, +} + impl App for Devmode { fn update(&mut self, ctx: &eframe::egui::Context, _: &mut eframe::Frame) { // catppuccin_egui::set_theme(&ctx, catppuccin_egui::MOCHA); ctx.style_mut(|s| { s.spacing.button_padding = vec2(20.0, 10.0); }); + + TopBottomPanel::bottom("footer").show(ctx, |ui| { + ui.style_mut().spacing.item_spacing = vec2(10.0, 10.0); + Frame::central_panel(ui.style()).show(ui, |ui| { + ui.vertical_centered_justified(|ui| match self.open_panel { + Panel::Clone => self.clone.footer(ui), + Panel::Open => self.open.footer(ui), + Panel::Workspaces => self.workspaces.footer(ui), + Panel::Preferences => self.preferences.footer(ui), + }); + }); + }); + CentralPanel::default().show(ctx, |ui| { ui.horizontal(|ui| { ui.selectable_value(&mut self.open_panel, Panel::Clone, "Clone"); @@ -47,15 +66,6 @@ impl App for Devmode { Panel::Preferences => self.preferences.ui(ui), } }); - - TopBottomPanel::bottom("footer").show(ctx, |ui| { - ui.vertical_centered_justified(|ui| match self.open_panel { - Panel::Clone => self.clone.footer(ui), - Panel::Open => self.open.footer(ui), - Panel::Workspaces => self.workspaces.footer(ui), - Panel::Preferences => self.preferences.footer(ui), - }); - }); } } @@ -63,6 +73,7 @@ fn main() -> Result<(), eframe::Error> { let options = NativeOptions { vsync: true, follow_system_theme: true, + window_builder: Some(Box::new(|vp| vp.with_min_inner_size(vec2(400.0, 300.0)))), centered: true, ..Default::default() }; diff --git a/egui/src/panels/clone.rs b/egui/src/panels/clone.rs index 22e2bf4..fd58cd1 100644 --- a/egui/src/panels/clone.rs +++ b/egui/src/panels/clone.rs @@ -1,4 +1,9 @@ -use eframe::egui::{Layout, Response, ScrollArea, TextEdit, Ui}; +use eframe::{ + egui::{Layout, Response, ScrollArea, TextEdit, Ui}, + epaint::vec2, +}; + +use crate::Repository; #[derive(Debug)] pub struct ClonePanel { @@ -23,18 +28,13 @@ impl Default for ClonePanel { } } -#[derive(Debug, Default, PartialEq, Clone)] -struct Repository { - name: String, - url: String, -} - impl ClonePanel { pub(crate) fn ui(&mut self, ui: &mut Ui) -> Response { ScrollArea::vertical().show(ui, |ui| { - ui.strong("Repositories"); + ui.heading("Remote repositories"); + ui.separator(); ui.vertical(|ui| { - ScrollArea::vertical().max_height(300.0).show(ui, |ui| { + ScrollArea::vertical().show(ui, |ui| { // Use the `Layout` API to justify the content vertically ui.with_layout( Layout::top_down(eframe::emath::Align::Min).with_cross_justify(true), @@ -54,7 +54,10 @@ impl ClonePanel { pub(crate) fn footer(&mut self, ui: &mut Ui) -> Response { ui.horizontal(|ui| { ui.label("URL:"); - ui.add_sized(ui.available_size(), TextEdit::singleline(&mut self.url)); + ui.add_sized( + ui.available_size(), + TextEdit::singleline(&mut self.url).margin(vec2(10.0, 10.0)), + ); }); ui.button("Clone") } diff --git a/egui/src/panels/open.rs b/egui/src/panels/open.rs index 4f1377f..124e6a3 100644 --- a/egui/src/panels/open.rs +++ b/egui/src/panels/open.rs @@ -1,14 +1,53 @@ -use eframe::egui::{Response, Ui}; +use eframe::egui::{Layout, Response, ScrollArea, Ui}; -#[derive(Debug, Default)] -pub struct OpenPanel; +use crate::Repository; + +#[derive(Debug)] +pub struct OpenPanel { + repositories: Vec, + selected: Repository, +} + +impl Default for OpenPanel { + fn default() -> Self { + let repositories: Vec = (0..20) + .map(|i| Repository { + name: "Test".to_string(), + url: i.to_string(), + }) + .collect(); + Self { + repositories: repositories.clone(), + selected: repositories.first().unwrap().to_owned(), + } + } +} impl OpenPanel { - pub(crate) fn ui(&self, ui: &mut Ui) -> Response { - ui.label("Open") + pub(crate) fn ui(&mut self, ui: &mut Ui) -> Response { + ScrollArea::vertical().show(ui, |ui| { + ui.heading("Local repositories"); + ui.separator(); + ui.vertical(|ui| { + ScrollArea::vertical().show(ui, |ui| { + // Use the `Layout` API to justify the content vertically + ui.with_layout( + Layout::top_down(eframe::emath::Align::Min).with_cross_justify(true), + |ui| { + for repo in &self.repositories { + let name = repo.name.clone(); + ui.selectable_value(&mut self.selected, repo.clone(), &name); + } + }, + ); + }) + }); + }); + ui.separator() } pub(crate) fn footer(&mut self, ui: &mut Ui) -> Response { - ui.label("Footer") + ui.button("Open"); + ui.button("Add to workspace") } } diff --git a/egui/src/panels/preferences.rs b/egui/src/panels/preferences.rs index 6d3622d..4ec4a9a 100644 --- a/egui/src/panels/preferences.rs +++ b/egui/src/panels/preferences.rs @@ -1,14 +1,76 @@ -use eframe::egui::{Response, Ui}; +use devmode_shared::{application::Application, editor::Editor, host::Host, settings::Settings}; +use eframe::{ + egui::{ComboBox, Response, TextEdit, Ui}, + epaint::vec2, +}; -#[derive(Debug, Default)] -pub struct PreferencesPanel; +#[derive(Debug)] +pub struct PreferencesPanel { + settings: Settings, +} + +impl Default for PreferencesPanel { + fn default() -> Self { + let settings = Settings::current().unwrap_or_default(); + Self { settings } + } +} impl PreferencesPanel { - pub(crate) fn ui(&self, ui: &mut Ui) -> Response { - ui.label("Preferences") + pub(crate) fn ui(&mut self, ui: &mut Ui) -> Response { + ui.heading("Preferences"); + ui.separator(); + ui.style_mut().spacing.item_spacing = vec2(10.0, 10.0); + ui.strong("Git Service"); + ui.horizontal(|ui| { + ComboBox::from_label("Select your prefered git service provider.") + .selected_text(self.settings.host.clone()) + .show_ui(ui, |ui| { + ui.selectable_value( + &mut self.settings.host, + Host::GitHub.to_string(), + "GitHub", + ); + ui.selectable_value( + &mut self.settings.host, + Host::GitLab.to_string(), + "GitLab", + ); + }); + }); + ui.strong("Git username"); + ui.horizontal(|ui| { + ui.add_sized( + ui.available_size(), + TextEdit::singleline(&mut self.settings.owner).margin(vec2(10.0, 10.0)), + ) + }); + ui.strong("Editor"); + ui.horizontal(|ui| { + ComboBox::from_label("Select your favorite editor.") + .selected_text(self.settings.editor.app.clone().to_string()) + .show_ui(ui, |ui| { + ui.selectable_value( + &mut self.settings.editor, + Editor::new(Application::VSCode), + Application::VSCode.to_string(), + ); + ui.selectable_value( + &mut self.settings.editor, + Editor::new(Application::Vim), + Application::Vim.to_string(), + ); + ui.selectable_value( + &mut self.settings.editor, + Editor::new(Application::Custom), + Application::Custom.to_string(), + ); + }); + }); + ui.separator() } pub(crate) fn footer(&mut self, ui: &mut Ui) -> Response { - ui.label("Footer") + ui.button("Save") } } diff --git a/egui/src/panels/workspaces.rs b/egui/src/panels/workspaces.rs index 7c1928c..e9ebc99 100644 --- a/egui/src/panels/workspaces.rs +++ b/egui/src/panels/workspaces.rs @@ -1,14 +1,56 @@ -use eframe::egui::{Response, Ui}; +use eframe::egui::{Layout, Response, ScrollArea, Ui}; -#[derive(Debug, Default)] -pub struct WorkspacesPanel; +#[derive(Debug)] +pub struct WorkspacesPanel { + workspaces: Vec, + selected: Workspace, +} + +impl Default for WorkspacesPanel { + fn default() -> Self { + let workspaces: Vec = (0..20) + .map(|i| Workspace { + name: i.to_string(), + }) + .collect(); + Self { + workspaces: workspaces.clone(), + selected: workspaces.first().unwrap().to_owned(), + } + } +} + +#[derive(Debug, Default, PartialEq, Clone)] +pub struct Workspace { + name: String, +} impl WorkspacesPanel { - pub(crate) fn ui(&self, ui: &mut Ui) -> Response { - ui.label("Workspaces") + pub(crate) fn ui(&mut self, ui: &mut Ui) -> Response { + ScrollArea::vertical().show(ui, |ui| { + ui.heading("Workspaces"); + ui.separator(); + ui.vertical(|ui| { + ScrollArea::vertical().show(ui, |ui| { + // Use the `Layout` API to justify the content vertically + ui.with_layout( + Layout::top_down(eframe::emath::Align::Min).with_cross_justify(true), + |ui| { + for ws in &self.workspaces { + let name = ws.name.clone(); + ui.selectable_value(&mut self.selected, ws.clone(), &name); + } + }, + ); + }) + }); + }); + ui.separator() } pub(crate) fn footer(&mut self, ui: &mut Ui) -> Response { - ui.label("Footer") + ui.button("Add"); + ui.button("Edit"); + ui.button("Remove") } } diff --git a/shared/src/clone.rs b/shared/src/clone.rs index b251989..b94610a 100644 --- a/shared/src/clone.rs +++ b/shared/src/clone.rs @@ -61,7 +61,7 @@ impl CloneAction { } let path = home() .join("Developer") - .join(Host::from(self.url.host.as_ref().unwrap()).name()) + .join(Host::from(self.url.host.as_ref().unwrap()).to_string()) .join(self.url.owner.as_ref().unwrap()) .join(self.workspace.as_ref().unwrap_or(&String::default())) .join(self.url.name.clone()); diff --git a/shared/src/host.rs b/shared/src/host.rs index 323250c..3e4ba9d 100644 --- a/shared/src/host.rs +++ b/shared/src/host.rs @@ -28,17 +28,18 @@ impl Host { Host::None } } - pub fn name(&self) -> &str { - match self { - Host::GitHub => GH_NAME, - Host::GitLab => GL_NAME, - Host::None => NONE, - } - } } impl Display for Host { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.name()) + write!( + f, + "{}", + match self { + Host::GitHub => GH_NAME, + Host::GitLab => GL_NAME, + Host::None => NONE, + } + ) } }