7#include <cyd_fabric_modules/headers/macros/async_events.h>
8#include <tracy/Tracy.hpp>
9#define SDL_MAIN_HANDLED
17import fabric.profiling;
25export namespace cydui {
34export namespace cydui {
35 class CWindow:
public fabric::async::async_bus_t {
46 using sptr = std::shared_ptr<CWindow>;
50 template <
typename... Args>
52 ZoneScopedN(
"Application:run_async");
53 return get_executor()->schedule(
54 [=](Args... argss) -> fabric::task<
decltype(fun(std::forward<Args>(argss)...))> {
55 ZoneScopedN(
"Application:run_async:()");
56 co_return fun(std::forward<Args>(argss)...);
58 std::forward<Args>(args)...
62 template <
typename... Args>
63 auto run(
auto&& fun, Args&&... args) {
64 ZoneScopedN(
"Application:run");
65 return run_async(fun, std::forward<Args>(args)...).get();
68 template <
typename... Args>
70 ZoneScopedN(
"Application:run_async");
71 return get_executor()->schedule(fun, std::forward<Args>(args)...);
74 template <
typename... Args>
75 auto schedule(fabric::tasks::time_point tp,
auto&& fun, Args&&... args) {
76 ZoneScopedN(
"Application:run_async");
77 return get_executor()->schedule(tp, fun, std::forward<Args>(args)...);
80 template <
typename... Args>
81 auto schedule(fabric::tasks::duration duration,
auto&& fun, Args&&... args) {
82 ZoneScopedN(
"Application:run_async");
83 return get_executor()->schedule(duration, fun, std::forward<Args>(args)...);
111 styles_.push_back(
style);
122 void configure_layout_style();
126 ZoneScopedN(
"CWindow:builder:show");
127 configure_layout_style();
128 auto ptr = std::shared_ptr<CWindow>(
new CWindow(layout_, title_, x_, y_, width_, height_));
129 std::string t = title_;
131 tracy::SetThreadNameWithHint(std::format(
"window[{}]", t).c_str(), 1);
133 ptr->schedule([](
Layout* lyt,
sptr win) -> fabric::task<> {
135 LOG::print {INFO}(
"Layout bound to window");
142 Layout* layout_ =
nullptr;
143 int x_ = SDL_WINDOWPOS_UNDEFINED;
144 int y_ = SDL_WINDOWPOS_UNDEFINED;
147 std::string title_ =
"CYD-UI";
148 std::vector<std::string> styles_ = {};
149 std::vector<std::filesystem::path> stylesheets_ = {};
156 template<
typename Component>
157 static builder_t
make(
typename Component::props_t props = { });
159 graphics::window_t*
native();
188 ): win_ref(std::make_unique<graphics::window_t>(this, nullptr, width, height)),
190 using namespace std::chrono_literals;
191 ZoneScopedN(
"CWindow{}");
193 get_executor()->get_spawn_context()->set_resource<AnimationSystem>(std::make_shared<AnimationSystem>(get_executor()));
197 ZoneScopedN(
"CWindow{}:init");
198 SDL_CreateWindowAndRenderer(
202 SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL,
203 &self->win_ref->window,
204 &self->win_ref->renderer
206 SDL_SetWindowPosition(self->win_ref->window, x, y);
211 self->compositor.set_render_target(self->win_ref.get(), &self->profiling_ctx);
212 LOG::print {INFO}(
"SDL3 Window initialized.");
226 emit<fabric::async::StopBusEvent>();
228 SDL_DestroyWindow(
win_ref->window);
229 SDL_DestroyRenderer(
win_ref->renderer);
241 SDL_GetWindowPosition(self->
win_ref->window, x, y);
249 SDL_GetCurrentRenderOutputSize(self->
win_ref->renderer, w, h);
static auto run(auto &&fun, Args &&... args)
static void register_window(std::size_t id, fabric::async::async_bus_t *window)
static void unregister_window(std::size_t id)
std::shared_ptr< CWindow > sptr
static builder_t make(Layout *layout)
auto schedule(fabric::tasks::duration duration, auto &&fun, Args &&... args)
graphics::window_t * native()
std::unique_ptr< graphics::window_t > win_ref
auto schedule(fabric::tasks::time_point tp, auto &&fun, Args &&... args)
prof::context_t profiling_ctx
std::pair< int, int > get_size()
compositing::LayoutCompositor compositor
auto run(auto &&fun, Args &&... args)
auto run_async(auto &&fun, Args &&... args)
std::pair< int, int > get_position()
auto schedule(auto &&fun, Args &&... args)
void bind_layout(Layout *layout, const CWindow::sptr &window)
builder_t & position(int x, int y)
builder_t & size(int width, int height)
builder_t(Layout *layout)
builder_t(const builder_t &)=delete
builder_t & stylesheet(const std::filesystem::path &stylesheet)
builder_t & title(const std::string &title)
builder_t & style(const std::string &style)