├── .gitignore ├── .vscode ├── extensions.json └── launch.json ├── CMakeLists.txt ├── LICENSE ├── README.md ├── src └── main.cpp └── ui └── app-window.slint /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # clangd cache 35 | .cache 36 | 37 | # CMake build directory 38 | build 39 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "vadimcn.vscode-lldb", 4 | "ms-vscode.cmake-tools", 5 | "llvm-vs-code-extensions.vscode-clangd", 6 | "Slint.slint" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "lldb", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${command:cmake.launchTargetPath}", 12 | "args": [], 13 | "cwd": "${workspaceFolder}" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.21) 2 | project(my_application LANGUAGES CXX) 3 | 4 | find_package(Slint QUIET) 5 | if (NOT Slint_FOUND) 6 | message("Slint could not be located in the CMake module search path. Downloading it from Git and building it locally") 7 | include(FetchContent) 8 | FetchContent_Declare( 9 | Slint 10 | GIT_REPOSITORY https://github.com/slint-ui/slint.git 11 | # `release/1` will auto-upgrade to the latest Slint >= 1.0.0 and < 2.0.0 12 | # `release/1.0` will auto-upgrade to the latest Slint >= 1.0.0 and < 1.1.0 13 | GIT_TAG release/1 14 | SOURCE_SUBDIR api/cpp 15 | ) 16 | FetchContent_MakeAvailable(Slint) 17 | endif (NOT Slint_FOUND) 18 | 19 | add_executable(my_application src/main.cpp) 20 | target_link_libraries(my_application PRIVATE Slint::Slint) 21 | slint_target_sources(my_application ui/app-window.slint) 22 | # On Windows, copy the Slint DLL next to the application binary so that it's found. 23 | if (WIN32) 24 | add_custom_command(TARGET my_application POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ $ COMMAND_EXPAND_LISTS) 25 | endif() 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Slint C++ Template 2 | 3 | A template for a C++ application that's using [Slint](https://slint.dev) for the user interface and CMake for the build system. 4 | 5 | ## About 6 | 7 | This template helps you get started developing a C++ application with Slint as toolkit 8 | for the user interface. It demonstrates the integration between the `.slint` UI markup and 9 | C++ code, how to trigger react to callbacks, get and set properties and use basic widgets. 10 | 11 | ## Prerequisites 12 | 13 | In order to use this template and build a C++ application, you need to install a few tools: 14 | 15 | * **[cmake](https://cmake.org/download/)** (3.21 or newer) 16 | * A C++ compiler that supports C++ 20 17 | 18 | If your target environment is Linux or Windows on an x86-64 architecture, then you may also opt into downloading one of our binary Slint packages. These are pre-compiled and require no further tools. You can find setup instructions and download links at 19 | 20 | 21 | 22 | Alternatively, this template will automatically download the Slint sources and compile them. This option requires you to install Rust by following the [Rust Getting Started Guide](https://www.rust-lang.org/learn/get-started). Once this is done, you should have the ```rustc``` compiler and the ```cargo``` build system installed in your path. 23 | 24 | ## Usage 25 | 26 | 1. Download and extract the [ZIP archive of this repository](https://github.com/slint-ui/slint-cpp-template/archive/refs/heads/main.zip). 27 | 2. Rename the extracted directory and change into it: 28 | ``` 29 | mv slint-cpp-template-main my-project 30 | cd my-project 31 | ``` 32 | 3. Configure with CMake 33 | ``` 34 | mkdir build 35 | cmake -B build 36 | ``` 37 | 4. Build with CMake 38 | ``` 39 | cmake --build build 40 | ``` 41 | 5. Run the application binary 42 | * Linux/macOS: 43 | ``` 44 | ./build/my_application 45 | ``` 46 | * Windows: 47 | ``` 48 | build\my_application.exe 49 | ``` 50 | 51 | We recommend using an IDE for development, along with our [LSP-based IDE integration for `.slint` files](https://github.com/slint-ui/slint/blob/master/tools/lsp/README.md). You can also load this project directly in [Visual Studio Code](https://code.visualstudio.com) and install our [Slint extension](https://marketplace.visualstudio.com/items?itemName=Slint.slint). 52 | 53 | ## Next Steps 54 | 55 | We hope that this template helps you get started and you enjoy exploring making user interfaces with Slint. To learn more 56 | about the Slint APIs and the `.slint` markup language check out our [online documentation](https://slint.dev/docs/cpp/). 57 | 58 | Don't forget to edit this README to replace it by yours 59 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "app-window.h" 2 | 3 | int main(int argc, char **argv) 4 | { 5 | auto ui = AppWindow::create(); 6 | 7 | ui->on_request_increase_value([&]{ 8 | ui->set_counter(ui->get_counter() + 1); 9 | }); 10 | 11 | ui->run(); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /ui/app-window.slint: -------------------------------------------------------------------------------- 1 | import { Button, VerticalBox } from "std-widgets.slint"; 2 | 3 | export component AppWindow inherits Window { 4 | in-out property counter: 42; 5 | callback request-increase-value(); 6 | VerticalBox { 7 | Text { 8 | text: "Counter: \{root.counter}"; 9 | } 10 | Button { 11 | text: "Increase value"; 12 | clicked => { 13 | root.request-increase-value(); 14 | } 15 | } 16 | } 17 | } 18 | --------------------------------------------------------------------------------