#include #include #include #include #include #include #include #include #include "ui_def.hpp" #include "util.hpp" using namespace ultralight; using ultralight::JSObject; using ultralight::JSArgs; using ultralight::JSFunction; class FiltApp : public WindowListener, public LoadListener { RefPtr app_; RefPtr window_; RefPtr overlay_; public: FiltApp() { ultralight::DefaultFontLoader(); /// /// Create our main App instance. /// app_ = App::Create(); /// /// Create our Window with the Resizable window flag. /// window_ = Window::Create(app_->main_monitor(), 1240, 768, false, kWindowFlags_Titled | kWindowFlags_Resizable ); /// /// Set our window title. /// window_->SetTitle("Filt"); /// /// Bind our App's main window. /// /// @note This MUST be done before creating any overlays or calling App::Run /// app_->set_window(*window_.get()); /// /// Create our Overlay, use the same dimensions as our Window. /// overlay_ = Overlay::Create(*window_.get(), window_->width(), window_->height(), 0, 0); /// /// Load a string of HTML into our overlay's View /// overlay_->view()->LoadHTML(String((const char*)ui_string, ui_string_len)); /// /// Register our MyApp instance as a WindowListener so we can handle the /// Window's OnResize event below. /// window_->set_listener(this); overlay_->view()->set_load_listener(this); /// /// Export global functions to js /// // Set the context for all subsequent JS* calls SetJSContext(overlay_->view()->js_context()); JSObject global = JSGlobalObject(); /// export error loggin function global["FiltLogError"] = BindJSCallback(&FiltApp::logError); } virtual ~FiltApp() {} void logError(const JSObject& obj, const JSArgs& args) { ultralight::String argString = JSArgsToString(args); std::cout << "here\n"; spdlog::error("[js_log] {}", argString.utf8().data()); } void OnDOMReady(ultralight::View* caller) override { } /// /// Inherited from WindowListener, not used. /// virtual void OnClose() override {} /// /// Inherited from WindowListener, called when the Window is resized. /// virtual void OnResize(uint32_t width, uint32_t height) override { /// /// Resize our Overlay to match the new Window dimensions. /// spdlog::info("{}x{}",width,height); overlay_->Resize(width, height); } void Run() { app_->Run(); } }; int main() { FiltApp app; app.Run(); return 0; }