Skip to content

Commit 125b90a

Browse files
committed
Merge remote-tracking branch 'origin/master' into wip/rename
Conflicts: api/cpp/cbindgen.rs api/cpp/include/slint.h examples/CMakeLists.txt examples/imagefilter/Cargo.toml examples/plotter/main.rs internal/backends/mcu/lib.rs
2 parents 1358de4 + 2f27c78 commit 125b90a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1475
-143
lines changed

.github/workflows/nightly_snapshot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ jobs:
286286
rm -rf snapshots/$target_branch/demos
287287
mkdir -p snapshots/$target_branch/demos
288288
289-
for demo_subdir in gallery, printerdemo,rust printerdemo_old,rust todo,rust slide_puzzle, memory, imagefilter, plotter,; do
289+
for demo_subdir in gallery, printerdemo,rust printerdemo_old,rust todo,rust slide_puzzle, memory, imagefilter, plotter, opengl_underlay,; do
290290
IFS=',' read demo subdir <<< "${demo_subdir}"
291291
292292
mkdir -p snapshots/$target_branch/demos/$demo

.github/workflows/wasm_demos.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ jobs:
6464
sed -i "s/#wasm# //" Cargo.toml
6565
wasm-pack build --release --target web
6666
working-directory: examples/plotter
67+
- name: OpenGL underlay example WASM build
68+
run: |
69+
sed -i "s/#wasm# //" Cargo.toml
70+
wasm-pack build --release --target web
71+
working-directory: examples/opengl_underlay
6772
- name: "Upload Demo Artifacts"
6873
uses: actions/upload-artifact@v2
6974
with:
@@ -77,6 +82,7 @@ jobs:
7782
examples/slide_puzzle/
7883
examples/imagefilter/
7984
examples/plotter/
85+
examples/opengl_underlay/
8086
- name: Clean cache # Otherwise the cache is much too big
8187
run: |
8288
du -hs target

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ as well as the [Rust migration guide for the `sixtyfps` crate](api/rs/slint/migr
2828
### Added
2929

3030
- `TextEdit::font-size` and `LineEdit::font-size` have been added to control the size of these widgets.
31+
- Added `sixtyfps::Window::set_rendering_notifier` to get a callback before and after a new frame is being rendered.
32+
- Added `sixtyfps::Window::request_redraw()` to schedule redrawing of the window contents.
3133

3234
### Fixed
3335

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ members = [
1414
'examples/gallery',
1515
'examples/imagefilter',
1616
'examples/memory',
17+
'examples/opengl_underlay',
1718
'examples/plotter',
1819
'examples/printerdemo_old/rust',
1920
'examples/printerdemo/rust',

api/cpp/cbindgen.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ fn gen_corelib(
128128
.map(|x| x.to_string())
129129
.collect();
130130

131+
let mut private_exported_types: std::collections::HashSet<String> =
132+
config.export.include.iter().cloned().collect();
133+
131134
config.export.exclude = [
132135
"SharedString",
133136
"SharedVector",
@@ -157,8 +160,10 @@ fn gen_corelib(
157160
"slint_color_darker",
158161
"slint_image_size",
159162
"slint_image_path",
160-
"TimerMode", // included in generated_public.h
161-
"IntSize", // included in generated_public.h
163+
"TimerMode", // included in generated_public.h
164+
"IntSize", // included in generated_public.h
165+
"RenderingState", // included in generated_public.h
166+
"SetRenderingNotifierError", // included in generated_public.h
162167
]
163168
.iter()
164169
.map(|x| x.to_string())
@@ -201,6 +206,7 @@ fn gen_corelib(
201206
.insert("StateInfo".to_owned(), " using Instant = uint64_t;".into());
202207
properties_config.structure.derive_eq = true;
203208
properties_config.structure.derive_neq = true;
209+
private_exported_types.extend(properties_config.export.include.iter().cloned());
204210
cbindgen::Builder::new()
205211
.with_config(properties_config)
206212
.with_src(crate_dir.join("properties.rs"))
@@ -252,6 +258,8 @@ fn gen_corelib(
252258
"slint_windowrc_set_focus_item",
253259
"slint_windowrc_set_component",
254260
"slint_windowrc_show_popup",
261+
"slint_windowrc_set_rendering_notifier",
262+
"slint_windowrc_request_redraw",
255263
"slint_new_path_elements",
256264
"slint_new_path_events",
257265
"slint_color_brighter",
@@ -280,6 +288,9 @@ fn gen_corelib(
280288
// Property<> fields uses the public `slint::Blah` type
281289
special_config.namespaces =
282290
Some(vec!["slint".into(), "cbindgen_private".into(), "types".into()]);
291+
292+
private_exported_types.extend(special_config.export.include.iter().cloned());
293+
283294
cbindgen::Builder::new()
284295
.with_config(special_config)
285296
.with_src(crate_dir.join("graphics.rs"))
@@ -300,8 +311,15 @@ fn gen_corelib(
300311
let mut public_config = config.clone();
301312
public_config.namespaces = Some(vec!["slint".into()]);
302313
public_config.export.item_types = vec![cbindgen::ItemType::Enums, cbindgen::ItemType::Structs];
303-
public_config.export.include = vec!["TimerMode".into(), "IntSize".into()];
304-
public_config.export.exclude.clear();
314+
// Previously included types are now excluded (to avoid duplicates)
315+
public_config.export.exclude = private_exported_types.into_iter().collect();
316+
public_config.export.exclude.push("Point".into());
317+
public_config.export.include = vec![
318+
"TimerMode".into(),
319+
"IntSize".into(),
320+
"RenderingState".into(),
321+
"SetRenderingNotifierError".into(),
322+
];
305323

306324
public_config.export.body.insert(
307325
"IntSize".to_owned(),
@@ -315,6 +333,8 @@ fn gen_corelib(
315333
.with_config(public_config)
316334
.with_src(crate_dir.join("timers.rs"))
317335
.with_src(crate_dir.join("graphics.rs"))
336+
.with_src(crate_dir.join("window.rs"))
337+
.with_src(crate_dir.join("api.rs"))
318338
.with_after_include(format!(
319339
r"
320340
/// This macro expands to the to the numeric value of the major version of Slint you're

api/cpp/include/slint.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ class WindowRc
141141
cbindgen_private::slint_windowrc_show_popup(&inner, &popup, p, &parent_item);
142142
}
143143

144+
template<typename F>
145+
std::optional<SetRenderingNotifierError> set_rendering_notifier(F callback) const
146+
{
147+
auto actual_cb = [](RenderingState state, void *data) {
148+
(*reinterpret_cast<F *>(data))(state);
149+
};
150+
SetRenderingNotifierError err;
151+
if (cbindgen_private::sixtyfps_windowrc_set_rendering_notifier(
152+
&inner, actual_cb,
153+
[](void *user_data) { delete reinterpret_cast<F *>(user_data); },
154+
new F(std::move(callback)), &err)) {
155+
return {};
156+
} else {
157+
return err;
158+
}
159+
}
160+
161+
void request_redraw() const { cbindgen_private::sixtyfps_windowrc_request_redraw(&inner); }
162+
144163
private:
145164
cbindgen_private::WindowRcOpaque inner;
146165
};
@@ -314,6 +333,19 @@ class Window
314333
/// De-registers the window from the windowing system, therefore hiding it.
315334
void hide() { inner.hide(); }
316335

336+
/// This function allows registering a callback that's invoked during the different phases of
337+
/// rendering. This allows custom rendering on top or below of the scene.
338+
/// On success, the function returns a std::optional without value. On error, the function
339+
/// returns the error code as value in the std::optional.
340+
template<typename F>
341+
std::optional<SetRenderingNotifierError> set_rendering_notifier(F &&callback) const
342+
{
343+
return inner.set_rendering_notifier(std::forward<F>(callback));
344+
}
345+
346+
/// This function issues a request to the windowing system to redraw the contents of the window.
347+
void request_redraw() const { inner.request_redraw(); }
348+
317349
/// \private
318350
private_api::WindowRc &window_handle() { return inner; }
319351
/// \private

cmake/FindOpenGLES2.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright © SixtyFPS GmbH <[email protected]>
2+
# SPDX-License-Identifier: (GPL-3.0-only OR LicenseRef-SixtyFPS-commercial)
3+
4+
include(CheckCXXSourceCompiles)
5+
6+
find_path(OPENGLES2_INCLUDE_DIR NAMES "GLES2/gl2.h" "OpenGLES/ES2/gl.h" DOC "The path where the OpenGL ES 2.0 headers are located")
7+
find_library(OPENGLES2_LIBRARY NAMES GLESv2 OpenGLES)
8+
9+
# Sometimes EGL linkage is required, so look it up and always use if available.
10+
find_package(OpenGL COMPONENTS EGL)
11+
12+
# See if we can compile some example code with what we've found.
13+
set(saved_libraries "${CMAKE_REQUIRED_LIBRARIES}")
14+
set(saved_includes "${CMAKE_REQUIRED_INCLUDES}")
15+
16+
if (OPENGLES2_LIBRARY)
17+
list(APPEND CMAKE_REQUIRED_INCLUDES "${OPENGLES2_INCLUDE_DIR}")
18+
list(APPEND CMAKE_REQUIRED_LIBRARIES "${OPENGLES2_LIBRARY}")
19+
endif()
20+
21+
if(OPENGL_egl_LIBRARY)
22+
list(APPEND CMAKE_REQUIRED_INCLUDES "${OPENGL_EGL_INCLUDE_DIRS}")
23+
list(APPEND CMAKE_REQUIRED_LIBRARIES "${OPENGL_egl_LIBRARY}")
24+
endif()
25+
26+
check_cxx_source_compiles("
27+
#include <GLES2/gl2.h>
28+
#include <GLES2/gl2platform.h>
29+
30+
int main(int argc, char *argv[]) {
31+
glClear(GL_STENCIL_BUFFER_BIT);
32+
glUseProgram(0);
33+
}" HAVE_OPENGLES2)
34+
35+
set(CMAKE_REQUIRED_INCLUDES "${saved_includes}")
36+
set(CMAKE_REQUIRED_LIBRARIES "${saved_libraries}")
37+
38+
# Standard CMake package dance
39+
set(package_args OPENGLES2_INCLUDE_DIR OPENGLES2_LIBRARY HAVE_OPENGLES2)
40+
include(FindPackageHandleStandardArgs)
41+
find_package_handle_standard_args(OpenGLES2 DEFAULT_MSG ${package_args})
42+
mark_as_advanced(${package_args})
43+
44+
# Create a convenience target for linkage
45+
if (OPENGLES2_FOUND AND NOT TARGET OpenGLES2::OpenGLES2)
46+
add_library(OpenGLES2::OpenGLES2 UNKNOWN IMPORTED)
47+
set_property(TARGET OpenGLES2::OpenGLES2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${OPENGLES2_INCLUDE_DIR}")
48+
set_property(TARGET OpenGLES2::OpenGLES2 PROPERTY IMPORTED_LOCATION "${OPENGLES2_LIBRARY}")
49+
if (TARGET OpenGL::EGL)
50+
target_link_libraries(OpenGLES2::OpenGLES2 INTERFACE OpenGL::EGL)
51+
endif()
52+
endif()

docs/langref.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ Animation can be configured with the following parameter:
678678

679679
* `delay`: the amount of time to wait before starting the animation
680680
* `duration`: the amount of time it takes for the animation to complete
681-
* `loop-count`: FIXME
681+
* `iteration-count`: The number of times a animation should run. A negative value specifies
682+
infinite reruns. Fractual values are possible.
682683
* `easing`: can be `linear`, `ease`, `ease-in`, `ease-out`, `ease-in-out`, `cubic-bezier(a, b, c, d)` as in CSS
683684

684685
It is also possible to animate several properties with the same animation:

examples/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
cmake_minimum_required(VERSION 3.19)
44
project(SlintExamples LANGUAGES CXX)
55

6+
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
7+
8+
find_package(OpenGLES2 QUIET)
9+
610
if (NOT TARGET Slint::Slint)
7-
find_package(Slint REQUIRED)
11+
find_package(SixtyFPS REQUIRED)
812
include(FetchContent)
913
endif()
1014

@@ -22,3 +26,6 @@ endif()
2226
if (SLINT_FEATURE_INTERPRETER)
2327
add_subdirectory(iot-dashboard/)
2428
endif()
29+
if (OpenGLES2_FOUND AND SIXTYFPS_FEATURE_BACKEND_GL)
30+
add_subdirectory(opengl_underlay)
31+
endif()

examples/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ graph and integrate the result into Slint.
9191

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

94+
### [`opengl_underlay`](./opengl_underlay)
95+
96+
A Rust and C++ example that shows how render SixtyFPS on top of graphical effect rendered using custom OpenGL code. For more details check out the [Readme](./opengl_underlay).
97+
98+
| `.60` Design | Rust Source | C++ Source | Online wasm Preview |
99+
| --- | --- | --- | --- |
100+
| [`scene.60`](./opengl_underlay/scene.60) | [`main.rs`](./opengl_underlay/main.rs) | [`main.cpp`](./opengl_underlay/main.cpp) | [Online simulation](https://sixtyfps.io/snapshots/master/demos/opengl_underlay/) |
101+
102+
![Screenshot of the OpenGL Underlay Example on Windows](https://sixtyfps.io/resources/opengl_underlay_screenshot.png "OpenGL Underlay")
103+
94104
### External examples
95105

96106
* [Cargo UI](https://github.com/sixtyfpsui/cargo-ui): A rust application that makes use of threads in the background.

0 commit comments

Comments
 (0)