The toolKit Abstraction System is not a GUI toolkit in the traditional sense — instead it provides an abstraction layer between an application's GUI description and the toolkit.
Rust has several existing GUI tools / projects:
Rust currently has a smattering of GUI libraries, but none currently offer the full complement of features which really show off the strengths of the Rust language:
Note that certain trade-offs must be made to allow the above goals; in particular this means the library will not be easy to use via FFI (e.g. from C):
It is also worth noting that we currently make no attempt to support building GUIs at run-time. This should eventually be possible to some extent, but is not a current goal.
A GUI system needs at least the following components:
This library focuses on providing a clean API for the last item (the application) via an abstraction layer over widget drawing, positioning and event handling. Specifically, this library provides:
This approach allows both the usage of a high-level GUI toolkit doing all the heavy lifting (the first toolkit being a wrapper around GTK) and implementation of a complete toolkit from scratch (in theory; this has yet to be done).
This design should therefore eventually support building applications using native widget rendering on all major desktops from a single source, as well as the option to use a toolkit which minimises non-Rust dependencies for ultimate performance and portability.
Widget behaviour is described via four traits, all of which are typically implemented via macro:
Coretrait handles access to common, core data; this is typically implemented over a
Layouttrait; this must be implemented by macro since it requires access to non-public parts of the API.
Widgettrait handles a few common operations implemented over the above traits, including access to child widgets.
Handlertrait implements event handling. This trait uses an associated type to allow user-defined return values, which may be caught and handled by a parent widget.
The library provides some standard widgets: a text label, a push-button, etc. Currently only a few are available; this should be expanded to a full set.
Some of these standard widgets are templated in order to allow user-defined payloads to be returned from handled events; e.g.:
TextButton::new("+", || Message::Incr)
defines a push-button labelled
+ which returns the enum value
when clicked. This allows application logic to be implemented on a parent widget
which encapsulates its controls.
Simple (or complex) widgets are typically encapsulated in parent widgets, which
position each sub-widget relative to the self and encapsulate event handling.
Typically such widgets are single-use. This library provides a convenient method
of constructing them: the
This macro creates a new struct type, implements all widget traits for this type, then constructs a new instance using the given values. Note that in many cases the types of sub-widgets need not be explicitly given and often the names of fields are not important; this macro allows both to be omitted.
The macro syntax is complex and likely to be refined; see the examples and the API documentation for details.
make_widget macro mentioned above is merely provided for convenience; its
usage is not required (compare the
The file includes a list of contributors who claim copyright on this project. This list may be incomplete; new contributors may optionally add themselves to this list.
The KAS library is published under the terms of the Apache License, Version 2.0. You may obtain a copy of this licence from the file or on the following webpage: https://www.apache.org/licenses/LICENSE-2.0