This commit is contained in:
2025-10-23 10:00:11 +00:00
parent 12e270c0cf
commit 36eba59887
7 changed files with 5059 additions and 0 deletions

1
.envrc Normal file
View File

@@ -0,0 +1 @@
use flake

2
.gitignore vendored Normal file
View File

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

4798
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

9
Cargo.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "imgui-testing"
version = "0.1.0"
edition = "2024"
[dependencies]
floem = { git = "https://github.com/lapce/floem", features = ["crossbeam", "vello"], version = "0.2.0" }
tracing = "0.1.41"
tracing-subscriber = "0.3.20"

63
flake.lock generated Normal file
View File

@@ -0,0 +1,63 @@
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1759301100,
"narHash": "sha256-hmiTEoVAqLnn80UkreCNunnRKPucKvcg5T4/CELEtbw=",
"rev": "0956bc5d1df2ea800010172c6bc4470d9a22cb81",
"revCount": 2408,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/nix-community/fenix/0.1.2408%2Brev-0956bc5d1df2ea800010172c6bc4470d9a22cb81/01999edc-854f-7714-9439-7c9ee1181398/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/nix-community/fenix/0.1"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1760878510,
"narHash": "sha256-K5Osef2qexezUfs0alLvZ7nQFTGS9DL2oTVsIXsqLgs=",
"rev": "5e2a59a5b1a82f89f2c7e598302a9cacebb72a67",
"revCount": 880095,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.880095%2Brev-5e2a59a5b1a82f89f2c7e598302a9cacebb72a67/0199ff22-59dd-7eb0-a8c6-783df1d83a4f/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.1"
}
},
"root": {
"inputs": {
"fenix": "fenix",
"nixpkgs": "nixpkgs"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1759245522,
"narHash": "sha256-H4Hx/EuMJ9qi1WzPV4UG2bbZiDCdREtrtDvYcHr0kmk=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "a6bc4a4bbe6a65b71cbf76a0cf528c47a8d9f97f",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

91
flake.nix Normal file
View File

@@ -0,0 +1,91 @@
{
description = "A Nix-flake-based Rust development environment";
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1"; # unstable Nixpkgs
fenix = {
url = "https://flakehub.com/f/nix-community/fenix/0.1";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self, ... }@inputs:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forEachSupportedSystem =
f:
inputs.nixpkgs.lib.genAttrs supportedSystems (
system:
f {
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.self.overlays.default
];
};
}
);
in
{
overlays.default = final: prev: {
rustToolchain =
with inputs.fenix.packages.${prev.stdenv.hostPlatform.system};
combine (
with stable;
[
clippy
rustc
cargo
rustfmt
rust-src
]
);
};
devShells = forEachSupportedSystem (
{ pkgs }:
{
default = pkgs.mkShellNoCC {
packages = with pkgs; [
rustToolchain
openssl
pkg-config
cargo-deny
cargo-edit
cargo-watch
rust-analyzer
gcc
gtk3-x11
atk
mesa # libGL + llvmpipe + lavapipe ICD (user-space GL & Vulkan soft drivers)
vulkan-loader # Vulkan loader
vulkan-tools # vulkaninfo, etc.
xorg.libX11
libxcb
xorg.libXrandr
xorg.libXinerama
xorg.libXcursor
xorg.libXfixes
xorg.libXcomposite
xorg.libXdamage
# xorg.libxkbcommon
# xorg.libdrm
llvm # JIT for llvmpipe (pulled in by mesa often, but safe to include)
];
env = {
# Required by rust-analyzer
RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library";
};
};
}
);
};
}

95
src/main.rs Normal file
View File

@@ -0,0 +1,95 @@
use floem::{
IntoView, View,
keyboard::{Key, NamedKey},
peniko::Color,
peniko::color::palette,
reactive::{SignalGet, SignalUpdate, create_signal},
unit::UnitExt,
views::{Decorators, LabelCustomStyle, dyn_view},
};
fn app_view() -> impl IntoView {
let (counter, set_counter) = create_signal(0);
let view = (
dyn_view(move || format!("Value: {}", counter.get())),
counter.style(|s| s.padding(10.0)),
(
"Increment"
.style(|s| {
s.border_radius(10.0)
.padding(10.0)
.background(palette::css::WHITE)
.box_shadow_blur(5.0)
.focus_visible(|s| s.outline(2.).outline_color(palette::css::BLUE))
.hover(|s| s.background(palette::css::LIGHT_GREEN))
.active(|s| {
s.color(palette::css::WHITE)
.background(palette::css::DARK_GREEN)
})
})
.on_click_stop({
move |_| {
set_counter.update(|value| *value += 1);
}
})
.keyboard_navigable(),
"Decrement"
.on_click_stop({
move |_| {
set_counter.update(|value| *value -= 1);
}
})
.style(|s| {
s.box_shadow_blur(5.0)
.background(palette::css::WHITE)
.border_radius(10.0)
.padding(10.0)
.margin_left(10.0)
.focus_visible(|s| s.outline(2.).outline_color(palette::css::BLUE))
.hover(|s| s.background(Color::from_rgb8(244, 67, 54)))
.active(|s| s.color(palette::css::WHITE).background(palette::css::RED))
})
.keyboard_navigable(),
"Reset to 0"
.on_click_stop(move |_| {
println!("Reset counter pressed"); // will not fire if button is disabled
set_counter.update(|value| *value = 0);
})
.disabled(move || counter.get() == 0)
.style(|s| {
s.box_shadow_blur(5.0)
.border_radius(10.0)
.padding(10.0)
.margin_left(10.0)
.background(palette::css::LIGHT_BLUE)
.focus_visible(|s| s.outline(2.).outline_color(palette::css::BLUE))
.disabled(|s| s.background(palette::css::LIGHT_GRAY))
.hover(|s| s.background(palette::css::LIGHT_YELLOW))
.active(|s| {
s.color(palette::css::WHITE)
.background(palette::css::YELLOW_GREEN)
})
})
.keyboard_navigable(),
)
.style(|s| s.custom_style_class(|s: LabelCustomStyle| s.selectable(false))),
)
.style(|s| {
s.size(100.pct(), 100.pct())
.flex_col()
.items_center()
.justify_center()
});
let id = view.id();
view.on_key_up(
Key::Named(NamedKey::F11),
|m| m.is_empty(),
move |_| id.inspect(),
)
}
fn main() {
tracing_subscriber::fmt::init();
floem::launch(app_view);
}