First commit
This commit is contained in:
commit
1544d831a2
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
1340
Cargo.lock
generated
Normal file
1340
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "sheet-organizer"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
# Core library
|
||||
relm4 = "0.6.2"
|
||||
# Optional: reusable components
|
||||
relm4-components = "0.6.2"
|
||||
# Optional: icons
|
||||
relm4-icons = { version = "0.6.0", features = ["plus"] }
|
27
flake.nix
Normal file
27
flake.nix
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
inputs = {
|
||||
naersk.url = "github:nix-community/naersk/master";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, utils, naersk }:
|
||||
utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
naersk-lib = pkgs.callPackage naersk { };
|
||||
in {
|
||||
defaultPackage = naersk-lib.buildPackage {
|
||||
src = ./.;
|
||||
nativeBuildInputs = with pkgs; [
|
||||
gtk4
|
||||
cairo
|
||||
glib
|
||||
pkg-config
|
||||
poppler
|
||||
wrapGAppsHook
|
||||
];
|
||||
};
|
||||
|
||||
});
|
||||
}
|
99
src/main.rs
Normal file
99
src/main.rs
Normal file
@ -0,0 +1,99 @@
|
||||
use gtk::glib::clone;
|
||||
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt};
|
||||
use relm4::{gtk, ComponentParts, ComponentSender, RelmApp, RelmWidgetExt, SimpleComponent};
|
||||
|
||||
struct AppModel {
|
||||
counter: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum AppInput {
|
||||
Increment,
|
||||
Decrement,
|
||||
}
|
||||
|
||||
struct AppWidgets {
|
||||
label: gtk::Label,
|
||||
}
|
||||
|
||||
impl SimpleComponent for AppModel {
|
||||
/// The type of the messages that this component can receive.
|
||||
type Input = AppInput;
|
||||
/// The type of the messages that this component can send.
|
||||
type Output = ();
|
||||
/// The type of data with which this component will be initialized.
|
||||
type Init = u8;
|
||||
/// The root GTK widget that this component will create.
|
||||
type Root = gtk::Window;
|
||||
/// A data structure that contains the widgets that you will need to update.
|
||||
type Widgets = AppWidgets;
|
||||
|
||||
fn init_root() -> Self::Root {
|
||||
gtk::Window::builder()
|
||||
.title("Simple app")
|
||||
.default_width(300)
|
||||
.default_height(100)
|
||||
.build()
|
||||
}
|
||||
|
||||
/// Initialize the UI and model.
|
||||
fn init(
|
||||
counter: Self::Init,
|
||||
window: &Self::Root,
|
||||
sender: ComponentSender<Self>,
|
||||
) -> relm4::ComponentParts<Self> {
|
||||
let model = AppModel { counter };
|
||||
|
||||
let vbox = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.spacing(5)
|
||||
.build();
|
||||
|
||||
let inc_button = gtk::Button::with_label("Increment");
|
||||
let dec_button = gtk::Button::with_label("Decrement");
|
||||
|
||||
let label = gtk::Label::new(Some(&format!("Counter: {}", model.counter)));
|
||||
label.set_margin_all(5);
|
||||
|
||||
window.set_child(Some(&vbox));
|
||||
vbox.set_margin_all(5);
|
||||
vbox.append(&inc_button);
|
||||
vbox.append(&dec_button);
|
||||
vbox.append(&label);
|
||||
|
||||
inc_button.connect_clicked(clone!(@strong sender => move |_| {
|
||||
sender.input(AppInput::Increment);
|
||||
}));
|
||||
|
||||
dec_button.connect_clicked(clone!(@strong sender => move |_| {
|
||||
sender.input(AppInput::Decrement);
|
||||
}));
|
||||
|
||||
let widgets = AppWidgets { label };
|
||||
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
|
||||
match message {
|
||||
AppInput::Increment => {
|
||||
self.counter = self.counter.wrapping_add(1);
|
||||
}
|
||||
AppInput::Decrement => {
|
||||
self.counter = self.counter.wrapping_sub(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the view to represent the updated model.
|
||||
fn update_view(&self, widgets: &mut Self::Widgets, _sender: ComponentSender<Self>) {
|
||||
widgets
|
||||
.label
|
||||
.set_label(&format!("Counter: {}", self.counter));
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let app = RelmApp::new("relm4.test.simple_manual");
|
||||
app.run::<AppModel>(0);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user