dtk is an open source library for building lightweight desktop applications.
Features:
- Support for Linux, macOS, and Windows
- Collection of widgets including buttons, editors, sliders, and menus
- Collection of layouts including horizontal, vertical, grid, and tabs
- Keyboard navigation
- Command-line parsing
- Written in C++17 with a CMake build system
- Entire project and dependencies can be built in a few minutes
- Statically linked demo binaries are under 10MB
- BSD open source license
Work in progress:
- Multiple line text editor widget
- Python bindings
Projects using dtk:
Demo example with dark color style:
Demo example with light color style:
Simple C++ example that shows a window with a text label:
#include <dtk/ui/App.h>
#include <dtk/ui/Label.h>
#include <dtk/ui/MainWindow.h>
using namespace dtk;
int main(int argc, char** argv)
{
// Create the context and application.
auto context = Context::create();
auto app = App::create(context, argc, argv, "simple", "Simple example");
if (app->getExit() != 0)
return app->getExit();
// Create a window.
auto window = MainWindow::create(context, app, "simple", Size2I(1280, 960));
// Create a label.
auto label = Label::create(context, "Hello world");
label->setFontRole(FontRole::Title);
label->setAlign(HAlign::Center, VAlign::Center);
label->setStretch(Stretch::Expanding);
window->setWidget(label);
// Show the window and run the application.
window->show();
app->run();
return 0;
}
Simple Python exmple that shows a window with a text label:
import dtk
import sys
# Create the context and application.
context = dtk.Context()
app = dtk.App(context, sys.argv, "simple", "Simple example")
if app.getExit() != 0:
sys.exit(app.getExit())
# Create a window.
window = dtk.MainWindow(context, app, "simple", dtk.Size2I(1280, 960))
# Create a label.
label = dtk.Label(context, "Hello world")
label.fontRole = dtk.FontRole.Title
label.setAlign(dtk.HAlign.Center, dtk.VAlign.Center);
label.setStretch(dtk.Stretch.Expanding);
window.setWidget(label)
# Show the window and run the application.
window.show()
app.run()
# \bug Need to manually reset the window.
window = None
A CMake super build script is provided to build all of the dependencies from source.
Required dependencies:
Optional dependencies:
Clone the repository:
git clone https://github.com/darbyjohnston/dtk.git
Run CMake:
cmake -S dtk/etc/SuperBuild -B Release -DCMAKE_INSTALL_PREFIX=$PWD/Release/install -DCMAKE_PREFIX_PATH=$PWD/Release/install -DCMAKE_BUILD_TYPE=Release
Start the build:
cmake --build Release -j 4 --config Release
Try running the simple
example:
Release/dtk/src/dtk-build/examples/simple/simple
Clone the repository:
git clone https://github.com/darbyjohnston/dtk.git
Run CMake:
cmake -S dtk/etc/SuperBuild -B Release -DCMAKE_INSTALL_PREFIX=$PWD/Release/install -DCMAKE_PREFIX_PATH=$PWD/Release/install -DCMAKE_BUILD_TYPE=Release
Start the build:
cmake --build Release -j 4 --config Release
Try running the simple
example:
Release/dtk/src/dtk-build/examples/simple/simple
The CMake variable "CMAKE_OSX_ARCHITECTURES" can be used to specify the build architecture:
-DCMAKE_OSX_ARCHITECTURES=x86_64
-DCMAKE_OSX_ARCHITECTURES=arm64
Clone the repository:
git clone https://github.com/darbyjohnston/dtk.git
Run CMake:
cmake -S dtk\etc\SuperBuild -B Release -DCMAKE_INSTALL_PREFIX=%CD%\Release\install -DCMAKE_PREFIX_PATH=%CD%\Release\install -DCMAKE_BUILD_TYPE=Release
Start the build:
cmake --build Release -j 4 --config Release
Try running the simple
example:
Release\dtk\src\dtk-build\examples\simple\Release\simple