GitXplorerGitXplorer
b

vgtk

public
1054 stars
36 forks
27 issues

Commits

List of commits on branch master.
Verified
6c152c392d1b8286b86a7861ce84259598cedef7

Update README.md

bbodil committed 3 years ago
Verified
0dfc11e734a6767a00624dc0c4b2593cbc2552ab

Merge pull request #51 from nt8r/master

ppepijndevos committed 4 years ago
Unverified
44fd4a4f67b0ce839138e3d352a1d04d2183634b

Add Image::surface property

nnt8r committed 5 years ago
Verified
c6325f8bc43eafd98a32705204e15053a62eba60

Merge pull request #73 from meteficha/fix-init

ppepijndevos committed 4 years ago
Verified
93e93d23e5fa67f363abb185d61a7f65c465b015

Revert "Ignore clippy warning coming from macro."

mmeteficha committed 4 years ago
Verified
3054df9d7f7fca9ad1f602e87039281a70c104f2

Ignore clippy warning coming from macro.

mmeteficha committed 4 years ago

README

The README file for this repository.

vgtk

A declarative desktop UI framework for Rust built on GTK and Gtk-rs.

At A Glance

  • A clean, functional component model inspired by the Elm architecture, Redux and Yew.
  • A declarative DSL for composing GTK widgets inspired by React and JSX, using virtual "DOM" diffing for efficient updates.
  • Fully cross platform with a native look and feel for Linux, Windows and macOS.
  • Built on Rust's Futures using GLib's event loop, giving you async/await superpowers cleanly integrated with the GTK event model.
  • Absolutely no need for an embedded browser engine, unless you really want one.

Documentation

Show Me!

use vgtk::{ext::*, gtk, run, Component, UpdateAction, VNode};
use vgtk::lib::{gtk::*, gio::ApplicationFlags};

#[derive(Clone, Default, Debug)]
struct Model {
    counter: usize,
}

#[derive(Clone, Debug)]
enum Message {
   Inc,
   Exit,
}

impl Component for Model {
   type Message = Message;
   type Properties = ();

   fn update(&mut self, message: Message) -> UpdateAction<Self> {
       match message {
           Message::Inc => {
               self.counter += 1;
               UpdateAction::Render
           }
           Message::Exit => {
               vgtk::quit();
               UpdateAction::None
           }
       }
   }

   fn view(&self) -> VNode<Model> {
       gtk! {
           <Application::new_unwrap(None, ApplicationFlags::empty())>
               <Window border_width=20 on destroy=|_| Message::Exit>
                   <HeaderBar title="inc!" show_close_button=true />
                   <Box spacing=10 halign=Align::Center>
                       <Label label=self.counter.to_string() />
                       <Button label="inc!" image="add" always_show_image=true
                               on clicked=|_| Message::Inc />
                   </Box>
               </Window>
           </Application>
       }
   }
}

fn main() {
   std::process::exit(run::<Model>());
}

Installation

You'll need to ensure GTK is installed and usable on your system before you can use vgtk. Please consult the Gtk documentation for detailed instructions. It can be especially involved on Windows, but if you follow their instructions carefully, it does eventually work.

Getting Started

You can use cargo generate to start a vgtk project:

cargo generate --git https://github.com/bodil/cargo-template-vgtk

Alternatively, if you don't want to install cargo generate, you can clone the template repo and edit the Cargo.toml file manually to fit your project.

To run your app, enter the project folder and type cargo run, and marvel at the little window which eventually appears and what wonders you could fill it with.

Examples

See the examples folder for a collection of example applications, including a complete TodoMVC implementation. To try out the TodoMVC example, clone the vgtk repo and issue cargo run --bin todomvc from the project root directory.

Licence

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public Licence as published by the Free Software Foundation, either version 3 of the Licence, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public Licence for more details.

You should have received a copy of the GNU Lesser General Public Licence along with this program. If not, see https://www.gnu.org/licenses/.