I want to create an ImGui button, when I click on this button, I want it to redirect to a url, that is, to the browser, how can I do that? can you help me please?
Asked
Active
Viewed 760 times
1 Answers
2
Creating a button:
#[imgui(
button(size = "button_size",
label = "Click me!",
catch ="click"),
separator,
display(label = "Clicks"),
)]
count: i32, }
const fn button_size() -> (f32, f32){
(100.0, 20.0)
}
However, opening a webpage is a bit harder since it depends on the api of the os that you're using. Doing that for windows and mac would look like this:
void OsOpenInShell(const char* path) {
#ifdef _WIN32
// Note: executable path must use backslashes!
::ShellExecuteA(NULL, "open", path, NULL, NULL, SW_SHOWDEFAULT);
#else
#if __APPLE__ const char* open_executable = "open";
#else
const char* open_executable = "xdg
open";
#endif char command[256];
snprintf(command, 256, "%s \"%s\"",
open_executable, path);
system(command);
#endif
Then you could put the previous code inside this:
let events = ui.imgui_ext(&mut buttons);
if events.click {
*insert code*
}

vizznet
- 43
- 5
-
Does code for creating button and receiving click event need to be so complex? Won't `if (ImGui::Button("SampleText")) { /*execute url logic here*/ }` do enough job as example? Just asking coz I've never seen such complex implementation for button. – i like bananas Jul 24 '22 at 17:51
-
1no, it doesn't have to be that long but this is an example with some attributes – vizznet Jul 24 '22 at 18:25
-
2sure. I think it's good to omit not needed code when trying to provide an example. This can scare people looking for the answears. It would be nice if you edit your post since you fully answered the question but it is just unpleasant to read through. – i like bananas Jul 24 '22 at 18:34
-
1