Skip to content

Commit

Permalink
Iced!
Browse files Browse the repository at this point in the history
- Added iced project.
  • Loading branch information
edfloreshz committed Feb 3, 2024
1 parent f4b530e commit 083c6df
Show file tree
Hide file tree
Showing 27 changed files with 261 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
members = ["gui", "cli", "egui"]
members = ["cli", "shared", "gui/slint", "gui/iced", "gui/egui"]
2 changes: 1 addition & 1 deletion egui/Cargo.toml → gui/egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2021"
[dependencies]
eframe = "0.25.0"
catppuccin-egui = "4.0"
devmode-shared = { path = "../shared" }
devmode-shared = { path = "../../shared" }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions gui/iced/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "iced"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
iced = "0.10.0"
strum = { version = "0.26.1", features = ["derive"] }
devmode-shared = { path = "../../shared" }
101 changes: 101 additions & 0 deletions gui/iced/src/app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use iced::{
widget::{button, column, container, horizontal_rule, row, text},
Length, Theme,
};
use strum::{Display, EnumIter, IntoEnumIterator};

use crate::pages::{ClonePanel, OpenPanel, PreferencesPanel, WorkspacesPanel};

#[derive(Debug, Default)]
pub struct Devmode {
theme: Theme,
pages: Vec<Page>,
selected: Page,
clone: ClonePanel,
open: OpenPanel,
workspaces: WorkspacesPanel,
preferences: PreferencesPanel,
}

#[derive(Debug, Clone)]
pub enum Message {
SwitchPage(Page),
SelectRepo(Repository),
}

#[derive(Debug, Default, PartialEq, EnumIter, Display, Clone)]
enum Page {
#[default]
Clone,
Open,
Workspaces,
Preferences,
}

#[derive(Debug, Default, PartialEq, Clone)]
pub struct Repository {
pub name: String,
pub url: String,
}

impl iced::Sandbox for Devmode {
type Message = Message;

fn new() -> Self {
Devmode {
theme: Theme::Dark,
pages: Page::iter().collect(),
selected: Page::default(),
..Default::default()
}
}

fn title(&self) -> String {
String::from("Devmode")
}

fn update(&mut self, message: Self::Message) {
match message {
Message::SwitchPage(page) => self.selected = page,
Message::SelectRepo(repo) => print!("Selected repo: {repo:?}"),
}
}

fn view(&self) -> iced::Element<'_, Self::Message> {
container(column!(self.tab_bar(), horizontal_rule(1), self.content()).spacing(10.0))
.padding(10.0)
.into()
}

fn theme(&self) -> Theme {
self.theme.clone()
}
}

impl Devmode {
fn tab_bar(&self) -> iced::Element<'_, Message> {
let pages = self
.pages
.iter()
.map(|page| {
button(text(page.to_string()))
.on_press(Message::SwitchPage(page.clone()))
.width(iced::Length::Fill)
.into()
})
.collect::<Vec<iced::Element<'_, Message>>>();

container(row(pages).spacing(5.0))
.width(Length::Fill)
.into()
}

fn content(&self) -> iced::Element<'_, Message> {
match self.selected {
Page::Clone => self.clone.ui(),
Page::Open => self.open.ui(),
Page::Workspaces => self.workspaces.ui(),
Page::Preferences => self.preferences.ui(),
}
}
}
9 changes: 9 additions & 0 deletions gui/iced/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use app::Devmode;
use iced::Application;

mod app;
mod pages;

fn main() -> iced::Result {
Devmode::run(iced::Settings::default())
}
42 changes: 42 additions & 0 deletions gui/iced/src/pages/clone.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use iced::widget::{button, column, text};

use crate::app::{Message, Repository};

#[derive(Debug)]
pub struct ClonePanel {
repositories: Vec<Repository>,
selected: Repository,
url: String,
}

impl Default for ClonePanel {
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(),
url: String::default(),
}
}
}

impl ClonePanel {
pub(crate) fn ui(&self) -> iced::Element<'_, Message> {
let repositories = self
.repositories
.iter()
.map(|repo| {
button(text(&repo.name))
.on_press(Message::SelectRepo(repo.clone()))
.width(iced::Length::Fill)
.into()
})
.collect::<Vec<iced::Element<'_, Message>>>();
column(repositories).into()
}
}
9 changes: 9 additions & 0 deletions gui/iced/src/pages/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod clone;
pub mod open;
pub mod preferences;
pub mod workspaces;

pub use clone::ClonePanel;
pub use open::OpenPanel;
pub use preferences::PreferencesPanel;
pub use workspaces::WorkspacesPanel;
30 changes: 30 additions & 0 deletions gui/iced/src/pages/open.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use iced::widget::text;

use crate::app::{Message, 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) -> iced::Element<'_, Message> {
text("Open").into()
}
}
22 changes: 22 additions & 0 deletions gui/iced/src/pages/preferences.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use devmode_shared::{application::Application, editor::Editor, host::Host, settings::Settings};
use iced::widget::text;

use crate::app::Message;

#[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) -> iced::Element<'_, Message> {
text("Preferences").into()
}
}
34 changes: 34 additions & 0 deletions gui/iced/src/pages/workspaces.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use iced::widget::text;

use crate::app::Message;

#[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) -> iced::Element<'_, Message> {
text("Workspaces").into()
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion gui/Cargo.toml → gui/slint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "dmg"
path = "src/main.rs"

[dependencies]
devmode-shared = { path = "../shared" }
devmode-shared = { path = "../../shared" }
git2 = "0.14.4"
slint = "1.4"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 083c6df

Please sign in to comment.