slint/examples
Simon Hausmann 9543a26201 Fix printer demo coming up too small in live-preview
There's an issue that the live-preview doesn't respect the preferred size when actively choosing to preview a new component, but regardless it makes sense to avoid shrinking the printer demo.

Amends ccc795beb8
2024-08-08 11:04:16 +02:00
..
7guis Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
bash Examples: port simple_input.sh to the new syntax 2024-06-11 09:06:07 +02:00
carousel Fix Node.js example instructions 2024-08-01 13:37:20 +02:00
cpp C++: minimize/maximize/fullscreen API on Window 2024-02-22 13:17:50 +01:00
energy-monitor Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
fancy_demo Remove stray imports of StyleMetrics 2024-07-12 09:13:35 +02:00
ffmpeg Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
gallery Update Translations: extract strings 2024-08-08 03:04:10 +00:00
gstreamer-player Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
imagefilter Fix Node.js example instructions 2024-08-01 13:37:20 +02:00
iot-dashboard Add an in-out boolean color-scheme property to Palette (#4701) 2024-03-26 15:44:22 +01:00
maps Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
mcu-board-support Revert "ESP32: Fix flashing examples such as printerdemo_mcu with espflash" 2024-08-06 14:27:23 +02:00
memory Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
opengl_texture Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
opengl_underlay Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
plotter Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
printerdemo Fix printer demo coming up too small in live-preview 2024-08-08 11:04:16 +02:00
printerdemo_mcu Zephyr: move the demo to examples/printerdemo 2024-08-07 15:26:32 +02:00
printerdemo_old Fix Node.js example instructions 2024-08-01 13:37:20 +02:00
slide_puzzle Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
todo Fix Node.js example instructions 2024-08-01 13:37:20 +02:00
todo-mvc Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
uefi-demo Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
virtual_keyboard Bump version number to 1.7.1 2024-07-23 12:05:34 +00:00
weather-demo Rename the weather-demo library name 2024-08-07 16:08:12 +02:00
CMakeLists.txt Fix build on Linux where GLESv3 is not present 2023-10-02 13:16:20 +02:00
README.md Fix Node.js example instructions 2024-08-01 13:37:20 +02:00

Examples

These examples demonstrate the main features of Slint and how to use them in different language environments.

printerdemo

A fictional user interface for the touch screen of a printer

.slint Design Rust Source C++ Source Node Source Online wasm Preview Open in SlintPad
ui.slint main.rs main.cpp main.js Online simulation Preview in Online Code Editor

Screenshot of the Printer Demo

A simple application showing the different widgets

.slint Design Rust Source C++ Source Online wasm Preview Open in SlintPad
gallery.slint main.rs main.cpp Online simulation Preview in Online Code Editor

Screenshot of the Gallery on Windows

energy-monitor

A fictional user interface of a device that monitors energy consumption in a building.

.slint Design Rust Source Online wasm Preview Open in SlintPad
desktop_window.slint main.rs Online simulation Preview in Online Code Editor

Screenshot of the Energy-Monitor Demo

todo

A simple todo application

.slint Design Rust Source C++ Source NodeJS Online wasm Preview Open in SlintPad
todo.slint main.rs main.cpp main.js Online simulation Preview in Online Code Editor

Screenshot of the Todo Demo

todo-mvc

A simple todo application based on the Model View Controller pattern.

.slint Design Rust Source Online wasm Preview Open in SlintPad
index.slint main.rs Online simulation Preview in Online Code Editor

A custom carousel widget that can be controlled by touch, mouse and keyboard

The example can be run on desktop, wasm and mcu platforms

.slint Design Rust Source C++ Source Node Source Online wasm Preview Open in SlintPad
ui.slint main.rs main.cpp main.js Online simulation Preview in Online Code Editor

Screenshot of the Carousel Demo

slide_puzzle

Puzzle game based on a Flutter example. See Readme

.slint Design Rust Source Online wasm Preview Open in SlintPad
slide_puzzle.slint main.rs Online simulation Preview in Online Code Editor

Screenshot of the Slide Puzzle

memory

A basic memory game used as an example the tutorial:

.slint Design Rust Source C++ Source Online wasm Preview Open in SlintPad
memory.slint main.rs memory.cpp Online simulation Preview in Online Code Editor

iot-dashboard

A clone of one demo from the QSkinny framework.

Also show how a way to dynamically load widgets with the interpreter from C++.

.slint Design C++ Source Online wasm Preview Open in SlintPad
main.slint main.cpp Online preview Preview in Online Code Editor

Screenshot of the IOT Dashboard

imagefilter

A Rust-only example that shows how to use the Rust image crate to do image manipulations and feed the result into Slint.

.slint Design Rust Source TypeScript Source Online wasm Preview
main.slint main.rs main.ts Online simulation

Screenshot of the imagefilter example

plotter

A Rust-only example that shows how to use the Rust plotters crate to do plot a graph and integrate the result into Slint.

.slint Design Rust Source Online wasm Preview
plotter.slint main.rs Online simulation

Screenshot of the plotter example

bash

Some examples of how to use the slint-viewer to add a GUI to shell scripts.

opengl_underlay

A Rust and C++ example that shows how render Slint on top of graphical effect rendered using custom OpenGL code. For more details check out the Readme.

.slint Design Rust Source C++ Source Online wasm Preview
scene.slint main.rs main.cpp Online simulation

Screenshot of the OpenGL Underlay Example on Windows

opengl_texture

A Rust and C++ example that shows how render a scene with custom OpenGL code into a texture and render that texture within a Slint scene. For more details check out the Readme.

.slint Design Rust Source C++ Source
scene.slint main.rs main.cpp

Screenshot of the OpenGL Texture Example on macOS

ffmpeg

A Rust example that shows how render video frames with FFmpeg within a Slint scene. For more details check out the Readme.

.slint Design Rust Source
scene.slint main.rs

Screenshot of the FFmpeg Example on macOS

maps

A rust example that load image tiles asynchronously from OpenStreetMap server and allow panning and zooming

Screenshot of the maps example

virtual keyboard

.slint Design Rust Source C++ Source
main_window.slint main.rs main.cpp

A Rust and C++ example that shows how to implement a custom virtual keyboard in Slint. For more details check out the Readme.

Screenshot of Virtual Keyboard Example on macOS

7guis

Our implementations of the "7GUIs" Tasks.

Composition of 7GUIs Screenshots

weather-demo

A simple, cross-platform (Desktop, Android, Wasm) weather application using real weather data from the OpenWeather API.

.slint Design Rust Source (Desktop) Rust Source (Android / Wasm) Online wasm Preview Open in SlintPad
main.slint main.rs lib.rs Online simulation Preview in Online Code Editor

Screenshot of the Weather Demo Desktop

Screenshot of the Weather Demo Desktop

External examples

  • Cargo UI: A rust application that makes use of threads in the background.

Screenshot of Cargo UI

Loading the example with the viewer

Simply load the .slint file with the viewer application

cargo run --release --bin slint-viewer -- examples/printerdemo/ui/printerdemo.slint

Running the Rust Examples

You can run the examples either by going into the rust sub-folder and use cargo run, for example:

cd examples/printerdemo/rust
cargo run --release

or you can run them from anywhere in the Cargo workspace by name:

cargo run --release --bin printerdemo

Wasm builds

In order to make the wasm build of the example, you first need to edit the Cargo.toml files to uncomment the line starting with #wasm# (or use the sed line bellow) You can then use wasm-pack (which you may need to obtain with cargo install wasm-pack). This will generate the wasm in the ./pkg directory, which the index.html file will open. Since wasm files cannot be served from file:// URL, you need to open a wab server to serve the content

cd examples/printerdemo/rust
sed -i "s/^#wasm# //" Cargo.toml
wasm-pack build --release --target web
python3 -m http.server

Running the C++ Examples

  • When compiling Slint from sources: If you follow the C++ build instructions, this will build the C++ examples as well by default
  • From installed binary packages: Simply run cmake in one of the example directory containing a CMakeLists.txt
mkdir build && cd build
cmake -GNinja -DCMAKE_PREFIX_PATH="<path to installed>" ..
cmake --build .

Running the Node Examples

You can run the examples by going into the node sub-folder and use npm, for example:

pushd api/node
npm install
npm run compile
popd
cd examples/printerdemo/node
npm install
npm start