Compare commits

...

No commits in common. "main" and "zig" have entirely different histories.
main ... zig

12 changed files with 80 additions and 3566 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
/target

3338
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +0,0 @@
[package]
name = "doggo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
iced = {version = "0.12.1"}
rfd = { version = "0.14.1", default-features = false, features = ["gtk3"] }

30
build.zig Normal file
View File

@ -0,0 +1,30 @@
const std = @import("std");
const capy = @import("capy");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "doggo",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = mode,
});
b.installArtifact(exe);
const run_cmd = try capy.install(exe, .{ .args = b.args });
const run_step = b.step("run", "Run the app");
run_step.dependOn(run_cmd);
const exe_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = mode,
});
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);
}

19
build.zig.zon Normal file
View File

@ -0,0 +1,19 @@
.{
.name = "doggo",
.version = "0.1.0",
.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
.dependencies = .{
.capy = .{
.url = "https://github.com/ffreling/capy/archive/refs/heads/zig-0.12.0.tar.gz",
.hash = "12207fd2f0d02eb929d1e8a05843de4dc3f4b362055e9e47a014fb6b806a592d9808",
},
.zigimg = .{
.url = "https://github.com/zigimg/zigimg/archive/8873f29fc449e1b63400e9f4ad86d3c76204f962.tar.gz",
.hash = "122019f6439545235af116d0d8eb81fde1ff05fdb070da57c723772c557f84c5bf39",
},
},
}

View File

@ -1,63 +1,23 @@
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1712211755,
"narHash": "sha256-KIJA4OvXFDXEeu7wstFDCxqZEfjaPQIowpzNww48TUw=",
"owner": "nix-community",
"repo": "fenix",
"rev": "39763c6e23a8423af316b85a74bad0cc5bc88d86",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1712163089,
"narHash": "sha256-Um+8kTIrC19vD4/lUCN9/cU9kcOsD1O1m+axJqQPyMM=",
"lastModified": 1714750952,
"narHash": "sha256-oOUdvPrO8CbupgDSaPou+Jv6GL+uQA2QlE33D7OLzkM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "fd281bd6b7d3e32ddfa399853946f782553163b5",
"rev": "5fd8536a9a5932d4ae8de52b7dc08d92041237fc",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"root": {
"inputs": {
"fenix": "fenix",
"nixpkgs": "nixpkgs"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1712156296,
"narHash": "sha256-St7ZQrkrr5lmQX9wC1ZJAFxL8W7alswnyZk9d1se3Us=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "8e581ac348e223488622f4d3003cb2bd412bf27e",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
}
},
"root": "root",

View File

@ -1,51 +1,19 @@
{
description = "Doggo flake";
inputs = {
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "nixpkgs/nixos-unstable";
};
outputs = { self, fenix, nixpkgs }:
outputs = { self, nixpkgs }:
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
devShell.x86_64-linux = with pkgs;
mkShell rec {
mkShell {
nativeBuildInputs = [
just
pkg-config
protobuf
(fenix.packages.x86_64-linux.fromToolchainFile {
dir = ./.;
sha256 = "sha256-7QfkHty6hSrgNM0fspycYkRcB82eEqYa4CoAJ9qA3tU= ";
})
fenix.packages.x86_64-linux.rust-analyzer
zig
zls
];
buildInputs = [
fontconfig
vulkan-headers
vulkan-loader
libGL
libxkbcommon
wayland
# rfd
gtk3
gtk4
];
env = {
# WAYLAND_DISPLAY = ""; # Window has nor decoration on Wayland
LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath buildInputs;
};
};
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt;
};
};
}

Binary file not shown.

View File

@ -1,15 +1,7 @@
alias b := build
build:
cargo build
zig build
alias r := run
run:
nixVulkanIntel cargo run
fmt:
nix fmt flake.nix
# See https://github.com/zed-industries/zed/blob/main/docs/src/developing_zed__building_zed_linux.md
alias e := edit
edit:
WALYAND_DISPLAY= nixVulkanIntel zed .
zig build run

View File

@ -1,3 +0,0 @@
[toolchain]
channel = "stable"
profile = "default"

View File

@ -1,123 +0,0 @@
use iced::{
alignment,
widget::{button, column, container, row, scrollable, text, text_input, Column},
Element, Length, Padding, Sandbox, Settings,
};
use rfd::FileDialog;
#[derive(Debug, Clone)]
enum Message {
InputValue(String),
Submitted,
DeleteItem(usize),
}
/**
* This is your model. It contains all the data needed for your application to work properly.
* The model can only be updated with the `update` function.
*/
struct GroceryList {
grocery_items: Vec<String>,
input_value: String,
}
impl Sandbox for GroceryList {
type Message = Message;
/* Initialize your app */
fn new() -> GroceryList {
Self {
grocery_items: vec!["Eggs".to_owned(), "Milk".to_owned(), "Flour".to_owned()],
input_value: String::default(),
}
}
/**
* The title of the window. It will show up on the top of your application window.
*/
fn title(&self) -> String {
String::from("Grocery List App")
}
fn update(&mut self, message: Self::Message) {
match message {
Message::InputValue(value) => self.input_value = value,
Message::Submitted => {
let input_value = self.input_value.clone();
self.input_value = String::default(); // Clear the input value
let _file = FileDialog::new()
.set_directory("/home/ffreling/Sync")
.pick_file();
let file_str = _file.and_then(|p| Some(String::from(p.to_str().unwrap())));
println!("{:?}", file_str);
match file_str {
None => (),
Some(path_str) => self.grocery_items.push(path_str),
}
// self.grocery_items.push(input_value);
}
Message::DeleteItem(item) => {
let _files = FileDialog::new()
.set_directory("/home/ffreling/Sync")
.pick_file();
self.grocery_items.remove(item);
}
}
}
fn view(&self) -> Element<Self::Message> {
container(
column!(
items_list_view(&self.grocery_items),
row!(
text_input("Input grocery item", &self.input_value)
.on_input(|value| Message::InputValue(value))
.on_submit(Message::Submitted),
button("Submit").on_press(Message::Submitted)
)
.spacing(30)
.padding(Padding::from(30))
)
.align_items(iced::Alignment::Center),
)
.height(Length::Fill)
.width(Length::Fill)
.align_x(alignment::Horizontal::Center)
.align_y(alignment::Vertical::Center)
.into()
}
fn theme(&self) -> iced::Theme {
iced::Theme::Dark
}
}
fn items_list_view(items: &Vec<String>) -> Element<'static, Message> {
let mut column = Column::new()
.spacing(20)
.align_items(iced::Alignment::Center)
.width(Length::Fill);
for (index, value) in items.into_iter().enumerate() {
column = column.push(grocery_item(index, value));
}
scrollable(container(column))
.height(250.0)
.width(300)
.into()
}
fn grocery_item(index: usize, value: &str) -> Element<'static, Message> {
row!(
text(value),
button("Delete").on_press(Message::DeleteItem(index))
)
.align_items(iced::Alignment::Center)
.spacing(30)
.into()
}
pub fn main() -> iced::Result {
GroceryList::run(Settings::default())
}

20
src/main.zig Normal file
View File

@ -0,0 +1,20 @@
const std = @import("std");
const capy = @import("capy");
// This is required for your app to build to WebAssembly and other particular architectures
pub usingnamespace capy.cross_platform;
pub fn main() !void {
try capy.backend.init();
var window = try capy.Window.init();
try window.set(
capy.label(.{ .text = "Hello, World", .alignment = .Center }),
);
window.setTitle("Hello");
window.setPreferredSize(250, 100);
window.show();
capy.runEventLoop();
}