Skip to content

Commit 56fccc8

Browse files
committed
added slint example
1 parent 8de1ce1 commit 56fccc8

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ IF(CPP_STARTER_USE_OPEN62541)
4848
ADD_SUBDIRECTORY(open62541)
4949
ENDIF()
5050

51+
# slint example
52+
IF(CPP_STARTER_USE_SLINT)
53+
MESSAGE("Using slint")
54+
ADD_SUBDIRECTORY(slint)
55+
ENDIF()
5156

5257
FIND_PACKAGE(docopt REQUIRED)
5358
FIND_PACKAGE(spdlog REQUIRED)

src/slint/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
INCLUDE(FetchContent)
2+
3+
FIND_PACKAGE(Slint QUIET)
4+
IF(NOT Slint_FOUND)
5+
MESSAGE(STATUS "Slint could not be located in the CMake module search path. Downloading it from Git and building it locally")
6+
FETCHCONTENT_DECLARE(
7+
Slint
8+
GIT_REPOSITORY https://github.com/slint-ui/slint.git
9+
GIT_TAG v1.9.2 # pin to a specific release for reproducible builds
10+
SOURCE_SUBDIR api/cpp
11+
GIT_SHALLOW TRUE # faster clone, no full history needed
12+
)
13+
FETCHCONTENT_MAKEAVAILABLE(Slint)
14+
ENDIF()
15+
16+
ADD_EXECUTABLE(slintExample src/main.cpp)
17+
TARGET_LINK_LIBRARIES(slintExample PRIVATE Slint::Slint)
18+
SLINT_TARGET_SOURCES(slintExample ui/app-window.slint)
19+
# On Windows, copy the Slint DLL next to the application binary so that it's found.
20+
IF(WIN32)
21+
ADD_CUSTOM_COMMAND(TARGET slintExample POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:slintExample> $<TARGET_FILE_DIR:slintExample> COMMAND_EXPAND_LISTS)
22+
ENDIF()

src/slint/src/main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <app-window.h>
2+
3+
int main()
4+
{
5+
auto ui = AppWindow::create();
6+
7+
ui->on_request_increase_value([ui]{
8+
ui->set_counter(ui->get_counter() + 1);
9+
});
10+
11+
ui->run();
12+
return 0;
13+
}

src/slint/ui/app-window.slint

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Button, VerticalBox } from "std-widgets.slint";
2+
3+
export component AppWindow inherits Window {
4+
in-out property<int> 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+
}

0 commit comments

Comments
 (0)