Compare commits

...

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

21 changed files with 268 additions and 3575 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
/target
libraylib.a

6
.gitmodules vendored Normal file
View File

@ -0,0 +1,6 @@
[submodule "3rdparty/raylib"]
path = 3rdparty/raylib
url = https://github.com/raysan5/raylib
[submodule "3rdparty/raygui"]
path = 3rdparty/raygui
url = https://github.com/raysan5/raygui.git

1
3rdparty/raygui vendored Submodule

@ -0,0 +1 @@
Subproject commit 865bb293764073c01e74314ef647464f1f10fd96

1
3rdparty/raylib vendored Submodule

@ -0,0 +1 @@
Subproject commit ca12ef48e9e9f4eae03b1ca43ec3eb0a78d63dd3

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"] }

49
build.zig Normal file
View File

@ -0,0 +1,49 @@
const std = @import("std");
const raylib = @import("./3rdparty/raylib/src/build.zig");
pub fn build(b: *std.build.Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("doggo", "src/main.zig");
exe.setTarget(target);
const ray = raylib.addRaylib(b, exe.target);
exe.linkLibrary(ray);
exe.addIncludeDir("3rdparty/raylib/src");
exe.addIncludeDir("3rdparty/raygui/src");
exe.addIncludeDir("3rdparty/raygui/examples");
const raylib_flags = &[_][]const u8{
"-std=gnu99",
"-DPLATFORM_DESKTOP",
"-DGL_SILENCE_DEPRECATION=199309L",
"-fno-sanitize=undefined",
};
exe.addCSourceFile("src/raylib.c", raylib_flags);
exe.setBuildMode(mode);
exe.install();
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const exe_tests = b.addTest("src/main.zig");
exe_tests.setTarget(target);
exe_tests.setBuildMode(mode);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);
}

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": 1651369430,
"narHash": "sha256-d86uUm0s11exU9zLo2K1AwtJQJDKubFpoF0Iw767uT4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "fd281bd6b7d3e32ddfa399853946f782553163b5",
"rev": "b283b64580d1872333a99af2b4cef91bb84580cf",
"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,41 @@
{
description = "Doggo flake";
inputs = {
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
outputs = { self, nixpkgs }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
# godot-alpha = (with pkgs; stdenv.mkDerivation {
# pname = "godot-alpha";
# version = "4.0.0-a8";
# src = fetchzip {
# url = "https://downloads.tuxfamily.org/godotengine/4.0/alpha8/Godot_v4.0-alpha8_linux.64.zip";
# hash = "sha512-qkUpt1reFgVDt5u9zLHYLoJAzC0D/YdtNpQhWLarpTW0e+Vzlqy7kna2plIeddybNsn+tS+QqTmYJExA7aT3zw==";
# };
# installPhase = ''
# mkdir -p $out/bin
# mv Godot_v4.0-alpha8_linux.64 $out/bin/godot-v4-alpha
# '';
# });
in {
devShell.x86_64-linux = with pkgs;
mkShell {
buildInputs = [
just
# zig
# godot
# godot-alpha
#
# xorg.libX11
# xorg.libXcursor
# xorg.libXi
# xorg.libXext
# xorg.libXrandr
# xorg.libXinerama
# libGL
# libGLU
];
};
nixpkgs.url = "nixpkgs/nixos-unstable";
};
outputs = { self, fenix, nixpkgs }:
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
devShell.x86_64-linux = with pkgs;
mkShell rec {
nativeBuildInputs = [
just
pkg-config
protobuf
(fenix.packages.x86_64-linux.fromToolchainFile {
dir = ./.;
sha256 = "sha256-7QfkHty6hSrgNM0fspycYkRcB82eEqYa4CoAJ9qA3tU= ";
})
fenix.packages.x86_64-linux.rust-analyzer
];
buildInputs = [
fontconfig
vulkan-headers
vulkan-loader
libGL
libxkbcommon
wayland
# rfd
gtk3
];
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.

26
godot-impl/Main.gd Normal file
View File

@ -0,0 +1,26 @@
extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
$HTTPRequest.connect("request_completed", self._on_request_completed)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var bodySize = $HTTPRequest.get_body_size()
var downloadedBytes = $HTTPRequest.get_downloaded_bytes()
var percent = downloadedBytes * 100 / bodySize
$Label.text = "Progress: %d %%" % percent
pass
func download_cpp_dap():
var url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz"
$HTTPRequest.download_file = "user://lldb.tar.xz"
$HTTPRequest.request(url)
func _on_request_completed(result, response_code, headers, body):
# TODO: decompress archive
# OS.execute("")
pass

27
godot-impl/Main.tscn Normal file
View File

@ -0,0 +1,27 @@
[gd_scene load_steps=2 format=3 uid="uid://cirquj62osi4v"]
[ext_resource type="Script" path="res://Main.gd" id="1_6lnje"]
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( "1_6lnje" )
[node name="Button" type="Button" parent="."]
offset_left = 148.0
offset_top = 70.0
offset_right = 296.0
offset_bottom = 162.0
text = "Download C++ DAP (lldb)"
[node name="HTTPRequest" type="HTTPRequest" parent="."]
use_threads = true
[node name="Label" type="Label" parent="."]
offset_left = 359.0
offset_top = 90.0
offset_right = 598.0
offset_bottom = 136.0
text = "Progress: 0%"
[connection signal="pressed" from="Button" to="." method="download_cpp_dap"]

BIN
godot-impl/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dda5wstjh822x"
path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

16
godot-impl/project.godot Normal file
View File

@ -0,0 +1,16 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="Doggo"
run/main_scene="res://Main.tscn"
config/icon="res://icon.png"
config/features=PackedStringArray("4.0", "Vulkan Clustered")

View File

@ -1,15 +1,21 @@
alias b := build
build:
cargo build
godot_project := "./godot-impl/project.godot"
godot_url := "https://downloads.tuxfamily.org/godotengine/4.0/alpha8/Godot_v4.0-alpha8_linux.64.zip"
godot_exe := "Godot_v4.0-alpha8_linux.64"
godot_exe_dir := "~/bin"
godot_path := godot_exe_dir + "/" + godot_exe
alias r := run
run:
nixVulkanIntel cargo run
setup:
#!/usr/bin/env bash
set -euo pipefail
if [ ! -e {{godot_path}} ]; then
curl {{godot_url}} -O
unzip Godot*.zip
mv {{godot_exe}} {{godot_exe_dir}}
rm Godot*.zip
fi
fmt:
nix fmt flake.nix
#run:
# nixGL zig build run
# 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 .
edit: setup
{{godot_exe}} {{godot_project}}

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())
}

40
src/main.zig Normal file
View File

@ -0,0 +1,40 @@
const std = @import("std");
const r = @import("raylib.zig");
pub fn main() anyerror!void {
r.InitWindow(800, 450, "doggo");
defer r.CloseWindow();
// var selected_filename: [512]u8 = undefined;
var file_dialog_state = r.InitGuiFileDialog(420, 310, r.GetWorkingDirectory(), false);
while (!r.WindowShouldClose()) {
// Update
if (file_dialog_state.SelectFilePressed) {
std.log.info("{s} / {s}", .{ file_dialog_state.dirPathText, file_dialog_state.fileNameText });
}
// Draw
r.BeginDrawing();
defer r.EndDrawing();
r.ClearBackground(r.RAYWHITE);
r.DrawText("Congrats! You created your first window!", 190, 200, 20, r.LIGHTGRAY);
if (file_dialog_state.fileDialogActive) {
r.GuiLock();
}
if (r.GuiButton(r.Rectangle{ .x = 190, .y = 250, .width = 150, .height = 30 }, "Button")) {
std.log.info("Button pressed", .{});
file_dialog_state.fileDialogActive = true;
}
r.GuiUnlock();
r.GuiFileDialog(&file_dialog_state);
}
}
test "basic test" {
try std.testing.expectEqual(10, 3 + 7);
}

6
src/raylib.c Normal file
View File

@ -0,0 +1,6 @@
#define RAYGUI_IMPLEMENTATION
#include <raygui.h>
#undef RAYGUI_IMPLEMENTATION // Avoid including raygui implementation again
#define GUI_FILE_DIALOG_IMPLEMENTATION
#include <custom_file_dialog/gui_file_dialog.h>

5
src/raylib.zig Normal file
View File

@ -0,0 +1,5 @@
pub usingnamespace @cImport({
@cInclude("raylib.h");
@cInclude("raygui.h");
@cInclude("custom_file_dialog/gui_file_dialog.h");
});