diff --git a/preview/CMakeLists.txt b/preview/CMakeLists.txt index a676173..1150c51 100644 --- a/preview/CMakeLists.txt +++ b/preview/CMakeLists.txt @@ -1,15 +1,9 @@ +add_executable(preview preview.cpp) +target_link_libraries(preview WebviewCandidateWindow) +target_include_directories(preview PRIVATE "${PROJECT_SOURCE_DIR}/include") + if(APPLE) - add_executable(preview - MACOSX_BUNDLE - preview.mm - ) - target_link_libraries(preview WebviewCandidateWindow "-framework WebKit" "-framework Cocoa") - target_compile_options(preview PRIVATE "-Wno-auto-var-id") -elseif(LINUX) - add_executable(preview preview.cpp) - target_link_libraries(preview WebviewCandidateWindow) + target_compile_options(preview PRIVATE "-Wno-auto-var-id" "-ObjC++") endif() -target_include_directories(preview PRIVATE "${PROJECT_SOURCE_DIR}/include") - add_dependencies(preview GenerateHTML) diff --git a/preview/preview.cpp b/preview/preview.cpp index 2025e6a..a959a8e 100644 --- a/preview/preview.cpp +++ b/preview/preview.cpp @@ -9,39 +9,42 @@ #include #include +std::unique_ptr candidateWindow; + +void doPreview() { + candidateWindow = std::make_unique(); + candidateWindow->set_select_callback( + [](int index) { std::cout << "selected " << index << std::endl; }); + candidateWindow->set_page_callback([](bool next) { + std::cout << (next ? "next" : "prev") << " page" << std::endl; + }); + candidateWindow->set_action_callback([](int index, int id) { + std::cout << "action " << id << " on " << index << std::endl; + }); + candidateWindow->set_init_callback([=]() { + std::cout << "Window loaded" << std::endl; + candidateWindow->set_layout(candidate_window::layout_t::vertical); + candidateWindow->set_paging_buttons(true, false, true); + candidateWindow->set_candidates( + {{"

防注入

", "1", "注释", {{0, "

防注入

"}}}, + {"候选词", "2", "", {{1, "删词"}, {2, "置顶"}}}, + {"制\t表\t符\n多 空 格", "2", ""}}, + 0, candidate_window::scroll_state_t::none, false, false); + candidateWindow->set_theme(candidate_window::theme_t::light); + candidateWindow->show(100, 200); + }); +} + int main(int argc, char *argv[]) { #ifdef __APPLE__ @autoreleasepool { NSApplication *application = [NSApplication sharedApplication]; -#endif - std::unique_ptr candidateWindow = - std::make_unique(); - candidateWindow->set_select_callback( - [](int index) { std::cout << "selected " << index << std::endl; }); - candidateWindow->set_init_callback( - []() { std::cout << "Window loaded" << std::endl; }); - candidateWindow->set_page_callback([](bool next) { - std::cout << (next ? "next" : "prev") << " page" << std::endl; - }); - candidateWindow->set_action_callback([](int index, int id) { - std::cout << "action " << id << " on " << index << std::endl; - }); - auto t = std::thread([&] { - std::this_thread::sleep_for(std::chrono::seconds(1)); - candidateWindow->set_layout(candidate_window::layout_t::vertical); - candidateWindow->set_paging_buttons(true, false, true); - candidateWindow->set_candidates( - {{"

防注入

", "1", "注释", {{0, "

防注入

"}}}, - {"候选词", "2", "", {{1, "删词"}, {2, "置顶"}}}, - {"制\t表\t符\n多 空 格", "2", ""}}, - 0, candidate_window::scroll_state_t::none, false, false); - candidateWindow->set_theme(candidate_window::theme_t::light); - candidateWindow->show(100, 200); - }); -#ifdef __APPLE__ + doPreview(); [application run]; } #elif defined(__linux__) + gtk_init(&argc, &argv); + doPreview() gtk_main(); #endif return 0; diff --git a/preview/preview.mm b/preview/preview.mm deleted file mode 120000 index e902c64..0000000 --- a/preview/preview.mm +++ /dev/null @@ -1 +0,0 @@ -preview.cpp \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8d7321f..0734b68 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,7 +14,7 @@ add_library(WebviewCandidateWindow ${SOURCES}) target_include_directories(WebviewCandidateWindow PUBLIC "${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/webview") if(APPLE) - target_link_libraries(WebviewCandidateWindow "-framework WebKit" PkgConfig::NlohmannJson) + target_link_libraries(WebviewCandidateWindow PUBLIC "-framework Cocoa" "-framework WebKit" PkgConfig::NlohmannJson) target_compile_options(WebviewCandidateWindow PRIVATE "-Wno-auto-var-id") elseif(LINUX) target_link_libraries(WebviewCandidateWindow PkgConfig::webkit2gtk PkgConfig::NlohmannJson)