mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-01 20:31:27 +00:00
Apply the renaming also to the new opengl_underlay example pulled from master
This commit is contained in:
parent
125b90a64b
commit
1314aa97bf
7 changed files with 30 additions and 30 deletions
|
|
@ -4,10 +4,10 @@
|
||||||
cmake_minimum_required(VERSION 3.14)
|
cmake_minimum_required(VERSION 3.14)
|
||||||
project(opengl_cpp_underlay LANGUAGES CXX)
|
project(opengl_cpp_underlay LANGUAGES CXX)
|
||||||
|
|
||||||
if (NOT TARGET SixtyFPS::SixtyFPS)
|
if (NOT TARGET Slint::Slint)
|
||||||
find_package(SixtyFPS REQUIRED)
|
find_package(Slint REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(opengl_underlay main.cpp)
|
add_executable(opengl_underlay main.cpp)
|
||||||
target_link_libraries(opengl_underlay PRIVATE SixtyFPS::SixtyFPS OpenGLES2::OpenGLES2)
|
target_link_libraries(opengl_underlay PRIVATE Slint::Slint OpenGLES2::OpenGLES2)
|
||||||
sixtyfps_target_60_sources(opengl_underlay scene.60)
|
slint_target_sources(opengl_underlay scene.slint)
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,12 @@ path = "main.rs"
|
||||||
name = "opengl_underlay"
|
name = "opengl_underlay"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sixtyfps = { path = "../../api/sixtyfps-rs" }
|
slint = { path = "../../api/rs/slint" }
|
||||||
glow = { version = "0.11" }
|
glow = { version = "0.11" }
|
||||||
instant = { version = "0.1", features = [ "now" ] }
|
instant = { version = "0.1", features = [ "now" ] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
sixtyfps-build = { path = "../../api/rs/build" }
|
slint-build = { path = "../../api/rs/build" }
|
||||||
|
|
||||||
# Remove the `#wasm#` to uncomment the wasm build.
|
# Remove the `#wasm#` to uncomment the wasm build.
|
||||||
# This is commented out by default because we don't want to build it as a library by default
|
# This is commented out by default because we don't want to build it as a library by default
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
This example application demonstrates how layer two scenes together in a window:
|
This example application demonstrates how layer two scenes together in a window:
|
||||||
|
|
||||||
1. First a graphical effect is rendered using low-level OpenGL code (underlay).
|
1. First a graphical effect is rendered using low-level OpenGL code (underlay).
|
||||||
2. A scene of SixtyFPS elements is rendered above.
|
2. A scene of Slint elements is rendered above.
|
||||||
|
|
||||||
This is implemented using the `set_rendering_notifier` function on the `sixtyfps::Window` type. It takes a callback as a parameter and that is invoked during different phases of the rendering. In this example the invocation during the setup phase is used to prepare the pipeline for OpenGL rendering later. Then the `BeforeRendering` phase is used to render the graphical effect with OpenGL. Afterwards, SixtyFPS will render the scene of elements into the same back-buffer as the previous OpenGL code rendered into.
|
This is implemented using the `set_rendering_notifier` function on the `slint::Window` type. It takes a callback as a parameter and that is invoked during different phases of the rendering. In this example the invocation during the setup phase is used to prepare the pipeline for OpenGL rendering later. Then the `BeforeRendering` phase is used to render the graphical effect with OpenGL. Afterwards, Slint will render the scene of elements into the same back-buffer as the previous OpenGL code rendered into.
|
||||||
|
|
||||||
Since the graphical effect is continuous, the code in the callback requests a redraw of the contents by calling `sixtyfps::Window::request_redraw()`.
|
Since the graphical effect is continuous, the code in the callback requests a redraw of the contents by calling `slint::Window::request_redraw()`.
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@
|
||||||
// SPDX-License-Identifier: (GPL-3.0-only OR LicenseRef-SixtyFPS-commercial)
|
// SPDX-License-Identifier: (GPL-3.0-only OR LicenseRef-SixtyFPS-commercial)
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
sixtyfps_build::compile("scene.60").unwrap();
|
slint_build::compile("scene.slint").unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,23 +42,23 @@ static GLint compile_shader(GLuint program, GLuint shader_type, const GLchar *co
|
||||||
class OpenGLUnderlay
|
class OpenGLUnderlay
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OpenGLUnderlay(sixtyfps::ComponentWeakHandle<App> app) : app_weak(app) { }
|
OpenGLUnderlay(slint::ComponentWeakHandle<App> app) : app_weak(app) { }
|
||||||
|
|
||||||
void operator()(sixtyfps::RenderingState state)
|
void operator()(slint::RenderingState state)
|
||||||
{
|
{
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case sixtyfps::RenderingState::RenderingSetup:
|
case slint::RenderingState::RenderingSetup:
|
||||||
setup();
|
setup();
|
||||||
break;
|
break;
|
||||||
case sixtyfps::RenderingState::BeforeRendering:
|
case slint::RenderingState::BeforeRendering:
|
||||||
if (auto app = app_weak.lock()) {
|
if (auto app = app_weak.lock()) {
|
||||||
render((*app)->get_rotation_enabled());
|
render((*app)->get_rotation_enabled());
|
||||||
(*app)->window().request_redraw();
|
(*app)->window().request_redraw();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case sixtyfps::RenderingState::AfterRendering:
|
case slint::RenderingState::AfterRendering:
|
||||||
break;
|
break;
|
||||||
case sixtyfps::RenderingState::RenderingTeardown:
|
case slint::RenderingState::RenderingTeardown:
|
||||||
teardown();
|
teardown();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +153,7 @@ private:
|
||||||
|
|
||||||
void teardown() { glDeleteProgram(program); }
|
void teardown() { glDeleteProgram(program); }
|
||||||
|
|
||||||
sixtyfps::ComponentWeakHandle<App> app_weak;
|
slint::ComponentWeakHandle<App> app_weak;
|
||||||
GLuint program = 0;
|
GLuint program = 0;
|
||||||
GLuint position_location = 0;
|
GLuint position_location = 0;
|
||||||
GLuint effect_time_location = 0;
|
GLuint effect_time_location = 0;
|
||||||
|
|
@ -167,7 +167,7 @@ int main()
|
||||||
auto app = App::create();
|
auto app = App::create();
|
||||||
|
|
||||||
if (auto error = app->window().set_rendering_notifier(OpenGLUnderlay(app))) {
|
if (auto error = app->window().set_rendering_notifier(OpenGLUnderlay(app))) {
|
||||||
if (*error == sixtyfps::SetRenderingNotifierError::Unsupported) {
|
if (*error == slint::SetRenderingNotifierError::Unsupported) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"This example requires the use of the GL backend. Please run with the "
|
"This example requires the use of the GL backend. Please run with the "
|
||||||
"environment variable SIXTYFPS_BACKEND=GL set.\n");
|
"environment variable SIXTYFPS_BACKEND=GL set.\n");
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
sixtyfps::include_modules!();
|
slint::include_modules!();
|
||||||
|
|
||||||
use glow::HasContext;
|
use glow::HasContext;
|
||||||
|
|
||||||
|
|
@ -169,14 +169,14 @@ pub fn main() {
|
||||||
// eprintln!("rendering state {:#?}", state);
|
// eprintln!("rendering state {:#?}", state);
|
||||||
|
|
||||||
match state {
|
match state {
|
||||||
sixtyfps::RenderingState::RenderingSetup => {
|
slint::RenderingState::RenderingSetup => {
|
||||||
let context = match graphics_api {
|
let context = match graphics_api {
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
sixtyfps::GraphicsAPI::NativeOpenGL { get_proc_address } => unsafe {
|
slint::GraphicsAPI::NativeOpenGL { get_proc_address } => unsafe {
|
||||||
glow::Context::from_loader_function(|s| get_proc_address(s))
|
glow::Context::from_loader_function(|s| get_proc_address(s))
|
||||||
},
|
},
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
sixtyfps::GraphicsAPI::WebGL { canvas_element_id, context_type } => {
|
slint::GraphicsAPI::WebGL { canvas_element_id, context_type } => {
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
|
|
||||||
let canvas = web_sys::window()
|
let canvas = web_sys::window()
|
||||||
|
|
@ -201,21 +201,21 @@ pub fn main() {
|
||||||
};
|
};
|
||||||
underlay = Some(EGLUnderlay::new(context))
|
underlay = Some(EGLUnderlay::new(context))
|
||||||
}
|
}
|
||||||
sixtyfps::RenderingState::BeforeRendering => {
|
slint::RenderingState::BeforeRendering => {
|
||||||
if let (Some(underlay), Some(app)) = (underlay.as_mut(), app_weak.upgrade()) {
|
if let (Some(underlay), Some(app)) = (underlay.as_mut(), app_weak.upgrade()) {
|
||||||
underlay.render(app.get_rotation_enabled());
|
underlay.render(app.get_rotation_enabled());
|
||||||
app.window().request_redraw();
|
app.window().request_redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sixtyfps::RenderingState::AfterRendering => {}
|
slint::RenderingState::AfterRendering => {}
|
||||||
sixtyfps::RenderingState::RenderingTeardown => {
|
slint::RenderingState::RenderingTeardown => {
|
||||||
drop(underlay.take());
|
drop(underlay.take());
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
match error {
|
match error {
|
||||||
sixtyfps::SetRenderingNotifierError::Unsupported => eprintln!("This example requires the use of the GL backend. Please run with the environment variable SIXTYFPS_BACKEND=GL set."),
|
slint::SetRenderingNotifierError::Unsupported => eprintln!("This example requires the use of the GL backend. Please run with the environment variable SLINT_BACKEND=GL set."),
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
}
|
}
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
// SPDX-License-Identifier: (GPL-3.0-only OR LicenseRef-SixtyFPS-commercial)
|
// SPDX-License-Identifier: (GPL-3.0-only OR LicenseRef-SixtyFPS-commercial)
|
||||||
|
|
||||||
import { ScrollView, Button, CheckBox, SpinBox, Slider, GroupBox, LineEdit, StandardListView,
|
import { ScrollView, Button, CheckBox, SpinBox, Slider, GroupBox, LineEdit, StandardListView,
|
||||||
ComboBox, HorizontalBox, VerticalBox, GridBox, TabWidget, TextEdit, AboutSixtyFPS } from "sixtyfps_widgets.60";
|
ComboBox, HorizontalBox, VerticalBox, GridBox, TabWidget, TextEdit, AboutSixtyFPS } from "std-widgets.slint";
|
||||||
|
|
||||||
App := Window {
|
App := Window {
|
||||||
preferred-width: 500px;
|
preferred-width: 500px;
|
||||||
preferred-height: 600px;
|
preferred-height: 600px;
|
||||||
title: "SixtyFPS OpenGL Underlay Example";
|
title: "Slnt OpenGL Underlay Example";
|
||||||
icon: @image-url("../../vscode_extension/extension-logo.png");
|
icon: @image-url("../../logo/slint-logo-square-light-128x128.png");
|
||||||
|
|
||||||
property <bool> rotation-enabled <=> apply-rotation.checked;
|
property <bool> rotation-enabled <=> apply-rotation.checked;
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ App := Window {
|
||||||
background: #ffffff92;
|
background: #ffffff92;
|
||||||
HorizontalBox {
|
HorizontalBox {
|
||||||
Text {
|
Text {
|
||||||
text: "This text is rendered using SixtyFPS. The animation below is rendered using OpenGL code.";
|
text: "This text is rendered using Slint. The animation below is rendered using OpenGL code.";
|
||||||
wrap: word-wrap;
|
wrap: word-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue