Skip to content

Commit

Permalink
feat: initial ui for clone
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed Jul 5, 2024
1 parent 6b11a45 commit 46ff890
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 70 deletions.
3 changes: 2 additions & 1 deletion src/ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ i18n-embed-fl = "0.8"
once_cell = "1.19.0"
open = "5.1.3"
rust-embed = "8.3.0"
slotmap = "1.0.7"
tokio = { version = "1.37.0", features = ["full"] }

[dependencies.libcosmic]
Expand All @@ -24,4 +25,4 @@ features = ["dbus-config", "tokio", "winit", "wgpu"]

[dependencies.i18n-embed]
version = "0.14"
features = ["fluent-system", "desktop-requester"]
features = ["fluent-system", "desktop-requester"]
2 changes: 1 addition & 1 deletion src/ui/justfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name := 'cosmic-app-template'
export APPID := 'com.example.CosmicAppTemplate'
export APPID := 'dev.edfloreshz.Devmode'

rootdir := ''
prefix := '/usr'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Exec=cosmic-app-template %F
Terminal=false
Type=Application
StartupNotify=true
Icon=com.example.CosmicAppTemplate
Icon=dev.edfloreshz.Devmode
Categories=COSMIC;Utility;
Keywords=Folder;Manager;
MimeType=inode/directory;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>com.example.CosmicAppTemplate</id>
<id>dev.edfloreshz.Devmode</id>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-3.0-only</project_license>
<project_group>COSMIC</project_group>
Expand All @@ -13,8 +13,8 @@
<description>
<p>A template for COSMIC applications</p>
</description>
<launchable type="desktop-id">com.example.CosmicAppTemplate.desktop</launchable>
<icon type="remote" height="256" width="256">https://raw.githubusercontent.com/edfloreshz/cosmic-app-template/master/res/icons/hicolor/256x256/apps/com.example.CosmicAppTemplate.svg</icon>
<launchable type="desktop-id">dev.edfloreshz.Devmode.desktop</launchable>
<icon type="remote" height="256" width="256">https://raw.githubusercontent.com/edfloreshz/cosmic-app-template/master/res/icons/hicolor/256x256/apps/dev.edfloreshz.Devmode.svg</icon>
<screenshots>
</screenshots>
<provides>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

103 changes: 53 additions & 50 deletions src/ui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use std::collections::HashMap;

use crate::fl;
use crate::pages::clone;
use crate::{fl, pages};
use cosmic::app::{Command, Core};
use cosmic::iced::alignment::{Horizontal, Vertical};
use cosmic::iced::{Alignment, Length};
Expand All @@ -13,14 +14,12 @@ const REPOSITORY: &str = "https://github.com/edfloreshz/cosmic-app-template";

/// This is the struct that represents your application.
/// It is used to define the data that will be used by your application.
pub struct YourApp {
/// Application state which is managed by the COSMIC runtime.
pub struct Devmode {
core: Core,
/// Display a context drawer with the designated page if defined.
context_page: ContextPage,
/// Key bindings for the application's menu bar.
page: Page,
clone: pages::clone::ClonePage,
key_binds: HashMap<menu::KeyBind, MenuAction>,
/// A model that contains all of the pages assigned to the nav bar panel.
nav: nav_bar::Model,
}

Expand All @@ -31,13 +30,15 @@ pub struct YourApp {
pub enum Message {
LaunchUrl(String),
ToggleContextPage(ContextPage),
Clone(clone::Message),
}

/// Identifies a page in the application.
pub enum Page {
Page1,
Page2,
Page3,
Clone,
Workspaces,
Open,
Config,
}

/// Identifies a context page to display in the context drawer.
Expand Down Expand Up @@ -78,14 +79,14 @@ impl menu::action::MenuAction for MenuAction {
/// - `Flags` is the data that your application needs to use before it starts.
/// - `Message` is the enum that contains all the possible variants that your application will need to transmit messages.
/// - `APP_ID` is the unique identifier of your application.
impl Application for YourApp {
impl Application for Devmode {
type Executor = cosmic::executor::Default;

type Flags = ();

type Message = Message;

const APP_ID: &'static str = "com.example.CosmicAppTemplate";
const APP_ID: &'static str = "dev.edfloreshz.Devmode";

fn core(&self) -> &Core {
&self.core
Expand All @@ -111,31 +112,36 @@ impl Application for YourApp {
let mut nav = nav_bar::Model::default();

nav.insert()
.text("Page 1")
.data::<Page>(Page::Page1)
.icon(icon::from_name("applications-science-symbolic"))
.text("Clone")
.data::<Page>(Page::Clone)
.icon(icon::from_name("browser-download-symbolic"))
.activate();

nav.insert()
.text("Page 2")
.data::<Page>(Page::Page2)
.icon(icon::from_name("applications-system-symbolic"));
.text("Workspaces")
.data::<Page>(Page::Workspaces)
.icon(icon::from_name("multitasking-symbolic"));

nav.insert()
.text("Page 3")
.data::<Page>(Page::Page3)
.icon(icon::from_name("applications-games-symbolic"));
.text("Open")
.data::<Page>(Page::Open)
.icon(icon::from_name("folder-open-symbolic"));

let mut app = YourApp {
nav.insert()
.text("Config")
.data::<Page>(Page::Config)
.icon(icon::from_name("settings-symbolic"));

let app = Devmode {
core,
context_page: ContextPage::default(),
page: Page::Clone,
clone: pages::clone::ClonePage::new(),
key_binds: HashMap::new(),
nav,
};

let command = app.update_titles();

(app, command)
(app, Command::none())
}

/// Elements to pack at the start of the header bar.
Expand All @@ -151,15 +157,19 @@ impl Application for YourApp {
vec![menu_bar.into()]
}

/// This is the main view of your application, it is the root of your widget tree.
///
/// The `Element` type is used to represent the visual elements of your application,
/// it has a `Message` associated with it, which dictates what type of message it can send.
///
/// To get a better sense of which widgets are available, check out the `widget` module.
fn view(&self) -> Element<Self::Message> {
widget::text::title1(fl!("welcome"))
let spacing = theme::active().cosmic().spacing;

let page: Element<Self::Message> = match self.page {
Page::Clone => self.clone.view().map(Message::Clone),
Page::Workspaces => todo!(),
Page::Open => todo!(),
Page::Config => todo!(),
};

widget::container(page)
.apply(widget::container)
.padding(spacing.space_xxs)
.width(Length::Fill)
.height(Length::Fill)
.align_x(Horizontal::Center)
Expand All @@ -172,6 +182,15 @@ impl Application for YourApp {
/// background thread managed by the application's executor.
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
match message {
Message::Clone(message) => {
for command in self.clone.update(message) {
match command {
clone::Command::Clone(_repository, _workspace) => {
todo!("Implement cloning mechanism.")
}
}
}
}
Message::LaunchUrl(url) => {
let _result = open::that_detached(url);
}
Expand Down Expand Up @@ -209,18 +228,17 @@ impl Application for YourApp {
// Activate the page in the model.
self.nav.activate(id);

self.update_titles()
Command::none()
}
}

impl YourApp {
impl Devmode {
/// The about page for this app.
pub fn about(&self) -> Element<Message> {
let cosmic_theme::Spacing { space_xxs, .. } = theme::active().cosmic().spacing;

let icon = widget::svg(widget::svg::Handle::from_memory(
&include_bytes!("../res/icons/hicolor/128x128/apps/com.example.CosmicAppTemplate.svg")
[..],
&include_bytes!("../res/icons/hicolor/scalable/apps/dev.edfloreshz.Devmode.svg")[..],
));

let title = widget::text::title3(fl!("app-title"));
Expand All @@ -237,19 +255,4 @@ impl YourApp {
.spacing(space_xxs)
.into()
}

/// Updates the header and window titles.
pub fn update_titles(&mut self) -> Command<Message> {
let mut window_title = fl!("app-title");
let mut header_title = String::new();

if let Some(page) = self.nav.text(self.nav.active()) {
window_title.push_str(" — ");
window_title.push_str(page);
header_title.push_str(page);
}

self.set_header_title(header_title);
self.set_window_title(window_title)
}
}
5 changes: 3 additions & 2 deletions src/ui/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-only

use app::YourApp;
use app::Devmode;
/// The `app` module is used by convention to indicate the main component of our application.
mod app;
mod core;
mod pages;

/// The `cosmic::app::run()` function is the starting point of your application.
/// It takes two arguments:
Expand All @@ -12,5 +13,5 @@ mod core;
/// If your app does not need any flags, you can pass in `()`.
fn main() -> cosmic::iced::Result {
let settings = cosmic::app::Settings::default();
cosmic::app::run::<YourApp>(settings, ())
cosmic::app::run::<Devmode>(settings, ())
}
1 change: 1 addition & 0 deletions src/ui/src/pages.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod clone;
Loading

0 comments on commit 46ff890

Please sign in to comment.