@@ -29,6 +29,27 @@ namespace splashkit_lib
2929
3030 static mu_Id focused_text_box = 0 ;
3131
32+ // Hold a stack in parallel to MicroUI's, which we use to
33+ // get incrementing IDs for elements which don't require labels
34+ static std::vector<mu_Id> id_stack;
35+
36+ mu_Id _id_stack_next ()
37+ {
38+ id_stack.back ()++;
39+
40+ return mu_get_id (ctx, &id_stack.back (), sizeof (id_stack.back ()));
41+ }
42+
43+ void _id_stack_push ()
44+ {
45+ id_stack.push_back (0 );
46+ }
47+
48+ void _id_stack_pop ()
49+ {
50+ id_stack.pop_back ();
51+ }
52+
3253 static bool element_changed = false ;
3354 static bool element_confirmed = false ;
3455
@@ -430,11 +451,14 @@ namespace splashkit_lib
430451 mu_get_current_container (ctx)->zindex = -1 ;
431452 int widths[] = {0 };
432453 sk_interface_set_layout (1 ,widths,0 );
454+
455+ _id_stack_push ();
433456 }
434457
435458 void sk_interface_end ()
436459 {
437460 // end root window
461+ _id_stack_pop ();
438462 mu_end_window (ctx);
439463
440464 mu_end (ctx);
@@ -469,41 +493,55 @@ namespace splashkit_lib
469493
470494 bool sk_interface_start_panel (const string& name, rectangle initial_rectangle)
471495 {
472- return mu_begin_window (ctx, name.c_str (), to_mu (initial_rectangle));
496+ bool open = mu_begin_window (ctx, name.c_str (), to_mu (initial_rectangle));
497+ if (open) _id_stack_push ();
498+
499+ return open;
473500 }
474501
475502 void sk_interface_end_panel ()
476503 {
504+ _id_stack_pop ();
477505 mu_end_window (ctx);
478506 }
479507
480508 bool sk_interface_start_popup (const string& name)
481509 {
482- return mu_begin_popup (ctx, name.c_str ());
510+ bool open = mu_begin_popup (ctx, name.c_str ());
511+ if (open) _id_stack_push ();
512+
513+ return open;
483514 }
484515
485516 void sk_interface_end_popup ()
486517 {
518+ _id_stack_pop ();
487519 mu_end_popup (ctx);
488520 }
489521
490522 void sk_interface_start_inset (const string& name)
491523 {
492524 mu_begin_panel (ctx, name.c_str ());
525+ _id_stack_push ();
493526 }
494527
495528 void sk_interface_end_inset ()
496529 {
530+ _id_stack_pop ();
497531 mu_end_panel (ctx);
498532 }
499533
500534 bool sk_interface_start_treenode (const string& name)
501535 {
502- return mu_begin_treenode (ctx, name.c_str ());
536+ bool open = mu_begin_treenode (ctx, name.c_str ());
537+ if (open) _id_stack_push ();
538+
539+ return open;
503540 }
504541
505542 void sk_interface_end_treenode ()
506543 {
544+ _id_stack_pop ();
507545 mu_end_treenode (ctx);
508546 }
509547
@@ -572,9 +610,10 @@ namespace splashkit_lib
572610 element_confirmed = result & MU_RES_SUBMIT;
573611 }
574612
575- void sk_interface_push_ptr_id ( void * ptr )
613+ void sk_interface_push_temp_id ( )
576614 {
577- mu_push_id (ctx, &ptr, sizeof (ptr));
615+ mu_Id id = _id_stack_next ();
616+ mu_push_id (ctx, &id, sizeof (id));
578617 }
579618
580619 void sk_interface_pop_id ()
@@ -605,7 +644,7 @@ namespace splashkit_lib
605644
606645 bool sk_interface_checkbox (const string& label_text, const bool & value)
607646 {
608- sk_interface_push_ptr_id (( void *)&value );
647+ sk_interface_push_temp_id ( );
609648
610649 int temp_value = value;
611650 update_elements_changed (mu_checkbox (ctx, label_text.c_str (), &temp_value));
@@ -616,7 +655,7 @@ namespace splashkit_lib
616655
617656 float sk_interface_slider (const float & value, float min_value, float max_value)
618657 {
619- sk_interface_push_ptr_id (( void *)&value );
658+ sk_interface_push_temp_id ( );
620659
621660 float temp_value = value;
622661 update_elements_changed (mu_slider (ctx, &temp_value, min_value, max_value));
@@ -627,7 +666,7 @@ namespace splashkit_lib
627666
628667 float sk_interface_number (const float & value, float step)
629668 {
630- sk_interface_push_ptr_id (( void *)&value );
669+ sk_interface_push_temp_id ( );
631670
632671 float temp_value = value;
633672 update_elements_changed (mu_number (ctx, &temp_value, step));
@@ -638,8 +677,7 @@ namespace splashkit_lib
638677
639678 std::string sk_interface_text_box (const std::string& value)
640679 {
641- const std::string* id = &value;
642- mu_Id m_id = mu_get_id (ctx, &id, sizeof (id));
680+ mu_Id m_id = _id_stack_next ();
643681 mu_Rect r = mu_layout_next (ctx);
644682
645683 // max 512 characters
0 commit comments