Skip to content

Commit

Permalink
egui
Browse files Browse the repository at this point in the history
- Implemented most of the UI.
  • Loading branch information
edfloreshz committed Feb 2, 2024
1 parent c45de35 commit 0b9eaf8
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 47 deletions.
1 change: 1 addition & 0 deletions egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ edition = "2021"
[dependencies]
eframe = "0.25.0"
catppuccin-egui = "4.0"
devmode-shared = { path = "../shared" }
31 changes: 21 additions & 10 deletions egui/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod panels;

use eframe::{
egui::{CentralPanel, TopBottomPanel},
egui::{CentralPanel, Frame, TopBottomPanel},
epaint::vec2,
run_native, App, NativeOptions,
};
Expand All @@ -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");
Expand All @@ -47,22 +66,14 @@ 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),
});
});
}
}

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()
};
Expand Down
23 changes: 13 additions & 10 deletions egui/src/panels/clone.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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),
Expand All @@ -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")
}
Expand Down
51 changes: 45 additions & 6 deletions egui/src/panels/open.rs
Original file line number Diff line number Diff line change
@@ -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<Repository>,
selected: Repository,
}

impl Default for OpenPanel {
fn default() -> Self {
let repositories: Vec<Repository> = (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")
}
}
74 changes: 68 additions & 6 deletions egui/src/panels/preferences.rs
Original file line number Diff line number Diff line change
@@ -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")
}
}
54 changes: 48 additions & 6 deletions egui/src/panels/workspaces.rs
Original file line number Diff line number Diff line change
@@ -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<Workspace>,
selected: Workspace,
}

impl Default for WorkspacesPanel {
fn default() -> Self {
let workspaces: Vec<Workspace> = (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")
}
}
2 changes: 1 addition & 1 deletion shared/src/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
17 changes: 9 additions & 8 deletions shared/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)
}
}

0 comments on commit 0b9eaf8

Please sign in to comment.