first commit
This commit is contained in:
commit
f52e004df2
6 changed files with 1176 additions and 0 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
@ -0,0 +1 @@
|
|||
use nix
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
.direnv/
|
1064
Cargo.lock
generated
Normal file
1064
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 = "dorocus"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
relm4 = "0.9.1"
|
||||
relm4-components = "0.9.1"
|
||||
relm4-macros = "0.9.1"
|
15
shell.nix
Normal file
15
shell.nix
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
}:
|
||||
|
||||
pkgs.mkShell rec {
|
||||
buildInputs = with pkgs; [
|
||||
pkg-config
|
||||
atk
|
||||
glib
|
||||
graphene
|
||||
gtk4
|
||||
];
|
||||
|
||||
LD_LIBRARY_PATH = builtins.foldl' (a: b: "${a}:${b}/lib") "${pkgs.vulkan-loader}/lib" buildInputs;
|
||||
}
|
85
src/main.rs
Normal file
85
src/main.rs
Normal file
|
@ -0,0 +1,85 @@
|
|||
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt};
|
||||
use relm4::gtk::prelude::OrientableExt;
|
||||
use relm4::{gtk, ComponentParts, ComponentSender, RelmApp, RelmWidgetExt, SimpleComponent};
|
||||
|
||||
struct AppModel {
|
||||
counter: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum AppMsg {
|
||||
Increment,
|
||||
Decrement,
|
||||
}
|
||||
|
||||
struct AppWidgets {
|
||||
label: gtk::Label,
|
||||
}
|
||||
|
||||
#[relm4::component]
|
||||
impl SimpleComponent for AppModel {
|
||||
type Init = u64;
|
||||
|
||||
type Input = AppMsg;
|
||||
type Output = ();
|
||||
|
||||
view! {
|
||||
gtk::Window {
|
||||
set_title: Some("Simple app"),
|
||||
set_default_width: 300,
|
||||
set_default_height: 100,
|
||||
|
||||
gtk::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
set_spacing: 5,
|
||||
set_margin_all: 5,
|
||||
|
||||
gtk::Button {
|
||||
set_label: "Increment",
|
||||
connect_clicked => AppMsg::Increment
|
||||
},
|
||||
|
||||
gtk::Button::with_label("Decrement") {
|
||||
connect_clicked => AppMsg::Decrement
|
||||
},
|
||||
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
set_label: &format!("Counter: {}", model.counter),
|
||||
set_margin_all: 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the UI.
|
||||
fn init(
|
||||
counter: Self::Init,
|
||||
root: Self::Root,
|
||||
sender: ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
let model = AppModel { counter };
|
||||
|
||||
// Insert the macro code generation here
|
||||
let widgets = view_output!();
|
||||
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
|
||||
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
|
||||
match msg {
|
||||
AppMsg::Increment => {
|
||||
self.counter = self.counter.wrapping_add(1);
|
||||
}
|
||||
AppMsg::Decrement => {
|
||||
self.counter = self.counter.wrapping_sub(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let app = RelmApp::new("relm4.test.simple_manual");
|
||||
app.run::<AppModel>(0);
|
||||
}
|
||||
|
Loading…
Reference in a new issue