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

allow updates to show window #103

Merged
merged 4 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
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
38 changes: 27 additions & 11 deletions src/imgui_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ struct WindowControl
int min;
int def;
int max;
int step;
void* user;
void(*onChange)(void* user, int value);
} sliderint;
Expand All @@ -120,7 +119,6 @@ struct WindowControl
float min;
float def;
float max;
float step;
void* user;
void(*onChange)(void* user, float value);
} sliderfloat;
Expand Down Expand Up @@ -222,7 +220,6 @@ void mcpelauncher_show_window(const char *title, int isModal, void *user, void (
break;
case 1:
new(&subentries[i].data.sliderint.label) std::string(controls[i].data.sliderint.label ? controls[i].data.sliderint.label : "");
subentries[i].data.sliderint.step = controls[i].data.sliderint.step;
subentries[i].data.sliderint.def = controls[i].data.sliderint.def;
subentries[i].data.sliderint.max = controls[i].data.sliderint.max;
subentries[i].data.sliderint.min = controls[i].data.sliderint.min;
Expand All @@ -231,7 +228,6 @@ void mcpelauncher_show_window(const char *title, int isModal, void *user, void (
break;
case 2:
new(&subentries[i].data.sliderfloat.label) std::string(controls[i].data.sliderfloat.label ? controls[i].data.sliderfloat.label : "");
subentries[i].data.sliderfloat.step = controls[i].data.sliderfloat.step;
subentries[i].data.sliderfloat.def = controls[i].data.sliderfloat.def;
subentries[i].data.sliderfloat.max = controls[i].data.sliderfloat.max;
subentries[i].data.sliderfloat.min = controls[i].data.sliderfloat.min;
Expand All @@ -254,13 +250,33 @@ void mcpelauncher_show_window(const char *title, int isModal, void *user, void (
break;
}
}
activeWindows.push_back(std::make_shared<ActiveWindow>(ActiveWindow{
.title = title ? title : "Untitled",
.isModal = !!isModal,
.user = user,
.onClose = onClose,
.controls = std::move(subentries),
}));

if(auto activeWindow = std::find_if(activeWindows.begin(), activeWindows.end(), [title](auto&& wnd) {
return wnd->title == (title ? title : "Untitled");
}); activeWindow != activeWindows.end()) {
(*activeWindow)->isModal = !!isModal;
(*activeWindow)->user = user;
(*activeWindow)->onClose = onClose;
(*activeWindow)->controls = std::move(subentries);
} else {
activeWindows.push_back(std::make_shared<ActiveWindow>(ActiveWindow{
.title = title ? title : "Untitled",
.isModal = !!isModal,
.user = user,
.onClose = onClose,
.controls = std::move(subentries),
}));
}
activeWindowsLock.unlock();
}

void mcpelauncher_close_window(const char *title) {
activeWindowsLock.lock();
if(auto activeWindow = std::find_if(activeWindows.begin(), activeWindows.end(), [title](auto&& wnd) {
return wnd->title == (title ? title : "Untitled");
}); activeWindow != activeWindows.end()) {
activeWindows.erase(activeWindow);
}
activeWindowsLock.unlock();
}

Expand Down
4 changes: 2 additions & 2 deletions src/imgui_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ struct control
int min;
int def;
int max;
int step;
void* user;
void(*onChange)(void* user, int value);
} sliderint;
Expand All @@ -38,7 +37,6 @@ struct control
float min;
float def;
float max;
float step;
void* user;
void(*onChange)(void* user, float value);
} sliderfloat;
Expand All @@ -56,3 +54,5 @@ struct control
} data;
};
void mcpelauncher_show_window(const char* title, int isModal, void* user, void(*onClose)(void* user), int count, control* controls);

void mcpelauncher_close_window(const char *title);
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ Hardware : Qualcomm Technologies, Inc MSM8998
linker::load_library("libmcpelauncher_menu.so", {
{ "mcpelauncher_addmenu", (void*)mcpelauncher_addmenu },
{ "mcpelauncher_show_window", (void*)mcpelauncher_show_window },
{ "mcpelauncher_close_window", (void*)mcpelauncher_close_window },
});

ModLoader modLoader;
Expand Down
Loading