Convert Figma logo to code with AI

gtk-rs logogtk

DEPRECATED, use https://github.com/gtk-rs/gtk3-rs repository instead!

1,246
82
1,246
3

Top Related Projects

1,415

Read-only mirror of https://gitlab.gnome.org/GNOME/gtk

81,614

Build smaller, faster, and more secure desktop applications with a web frontend.

17,492

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS

24,481

Cross platform GUI toolkit in Go inspired by Material Design

24,082

A cross-platform GUI library for Rust, inspired by Elm

30,490

Rust / Wasm framework for creating reliable and efficient web applications

Quick Overview

The gtk-rs/gtk repository is a Rust binding for the GTK+ toolkit, a popular cross-platform GUI toolkit. It provides a safe and idiomatic Rust interface to the GTK+ library, allowing developers to create modern and responsive graphical user interfaces for their Rust applications.

Pros

  • Cross-platform: The GTK+ toolkit is available on multiple platforms, including Linux, Windows, and macOS, allowing developers to create applications that can run on a variety of systems.
  • Robust and Mature: GTK+ has been under active development for over 20 years, making it a mature and reliable toolkit with a large ecosystem of libraries and tools.
  • Extensive Documentation: The gtk-rs project has extensive documentation, including tutorials, examples, and API references, making it easier for developers to get started and learn the library.
  • Active Community: The gtk-rs project has an active community of contributors and users, providing support, bug fixes, and new features.

Cons

  • Learning Curve: The GTK+ toolkit and the gtk-rs bindings have a steeper learning curve compared to some other GUI frameworks, especially for developers new to Rust or GUI programming.
  • Dependency Management: The gtk-rs project has a large number of dependencies, which can make it more challenging to manage and update the project's dependencies.
  • Performance Overhead: The use of a binding layer between Rust and the underlying C-based GTK+ library can introduce some performance overhead, which may be a concern for certain types of applications.
  • Limited Platform Support: While GTK+ is available on multiple platforms, the gtk-rs project may not have the same level of support or feature parity across all platforms.

Code Examples

Here are a few code examples demonstrating the usage of the gtk-rs/gtk library:

  1. Creating a Window:
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow};

fn main() {
    let app = Application::new(Some("com.example.app"), Default::default())
        .expect("Application creation failed");

    app.connect_activate(|app| {
        let window = ApplicationWindow::new(app);
        window.set_title("My GTK App");
        window.set_default_size(400, 300);
        window.show_all();
    });

    app.run(&[]);
}
  1. Adding a Button:
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, Button};

fn main() {
    let app = Application::new(Some("com.example.app"), Default::default())
        .expect("Application creation failed");

    app.connect_activate(|app| {
        let window = ApplicationWindow::new(app);
        window.set_title("My GTK App");
        window.set_default_size(400, 300);

        let button = Button::with_label("Click me!");
        button.connect_clicked(|_| {
            println!("Button clicked!");
        });

        window.add(&button);
        window.show_all();
    });

    app.run(&[]);
}
  1. Using a ListBox:
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, ListBox, ListBoxRow, Label};

fn main() {
    let app = Application::new(Some("com.example.app"), Default::default())
        .expect("Application creation failed");

    app.connect_activate(|app| {
        let window = ApplicationWindow::new(app);
        window.set_title("My GTK App");
        window.set_default_size(400, 300);

        let listbox = ListBox::new();
        for item in &["Item 1", "Item 2", "Item 3"] {
            let row = ListBoxRow::new();
            let label = Label::new(Some(item));
            row.add(&label);
            listbox.add(&row);
        }

        window.add(&listbox);
        window.show_all();
    });

    app.run(&[]);
}

Getting Started

To get started with the `gtk-rs/

Competitor Comparisons

1,415

Read-only mirror of https://gitlab.gnome.org/GNOME/gtk

Pros of GTK

  • Native C implementation, offering direct access to the GTK toolkit
  • Extensive documentation and long-standing community support
  • Wider range of features and more granular control over UI elements

Cons of GTK

  • Steeper learning curve, especially for developers not familiar with C
  • More verbose code, requiring more lines to achieve the same functionality
  • Potential for memory management issues if not handled carefully

Code Comparison

GTK (C):

#include <gtk/gtk.h>

static void activate(GtkApplication* app, gpointer user_data) {
  GtkWidget *window = gtk_application_window_new(app);
  gtk_window_set_title(GTK_WINDOW(window), "Hello, World!");
  gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
  gtk_widget_show_all(window);
}

gtk-rs (Rust):

use gtk::prelude::*;
use gtk::{Application, ApplicationWindow};

fn main() {
    let app = Application::new(Some("com.example.app"), Default::default());
    app.connect_activate(|app| {
        let window = ApplicationWindow::new(app);
        window.set_title("Hello, World!");
        window.set_default_size(200, 200);
        window.show_all();
    });
    app.run(&[]);
}

The gtk-rs bindings provide a more idiomatic Rust experience, with safer memory management and a more concise syntax. However, GTK offers more direct control and a broader feature set, albeit with a steeper learning curve and more verbose code.

81,614

Build smaller, faster, and more secure desktop applications with a web frontend.

Pros of Tauri

  • Smaller application size due to leveraging native OS components
  • Cross-platform development with web technologies (HTML, CSS, JavaScript)
  • Better security through Rust-based backend and limited system access

Cons of Tauri

  • Less mature ecosystem compared to GTK
  • Potentially slower performance for complex UI interactions
  • Limited native UI components, relying more on web-based rendering

Code Comparison

Tauri (JavaScript):

import { invoke } from '@tauri-apps/api/tauri'

async function greet() {
  const response = await invoke('greet', { name: 'World' })
  console.log(response)
}

GTK (Rust):

use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, Button};

fn main() {
    let app = Application::builder().build();
    app.connect_activate(build_ui);
    app.run(&[]);
}

Summary

Tauri offers a modern approach to desktop app development using web technologies, resulting in smaller app sizes and cross-platform compatibility. However, GTK provides a more mature ecosystem with native UI components and potentially better performance for complex applications. The choice between the two depends on the specific requirements of the project and the developer's familiarity with the respective technologies.

17,492

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS

Pros of Kivy

  • Cross-platform support for desktop and mobile (iOS, Android)
  • Python-based, making it easier for Python developers to create GUIs
  • Flexible and customizable UI with its own graphics engine

Cons of Kivy

  • Steeper learning curve due to its unique approach to UI design
  • Less native look and feel compared to GTK-based applications
  • Larger application size due to bundled dependencies

Code Comparison

Kivy:

from kivy.app import App
from kivy.uix.button import Button

class MyApp(App):
    def build(self):
        return Button(text='Hello World')

MyApp().run()

GTK-rs:

use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, Button};

fn main() {
    let app = Application::builder().build();
    app.connect_activate(|app| {
        let window = ApplicationWindow::builder()
            .application(app)
            .title("Hello World")
            .build();
        let button = Button::with_label("Click me!");
        window.set_child(Some(&button));
        window.present();
    });
    app.run(&[]);
}

The code examples demonstrate the simplicity of creating a basic GUI application in both frameworks. Kivy's Python-based approach is more concise, while GTK-rs offers a more structured, Rust-based implementation.

24,481

Cross platform GUI toolkit in Go inspired by Material Design

Pros of Fyne

  • Cross-platform support with native look and feel
  • Simpler API and easier learning curve for beginners
  • Built-in material design components

Cons of Fyne

  • Less mature ecosystem compared to GTK
  • Fewer third-party widgets and extensions available
  • Limited support for complex, custom UI layouts

Code Comparison

Fyne example:

package main

import (
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/widget"
)

func main() {
    myApp := app.New()
    myWindow := myApp.NewWindow("Hello")
    myWindow.SetContent(widget.NewLabel("Hello Fyne!"))
    myWindow.ShowAndRun()
}

GTK example:

use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, Button};

fn main() {
    let app = Application::builder().build();
    app.connect_activate(|app| {
        let window = ApplicationWindow::builder()
            .application(app)
            .title("Hello")
            .build();
        let button = Button::with_label("Hello GTK!");
        window.add(&button);
        window.show_all();
    });
    app.run(&[]);
}

Both examples create a simple window with a label or button, showcasing the basic structure and syntax differences between Fyne and GTK.

24,082

A cross-platform GUI library for Rust, inspired by Elm

Pros of iced

  • Pure Rust implementation, offering better safety and easier integration
  • Designed for cross-platform development, including web applications
  • More modern, reactive approach to UI development

Cons of iced

  • Smaller ecosystem and community compared to GTK
  • Less mature, with fewer built-in widgets and features
  • Limited support for native OS look-and-feel

Code Comparison

iced example:

use iced::{button, Button, Column, Element, Sandbox, Settings, Text};

struct Counter {
    value: i32,
    increment_button: button::State,
    decrement_button: button::State,
}

impl Sandbox for Counter {
    // ... implementation details
}

gtk-rs example:

use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, Button};

fn main() {
    let app = Application::builder().build();
    app.connect_activate(|app| {
        let window = ApplicationWindow::builder()
            .application(app)
            .title("My GTK App")
            .build();
        // ... more implementation details
    });
    app.run(&[]);
}

Both iced and gtk-rs provide Rust bindings for creating graphical user interfaces. iced offers a more Rust-centric approach with a focus on type safety and cross-platform development, while gtk-rs provides access to the mature and feature-rich GTK toolkit. The choice between them depends on project requirements, target platforms, and developer preferences.

30,490

Rust / Wasm framework for creating reliable and efficient web applications

Pros of Yew

  • Web-based: Yew targets web applications, allowing for cross-platform deployment without native dependencies
  • React-like: Familiar component-based architecture for developers with React experience
  • WebAssembly: Leverages Rust's performance in the browser through WebAssembly

Cons of Yew

  • Limited to web: Not suitable for native desktop applications, unlike GTK
  • Ecosystem: Smaller ecosystem and fewer UI components compared to GTK's mature toolkit

Code Comparison

Yew component example:

use yew::prelude::*;

#[function_component(App)]
fn app() -> Html {
    html! { <h1>{"Hello, World!"}</h1> }
}

GTK component example:

use gtk::prelude::*;

fn build_ui(app: &gtk::Application) {
    let window = gtk::ApplicationWindow::new(app);
    window.set_title("Hello, World!");
    window.show_all();
}

Summary

Yew is ideal for web applications leveraging Rust's performance through WebAssembly, with a React-like component model. GTK, on the other hand, excels in creating native desktop applications with a rich set of UI components. The choice between them depends on the target platform and development preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

gtk Build Status Build status Gitter

Project site | Online documentation

Rust bindings and wrappers for GLib, GDK 3, GTK+ 3 and Cairo.

Building

gtk expects GTK+, GLib and Cairo development files to be installed on your system. See the GTK installation page.

Using

We recommend using crates from crates.io, as demonstrated here.

If you want to track the bleeding edge, use the git dependency instead:

[dependencies]
gtk = { git = "https://github.com/gtk-rs/gtk.git" }

Avoid mixing versioned and git crates like this:

# This will not compile
[dependencies]
gdk = "0.2"
gtk = { git = "https://github.com/gtk-rs/gtk.git" }

Documentation

The majority of the documentation is kept in a separate repo due to licensing issues. You can pull it in with cargo:

> cargo build --features embed-lgpl-docs

Changes to those doc-comments should be submitted to the lgpl-docs repo. Avoid including those embedded doc-comments in PRs to this repo.

The opposite feature removes all of those docs regardless of edits:

> cargo build --features purge-lgpl-docs

These features rewrite the crate sources so it's sufficient to enable them once. Omitting them in the following cargo invocations will not undo their effects!

Generate the docs:

> cargo doc --features v3_16

(if the installed GTK+ version is lower than 3.16, adjust the feature name accordingly).

Contribute

Contributor you're welcome!

See the general bindings documentation.

Most of the bindings (src/auto) are generated by gir using this configuration file. After editing Gir.toml the sources can be regenerated with

> make gir

When opening a PR please put the changes to the src/auto directory in a separate commit.

You may also wish to run cargo clippy -- -D warnings and check that you're clean because otherwise you may be surprised when CI fails.

License

gtk is available under the MIT License, please refer to it.