Skip to content

Commit 42d4230

Browse files
committed
Minor Examples Update
1 parent 21bbdc5 commit 42d4230

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

examples/C++/call_js_from_cpp/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ int main() {
7676
<br>
7777
<h1 id="count">0</h1>
7878
<br>
79-
<button OnClick="my_function_count();">Manual Count</button>
79+
<button id="ManualBtn" OnClick="my_function_count();">Manual Count</button>
8080
<br>
81-
<button OnClick="AutoTest();">Auto Count (Every 10ms)</button>
81+
<button id="AutoBtn" OnClick="AutoTest();">Auto Count (Every 10ms)</button>
8282
<br>
83-
<button id="Exit">Exit</button>
83+
<button id="Exit" OnClick="this.disabled=true;">Exit</button>
8484
<script>
8585
let count = 0;
86+
let auto_running = false;
87+
8688
function GetCount() {
8789
return count;
8890
}
@@ -91,6 +93,11 @@ int main() {
9193
count = number;
9294
}
9395
function AutoTest(number) {
96+
if (auto_running) return;
97+
auto_running = true;
98+
document.getElementById('AutoBtn').disabled = true;
99+
document.getElementById('ManualBtn').disabled = true;
100+
94101
setInterval(function() {
95102
my_function_count();
96103
}, 10);
@@ -100,6 +107,9 @@ int main() {
100107
</html>
101108
)V0G0N";
102109

110+
// Set WebUI configuration to proceess UI events one at a time
111+
webui::set_config(ui_event_blocking, true);
112+
103113
// Create a window
104114
webui::window my_window;
105115

examples/C/call_js_from_c/main.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ int main() {
7575
" }"
7676
" h1 { text-shadow: -7px 10px 7px rgb(67 57 57 / 76%); }"
7777
" button:hover { background: #c9913d; }"
78+
" button:disabled {"
79+
" opacity: 0.6;"
80+
" cursor: not-allowed;"
81+
" box-shadow: none;"
82+
" filter: grayscale(30%);"
83+
" }"
84+
" button:disabled:hover { background: #3498db; }"
7885
" input:focus { outline: none; border-color: #3498db; }"
7986
" </style>"
8087
" </head>"
@@ -83,13 +90,14 @@ int main() {
8390
" <br>"
8491
" <h1 id=\"count\">0</h1>"
8592
" <br>"
86-
" <button OnClick=\"my_function_count();\">Manual Count</button>"
93+
" <button id=\"ManualBtn\" OnClick=\"my_function_count();\">Manual Count</button>"
8794
" <br>"
8895
" <button id=\"MyTest\" OnClick=\"AutoTest();\">Auto Count (Every 10ms)</button>"
8996
" <br>"
90-
" <button OnClick=\"my_function_exit();\">Exit</button>"
97+
" <button id=\"ExitBtn\" OnClick=\"this.disabled=true; my_function_exit();\">Exit</button>"
9198
" <script>"
9299
" let count = 0;"
100+
" let auto_running = false;"
93101
" function GetCount() {"
94102
" return count;"
95103
" }"
@@ -98,12 +106,19 @@ int main() {
98106
" count = number;"
99107
" }"
100108
" function AutoTest(number) {"
109+
" if (auto_running) return;"
110+
" auto_running = true;"
111+
" document.getElementById('MyTest').disabled = true;"
112+
" document.getElementById('ManualBtn').disabled = true;"
101113
" setInterval(function(){ my_function_count(); }, 10);"
102114
" }"
103115
" </script>"
104116
" </body>"
105117
"</html>";
106118

119+
// Set WebUI configuration to proceess UI events one at a time
120+
webui_set_config(ui_event_blocking, true);
121+
107122
// Create a window
108123
size_t my_window = webui_new_window();
109124

0 commit comments

Comments
 (0)