init: simple ui
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
4276
Cargo.lock
generated
Normal file
4276
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "zilch"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
eframe = "0.33.2"
|
||||
egui = "0.33.2"
|
||||
egui_extras = "0.33.2"
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Himadri Bhattacharjee
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
25
flake.lock
generated
Normal file
25
flake.lock
generated
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1765457389,
|
||||
"narHash": "sha256-ddhDtNYvleZeYF7g7TRFSmuQuZh7HCgqstg5YBGwo5s=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "f997fa0f94fb1ce55bccb97f60d41412ae8fde4c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
32
flake.nix
Normal file
32
flake.nix
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
description = "flake for github:lavafroth/shush";
|
||||
|
||||
outputs =
|
||||
{
|
||||
nixpkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
forAllSystems =
|
||||
f:
|
||||
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: f nixpkgs.legacyPackages.${system});
|
||||
in
|
||||
{
|
||||
|
||||
devShells = forAllSystems (pkgs: {
|
||||
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
stdenv.cc.cc.lib
|
||||
];
|
||||
LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [
|
||||
wayland-protocols
|
||||
wayland
|
||||
libxkbcommon
|
||||
libGL
|
||||
];
|
||||
};
|
||||
|
||||
});
|
||||
};
|
||||
}
|
||||
103
src/main.rs
Normal file
103
src/main.rs
Normal file
@@ -0,0 +1,103 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
|
||||
|
||||
use eframe::egui;
|
||||
use egui::{Button, Layout, Sense, TextEdit};
|
||||
|
||||
fn main() -> eframe::Result {
|
||||
// env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(
|
||||
"My egui App",
|
||||
options,
|
||||
Box::new(|_| Ok(Box::<MyApp>::default())),
|
||||
)
|
||||
}
|
||||
|
||||
struct MyApp {
|
||||
name: String,
|
||||
entries: Vec<Entry>,
|
||||
}
|
||||
|
||||
struct Entry {
|
||||
id: String,
|
||||
expanded: bool,
|
||||
selected: bool,
|
||||
}
|
||||
|
||||
impl Default for MyApp {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: "someapp".to_owned(),
|
||||
|
||||
entries: vec![
|
||||
Entry {
|
||||
id: "ping.pong.bell".to_string(),
|
||||
expanded: false,
|
||||
selected: false,
|
||||
},
|
||||
Entry {
|
||||
id: "ding.dong.bell".to_string(),
|
||||
expanded: false,
|
||||
selected: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ctx.set_pixels_per_point(1.5);
|
||||
// self.ctrl = ui.input(|i| i.modifiers.ctrl);
|
||||
|
||||
ui.take_available_width();
|
||||
ui.horizontal(|ui| {
|
||||
ui.take_available_width();
|
||||
let search_label = ui.label("Search: ");
|
||||
ui.add_sized(
|
||||
[ui.available_width(), 20.0],
|
||||
TextEdit::singleline(&mut self.name),
|
||||
)
|
||||
.labelled_by(search_label.id);
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
||||
for entry in self.entries.iter_mut() {
|
||||
render_entry(ui, entry);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn render_entry(ui: &mut egui::Ui, entry: &mut Entry) {
|
||||
let id = ui.make_persistent_id(&format!("{}_state", entry.id));
|
||||
let mut state =
|
||||
egui::collapsing_header::CollapsingState::load_with_default_open(ui.ctx(), id, false);
|
||||
|
||||
if entry.expanded {
|
||||
state.toggle(ui);
|
||||
entry.expanded = false;
|
||||
}
|
||||
state
|
||||
.show_header(ui, |ui| {
|
||||
ui.with_layout(Layout::top_down_justified(egui::Align::LEFT), |ui| {
|
||||
let response = ui.selectable_label(entry.selected, &entry.id);
|
||||
let id = ui.make_persistent_id(&format!("{}_interact", entry.id));
|
||||
if ui
|
||||
.interact(response.rect, id, Sense::click())
|
||||
.double_clicked()
|
||||
{
|
||||
entry.expanded = true;
|
||||
} else if ui.interact(response.rect, id, Sense::click()).clicked() {
|
||||
entry.selected ^= true;
|
||||
}
|
||||
});
|
||||
})
|
||||
.body(|ui| ui.label("ping pong"));
|
||||
}
|
||||
Reference in New Issue
Block a user