templates: Add gui template

This commit is contained in:
traxys 2023-11-09 23:37:32 +01:00
parent ac956d4627
commit 960efd4cf6
6 changed files with 90 additions and 0 deletions

View file

@ -134,6 +134,10 @@
path = ./templates/webserver;
description = "A template for a web server (using templates for the frontend)";
};
gui = {
path = ./templates/gui;
description = "A template for rust GUI applications";
};
};
packages.x86_64-linux = pkgList "x86_64-linux" nixpkgs.legacyPackages.x86_64-linux.callPackage;
packages.aarch64-linux = pkgList "aarch64-linux" nixpkgs.legacyPackages.aarch64-linux.callPackage;

1
templates/gui/.envrc Normal file
View file

@ -0,0 +1 @@
use flake

3
templates/gui/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/target
/.direnv

8
templates/gui/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "todo_change_name"
version = "0.1.0"
authors = ["traxys <quentin@familleboyer.net>"]
edition = "2021"
[dependencies]
iced = "0.10.0"

43
templates/gui/flake.nix Normal file
View file

@ -0,0 +1,43 @@
{
description = "A basic flake with a shell";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.naersk.url = "github:nix-community/naersk";
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
outputs = {
self,
nixpkgs,
flake-utils,
naersk,
rust-overlay,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [(import rust-overlay)];
};
rust = pkgs.rust-bin.stable.latest.default;
naersk' = pkgs.callPackage naersk {
cargo = rust;
rustc = rust;
};
libPath = with pkgs; lib.makeLibraryPath [libxkbcommon wayland];
in {
devShell = pkgs.mkShell {
nativeBuildInputs = [rust];
RUST_PATH = "${rust}";
RUST_DOC_PATH = "${rust}/share/doc/rust/html/std/index.html";
LD_LIBRARY_PATH = libPath;
};
defaultPackage = naersk'.buildPackage {
src = ./.;
nativeBuildInputs = [pkgs.makeWrapper];
postInstall = ''
wrapProgram "$out/bin/todo_change_name" --prefix LD_LIBRARY_PATH : "${libPath}"
'';
};
});
}

31
templates/gui/src/main.rs Normal file
View file

@ -0,0 +1,31 @@
use iced::{widget::column, Sandbox, Settings};
#[derive(Clone, Copy, Debug)]
enum Message {}
struct App {}
impl Sandbox for App {
type Message = Message;
fn new() -> Self {
Self {}
}
fn title(&self) -> String {
"TODO change name".into()
}
fn update(&mut self, message: Self::Message) {
match message {}
}
fn view(&self) -> iced::Element<'_, Self::Message> {
column![].into()
}
}
fn main() -> iced::Result {
App::run(Settings::default())
}