-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add rust build support for example
- Loading branch information
Showing
9 changed files
with
101 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use std::ffi::{c_void, CString}; | ||
use webf_sys::event::Event; | ||
use webf_sys::executing_context::ExecutingContextRustMethods; | ||
use webf_sys::{AddEventListenerOptions, element, EventTargetMethods, initialize_webf_api, RustValue}; | ||
use webf_sys::element::Element; | ||
use webf_sys::node::NodeMethods; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn init_webf_app(handle: RustValue<ExecutingContextRustMethods>) -> *mut c_void { | ||
let context = initialize_webf_api(handle); | ||
println!("Context created"); | ||
// let exception_state = context.create_exception_state(); | ||
// let document = context.document(); | ||
|
||
// let click_event = document.create_event("custom_click", &exception_state).unwrap(); | ||
// document.dispatch_event(&click_event, &exception_state); | ||
|
||
// let div_element = document.create_element("div", &exception_state).unwrap(); | ||
|
||
// let event_listener_options = AddEventListenerOptions { | ||
// passive: 0, | ||
// once: 0, | ||
// capture: 0, | ||
// }; | ||
|
||
// let event_handler = Box::new(|event: &Event| { | ||
// let context = event.context(); | ||
// let exception_state = context.create_exception_state(); | ||
// let document = context.document(); | ||
// let div = document.create_element("div", &exception_state).unwrap(); | ||
// let text_node = document.create_text_node("Created By Event Handler", &exception_state).unwrap(); | ||
// div.append_child(&text_node.as_node(), &exception_state).unwrap(); | ||
// document.body().append_child(&div.as_node(), &exception_state).unwrap(); | ||
// }); | ||
|
||
// div_element.add_event_listener("custom_click", event_handler.clone(), &event_listener_options, &exception_state).unwrap(); | ||
|
||
// let real_click_handler = Box::new(move |event: &Event| { | ||
// let context = event.context(); | ||
// let exception_state = context.create_exception_state(); | ||
// let document = context.document(); | ||
// let custom_click_event = document.create_event("custom_click", &exception_state); | ||
|
||
// match custom_click_event { | ||
// Ok(custom_click_event) => { | ||
// let event_target = event.target(); | ||
// let element: Element = event_target.as_element().unwrap(); | ||
// let _ = element.dispatch_event(&custom_click_event, &exception_state); | ||
// }, | ||
// Err(err) => { | ||
// println!("{err}"); | ||
// } | ||
// } | ||
// }); | ||
|
||
// div_element.add_event_listener("click", real_click_handler, &event_listener_options, &exception_state).unwrap(); | ||
|
||
// let text_node = document.create_text_node("From Rust", &exception_state).unwrap(); | ||
|
||
// div_element.append_child(&text_node.as_node(), &exception_state).expect("append Node Failed"); | ||
|
||
// document.body().append_child(&div_element.as_node(), &exception_state).unwrap(); | ||
|
||
// let event_cleaner_element = document.create_element("button", &exception_state).unwrap(); | ||
|
||
// let event_cleaner_text_node = document.create_text_node("Remove Event", &exception_state).unwrap(); | ||
|
||
// event_cleaner_element.append_child(&event_cleaner_text_node.as_node(), &exception_state).unwrap(); | ||
|
||
// let event_cleaner_handler = Box::new(move |event: &Event| { | ||
// let context = event.context(); | ||
// let exception_state = context.create_exception_state(); | ||
|
||
// let _ = div_element.remove_event_listener("custom_click", event_handler.clone(), &exception_state); | ||
// }); | ||
|
||
// event_cleaner_element.add_event_listener("click", event_cleaner_handler, &event_listener_options, &exception_state).unwrap(); | ||
|
||
// document.body().append_child(&event_cleaner_element.as_node(), &exception_state).unwrap(); | ||
|
||
std::ptr::null_mut() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
# The Flutter tooling requires that developers have a version of Visual Studio | ||
# installed that includes CMake 3.14 or later. You should not increase this | ||
# version, as doing so will cause the plugin to fail to compile for some | ||
# customers of the plugin. | ||
cmake_minimum_required(VERSION 3.14) | ||
# The Flutter tooling requires that developers have CMake 3.10 or later | ||
# installed. You should not increase this version, as doing so will cause | ||
# the plugin to fail to compile for some customers of the plugin. | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
# Project-level configuration. | ||
set(PROJECT_NAME "example_app") | ||
project(${PROJECT_NAME} LANGUAGES CXX) | ||
|
||
# Invoke the build for native code shared with the other target platforms. | ||
# This can be changed to accommodate different builds. | ||
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../src" "${CMAKE_CURRENT_BINARY_DIR}/shared") | ||
|
||
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
# Replace add_subdirectory that references old C++ code with Cargokit: | ||
include("../cargokit/cmake/cargokit.cmake") | ||
apply_cargokit(${PROJECT_NAME} "../rust" example_app "") | ||
|
||
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
|
||
# List of absolute paths to libraries that should be bundled with the plugin. | ||
# This list could contain prebuilt libraries, or libraries created by an | ||
# external build triggered from this build file. | ||
set(rust_builder_bundled_libraries | ||
set(example_app_bundled_libraries | ||
"${${PROJECT_NAME}_cargokit_lib}" | ||
# Defined in ../src/CMakeLists.txt. | ||
# This can be changed to accommodate different builds. | ||
$<TARGET_FILE:example_app> | ||
PARENT_SCOPE | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters