Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align C++ event APIs with C event APIs #118

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions nuklear_console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,16 @@ void nk_console_event_handler_destroy(nk_console*, void* user_data) {
}

template <typename T>
void nk_console_set_event_handler(nk_console* widget, nk_console_event_type type, T&& t) {
void nk_console_add_event_handler(nk_console* widget, nk_console_event_type type, T&& t) {
void* memory = nk_console_malloc(nk_handle_id(0), NULL, sizeof(T));
T* user_data = new (memory) T(std::move(t));
nk_console_add_event_handler(widget, type, &nk_console_event_handler_call<T>, user_data, &nk_console_event_handler_destroy<T>);
}

template <typename T>
void nk_console_set_onchange_handler(nk_console* widget, T&& t) {
nk_console_set_event_handler(widget, NK_CONSOLE_EVENT_CHANGED, std::move(t));
}

template <typename T>
void nk_console_button_set_onclick_handler(nk_console* button, T&& t) {
nk_console_set_event_handler(button, NK_CONSOLE_EVENT_CLICKED, std::move(t));
}

template <typename T>
nk_console* nk_console_button_onclick_handler(nk_console* parent, const char* text, T&& t) {
nk_console* button = nk_console_button(parent, text);
nk_console_add_event(button, NK_CONSOLE_EVENT_CLICKED, std::move(t));
nk_console_add_event_handler(button, NK_CONSOLE_EVENT_CLICKED, std::move(t));
return button;
}

Expand Down