#state #gtk #widgets #libadwaita

gtk_estate

A GTK and libadwaita state association library

3 releases (breaking)

0.3.0 Jun 3, 2024
0.2.0 Apr 22, 2024
0.1.3 Jul 21, 2023

#162 in GUI

Download history 20/week @ 2024-07-30 7/week @ 2024-09-24

378 downloads per month
Used in 2 crates

MIT/Apache

94KB
2K SLoC

GTK Estate

Crates.io License Downloads Docs Twitch Status

X | Twitch | Youtube | Mastodon | GitHub | GitHub Sponsors

GTK Estate is a state association library for GTK widgets using the excellent GTK 4 and libadwaita libraries.


The main purpose of GTK Estate is to provide a convenient way to associate user-defined state objects with GTK and libadwaita container widgets. Using user-defined objects you control the user-centric state of their associated widgets and react to their signals. GTK Estate also contains objects such as TimeOut and helper functions that can assist you in building dynamic GTK applications programmatically.

The StateContainers struct is a singleton and contains widget state association hashmaps, each type of widget gets its own map instance.



mod application_state;

use gtk_estate::{adw::{prelude::*, Application}, StateContainers};

use crate::application_state::ApplicationState;

fn main()
{

    let app = Application::builder().application_id("org.example_gui").build();

    //Explicit initialisation of the StateContainers object is no longer required as of v0.3.0.

    //StateContainers::init();

    //The ApplicationState (which you define) should add itself to the StateContainers instance from within its own constructor.

    ApplicationState::new(&app);

    //Run the application

    _ = app.run();

}


In the above example an adw::Application is constructed then ApplicationState is instantiated and passed a reference to the Application (a clone of which will become part of its state). An ApplicationState object must implement ApplicationStateContainer, likewise widget state container objects (including windows) must implement WidgetStateContainer (see example applications).

StateContainers is a single-threaded singleton which should only contain state which deals with UI and inter-thread-communication related tasks probably using a crate like act_rs for the latter.


Building Requirements

Requires the GTK4 library binaries on your system (See The GTK Book for GTK installation instructions).

Search your software repositories to find the libadwaita libraries if you want to use any adw features.


Features

GTK4

Feature Enabled Feature
gtk_v4_14 gtk4/v4_14
gtk_v4_12 gtk4/v4_12
gtk_v4_10 gtk4/v4_10
gtk_v4_8 gtk4/v4_8
gtk_v4_6 gtk4/v4_6
gtk_v4_4 gtk4/v4_4
gtk_v4_2 gtk4/v4_2
gtk_gnome_45 gtk4/gnome_45
gtk_gnome_44 gtk4/gnome_44
gtk_gnome_43 gtk4/gnome_43
gtk_gnome_42 gtk4/gnome_42
gtk_unsafe-assume-initialized gtk4/unsafe-assume-initialized
gtk_xml_validation gtk4/xml_validation
gtk_blueprint gtk4/blueprint

libadwaita

Feature Enabled Feature
adw dep:adw
adw_gtk_v4_2 adw/gtk_v4_2
adw_gtk_v4_4 adw/gtk_v4_4
adw_gtk_v4_6 adw/gtk_v4_6
adw_gtk_v4_8 adw/gtk_v4_8
adw_gtk_v4_10 adw/gtk_v4_10
adw_gtk_v4_12 adw/gtk_v4_12
adw_v1_2 adw/v1_2
adw_v1_3 adw/v1_3
adw_v1_4 adw/v1_4
adw_v1_5 adw/v1_5

Additionally

GTK Estate Re-exposes:

  • GTK4 (gtk)
  • libadwaita (adw (if selected))
  • Corlib (corlib)

Todo

  • Add more GTK/adw helper functions and helper objects.
  • Add more documentation.

Example Applications


Coding Style

This project uses a coding style which emphasises the use of white space over keeping the line and column counts as low as possible.

So this:

fn foo()
{

    bar();

}

Not this:

fn foo()
{
    bar();
}


License

Licensed under either of:

at your discretion


Contributing

Please clone the repository and create an issue explaining what feature or features you'd like to add or bug or bugs you'd like to fix and perhaps how you intend to implement these additions or fixes. Try to include details though it doesn't need to be exhaustive and we'll take it from there (dependant on availability).


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~16–25MB
~456K SLoC