initial commit

This commit is contained in:
roux 2023-07-13 22:54:49 -06:00
commit 31af51d0bd
4 changed files with 2429 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

2241
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "waffle"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
image = "0.24"
willow-desktop = { git = "https://github.com/hearth-rs/willow", rev = "de4ef03" }
winit = "0.28"

175
src/main.rs Normal file
View File

@ -0,0 +1,175 @@
use willow_desktop::willow_react::{self, willow_server};
use willow_react::*;
use willow_server::{glam::*, Operation, Shape};
use winit::{event::WindowEvent, event_loop::EventLoopProxy};
#[derive(Clone, Debug)]
struct ApplicationContent {
pub application_type: String,
pub name: String,
pub generic_name: String,
//TODO update when willow supports images
// pub icon: Vec<u8>,
pub try_exec: String,
pub exec: String,
pub terminal: bool,
pub mime_type: String,
pub categories: Vec<String>,
pub comment: String,
}
impl ApplicationContent {
pub fn format(self, width: f32) -> Application {
let height = Application::PADDING.x + Application::PADDING.z + Application::LINE_HEIGHT;
let name = format!("{} ({})", self.name, self.generic_name);
Application {
name,
size: vec2(width, height),
}
}
}
struct Application {
name: String,
//TODO update when willow supports images
// pub icon: Vec<u8>,
size: Vec2,
}
impl Application {
pub const PADDING: Vec4 = Vec4::splat(10.0);
pub const ROUNDING: Vec4 = Vec4::splat(10.0);
pub const LINE_HEIGHT: f32 = 15.0;
}
impl ElementComponent for Application {
fn render(&mut self, hooks: &mut Hooks) -> Element {
let theme = hooks.use_theme();
let mut body = Vec::new();
let mut cursor = Self::LINE_HEIGHT + Self::PADDING.x;
body.push(Element::operation(
stroke_color(theme.surface),
Shape::RoundedRectangle {
min: vec2(0.0, 0.0),
max: self.size,
radii: Self::ROUNDING,
},
));
body.push(Element::operation(
stroke_color(theme.text),
Element::operation(
Operation::Translate {
offset: vec2(Self::PADDING.w, cursor),
},
Shape::Text {
content: self.name.to_owned(),
font: String::new(),
},
),
));
body.into()
}
}
struct ApplicationsList {
pub applications: Vec<ApplicationContent>,
pub size: Vec2,
}
impl ApplicationsList {
pub const PADDING: Vec4 = Vec4::splat(10.0);
pub const INNER_PADDING: f32 = 10.0;
}
impl ElementComponent for ApplicationsList {
fn render(&mut self, hooks: &mut Hooks) -> Element {
let theme = hooks.use_theme();
let mut elements = Vec::new();
elements.push(Element::operation(
stroke_color(theme.base),
Shape::Rectangle {
min: Vec2::ZERO,
max: self.size,
},
));
let application_width = self.size.x - Self::PADDING.y - Self::PADDING.w;
let mut cursor = Self::PADDING.x;
for application in self.applications.iter() {
let application = application.clone().format(application_width);
let cursor_delta = application.size.y + Self::INNER_PADDING;
elements.push(Element::operation(
Operation::Translate {
offset: vec2(Self::PADDING.w, cursor),
},
application,
));
cursor += cursor_delta;
}
elements.into()
}
}
pub enum AppEvent {}
struct App {}
impl willow_desktop::App for App {
type Event = AppEvent;
fn with_proxy(&self, proxy: EventLoopProxy<Self::Event>) {}
fn redraw(&mut self, size: Vec2) -> Box<dyn ElementComponent> {
let application_list = ApplicationsList {
size,
applications: vec![
ApplicationContent {
name: "zathura".to_string(),
application_type: "editor".to_string(),
generic_name: "pdf editor".to_string(),
try_exec: "mew".to_string(),
exec: "mew".to_string(),
terminal: false,
mime_type: "piss".to_string(),
categories: vec!["pdf".to_string(), "editor".to_string()],
comment: "weener".to_string(),
},
ApplicationContent {
name: "spotify".to_string(),
application_type: "music player".to_string(),
generic_name: "music player".to_string(),
try_exec: "mew".to_string(),
exec: "mew".to_string(),
terminal: false,
mime_type: "piss".to_string(),
categories: vec!["music".to_string(), "player".to_string()],
comment: "weener".to_string(),
},
],
};
Box::new(application_list)
}
fn on_event(&mut self, event: Self::Event) {}
fn on_window_event(&mut self, event: WindowEvent) {}
}
impl App {
pub fn new() -> Self {
Self {}
}
}
fn main() {
let app = App::new();
willow_desktop::run_app(app);
}