@ -2781,17 +2781,17 @@ struct ExampleSelection
{
{
// Data
// Data
ImGuiStorage Storage ; // Selection set
ImGuiStorage Storage ; // Selection set
int Size ; // Number of selected items (== number of 1 in the Storage, maintained by this class). // FIXME-MULTISELECT: Imply more difficult to track with intrusive selection schemes?
int Size ; // Number of selected items (== number of 1 in the Storage, maintained by this class).
bool QueueDeletion ; // Request deleting selected items
bool QueueDeletion ; // Request deleting selected items
// Functions
// Functions
ExampleSelection ( ) { Clear ( ) ; }
ExampleSelection ( ) { Clear ( ) ; }
void Clear ( ) { Storage . Clear ( ) ; Size = 0 ; QueueDeletion = false ; }
void Clear ( ) { Storage . Clear ( ) ; Size = 0 ; QueueDeletion = false ; }
void Swap ( ExampleSelection & rhs ) { Storage . Data . swap ( rhs . Storage . Data ) ; }
void Swap ( ExampleSelection & rhs ) { Storage . Data . swap ( rhs . Storage . Data ) ; }
bool Contains ( int n ) const { return Storage . GetInt ( ( ImGuiID ) n , 0 ) ! = 0 ; }
bool Contains ( ImGuiID key ) const { return Storage . GetInt ( key , 0 ) ! = 0 ; }
void AddItem ( int n ) { int * p_int = Storage . GetIntRef ( ( ImGuiID ) n , 0 ) ; if ( * p_int ! = 0 ) return ; * p_int = 1 ; Size + + ; }
void AddItem ( ImGuiID key ) { int * p_int = Storage . GetIntRef ( key , 0 ) ; if ( * p_int ! = 0 ) return ; * p_int = 1 ; Size + + ; }
void RemoveItem ( int n ) { int * p_int = Storage . GetIntRef ( ( ImGuiID ) n , 0 ) ; if ( * p_int = = 0 ) return ; * p_int = 0 ; Size - - ; }
void RemoveItem ( ImGuiID key ) { int * p_int = Storage . GetIntRef ( key , 0 ) ; if ( * p_int = = 0 ) return ; * p_int = 0 ; Size - - ; }
void UpdateItem ( int n , bool v ) { if ( v ) AddItem ( n ) ; else RemoveItem ( n ) ; }
void UpdateItem ( ImGuiID key , bool v ) { if ( v ) AddItem ( key ) ; else RemoveItem ( key ) ; }
int GetSize ( ) const { return Size ; }
int GetSize ( ) const { return Size ; }
void DebugTooltip ( ) { if ( ImGui : : BeginTooltip ( ) ) { for ( auto & pair : Storage . Data ) if ( pair . val_i ) ImGui : : Text ( " 0x%03X (%d) " , pair . key , pair . key ) ; ImGui : : EndTooltip ( ) ; } }
void DebugTooltip ( ) { if ( ImGui : : BeginTooltip ( ) ) { for ( auto & pair : Storage . Data ) if ( pair . val_i ) ImGui : : Text ( " 0x%03X (%d) " , pair . key , pair . key ) ; ImGui : : EndTooltip ( ) ; } }
@ -2965,7 +2965,7 @@ static void ShowDemoWindowMultiSelect()
{
{
char label [ 64 ] ;
char label [ 64 ] ;
sprintf ( label , " Object %05d: %s " , n , random_names [ n % IM_ARRAYSIZE ( random_names ) ] ) ;
sprintf ( label , " Object %05d: %s " , n , random_names [ n % IM_ARRAYSIZE ( random_names ) ] ) ;
bool item_is_selected = selection . Contains ( n ) ;
bool item_is_selected = selection . Contains ( ( ImGuiID ) n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : Selectable ( label , item_is_selected ) ;
ImGui : : Selectable ( label , item_is_selected ) ;
}
}
@ -3006,7 +3006,7 @@ static void ShowDemoWindowMultiSelect()
{
{
char label [ 64 ] ;
char label [ 64 ] ;
sprintf ( label , " Object %05d: %s " , n , random_names [ n % IM_ARRAYSIZE ( random_names ) ] ) ;
sprintf ( label , " Object %05d: %s " , n , random_names [ n % IM_ARRAYSIZE ( random_names ) ] ) ;
bool item_is_selected = selection . Contains ( n ) ;
bool item_is_selected = selection . Contains ( ( ImGuiID ) n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : Selectable ( label , item_is_selected ) ;
ImGui : : Selectable ( label , item_is_selected ) ;
}
}
@ -3051,7 +3051,7 @@ static void ShowDemoWindowMultiSelect()
items . push_back ( items_next_id + + ) ;
items . push_back ( items_next_id + + ) ;
if ( ImGui : : SmallButton ( " Add 20 items " ) ) { for ( int n = 0 ; n < 20 ; n + + ) { items . push_back ( items_next_id + + ) ; } }
if ( ImGui : : SmallButton ( " Add 20 items " ) ) { for ( int n = 0 ; n < 20 ; n + + ) { items . push_back ( items_next_id + + ) ; } }
ImGui : : SameLine ( ) ;
ImGui : : SameLine ( ) ;
if ( ImGui : : SmallButton ( " Remove 20 items " ) ) { for ( int n = IM_MIN ( 20 , items . Size ) ; n > 0 ; n - - ) { selection . RemoveItem ( items . Size - 1 ) ; items . pop_back ( ) ; } } // This is to test
if ( ImGui : : SmallButton ( " Remove 20 items " ) ) { for ( int n = IM_MIN ( 20 , items . Size ) ; n > 0 ; n - - ) { selection . RemoveItem ( ( ImGuiID ) ( items . Size - 1 ) ) ; items . pop_back ( ) ; } } // This is to test
// (1) Extra to support deletion: Submit scrolling range to avoid glitches on deletion
// (1) Extra to support deletion: Submit scrolling range to avoid glitches on deletion
const float items_height = ImGui : : GetTextLineHeightWithSpacing ( ) ;
const float items_height = ImGui : : GetTextLineHeightWithSpacing ( ) ;
@ -3077,7 +3077,7 @@ static void ShowDemoWindowMultiSelect()
char label [ 64 ] ;
char label [ 64 ] ;
sprintf ( label , " Object %05d: %s " , item_id , random_names [ item_id % IM_ARRAYSIZE ( random_names ) ] ) ;
sprintf ( label , " Object %05d: %s " , item_id , random_names [ item_id % IM_ARRAYSIZE ( random_names ) ] ) ;
bool item_is_selected = selection . Contains ( n ) ;
bool item_is_selected = selection . Contains ( ( ImGuiID ) n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : Selectable ( label , item_is_selected ) ;
ImGui : : Selectable ( label , item_is_selected ) ;
if ( next_focus_item_idx = = n )
if ( next_focus_item_idx = = n )
@ -3119,7 +3119,7 @@ static void ShowDemoWindowMultiSelect()
{
{
char label [ 64 ] ;
char label [ 64 ] ;
sprintf ( label , " Object %05d: %s " , n , random_names [ n % IM_ARRAYSIZE ( random_names ) ] ) ;
sprintf ( label , " Object %05d: %s " , n , random_names [ n % IM_ARRAYSIZE ( random_names ) ] ) ;
bool item_is_selected = selection - > Contains ( n ) ;
bool item_is_selected = selection - > Contains ( ( ImGuiID ) n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : Selectable ( label , item_is_selected ) ;
ImGui : : Selectable ( label , item_is_selected ) ;
}
}
@ -3241,7 +3241,7 @@ static void ShowDemoWindowMultiSelect()
ImGui : : SameLine ( ) ;
ImGui : : SameLine ( ) ;
}
}
bool item_is_selected = selection . Contains ( n ) ;
bool item_is_selected = selection . Contains ( ( ImGuiID ) n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
if ( widget_type = = WidgetType_Selectable )
if ( widget_type = = WidgetType_Selectable )
{
{