@@ -26,6 +26,8 @@ class Program
2626 private static bool _showAnotherWindow = false ;
2727 private static bool _showMemoryEditor = false ;
2828 private static byte [ ] _memoryEditorData ;
29+ private static uint s_tab_bar_flags = ( uint ) ImGuiTabBarFlags . Reorderable ;
30+ static bool [ ] s_opened = { true , true , true , true } ; // Persistent user state
2931
3032 static void SetThing ( out float i , float val ) { i = val ; }
3133
@@ -120,6 +122,75 @@ private static unsafe void SubmitUI()
120122 ImGui . ShowDemoWindow ( ref _showDemoWindow ) ;
121123 }
122124
125+ if ( ImGui . TreeNode ( "Tabs" ) )
126+ {
127+ if ( ImGui . TreeNode ( "Basic" ) )
128+ {
129+ ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags . None ;
130+ if ( ImGui . BeginTabBar ( "MyTabBar" , tab_bar_flags ) )
131+ {
132+ if ( ImGui . BeginTabItem ( "Avocado" ) )
133+ {
134+ ImGui . Text ( "This is the Avocado tab!\n blah blah blah blah blah" ) ;
135+ ImGui . EndTabItem ( ) ;
136+ }
137+ if ( ImGui . BeginTabItem ( "Broccoli" ) )
138+ {
139+ ImGui . Text ( "This is the Broccoli tab!\n blah blah blah blah blah" ) ;
140+ ImGui . EndTabItem ( ) ;
141+ }
142+ if ( ImGui . BeginTabItem ( "Cucumber" ) )
143+ {
144+ ImGui . Text ( "This is the Cucumber tab!\n blah blah blah blah blah" ) ;
145+ ImGui . EndTabItem ( ) ;
146+ }
147+ ImGui . EndTabBar ( ) ;
148+ }
149+ ImGui . Separator ( ) ;
150+ ImGui . TreePop ( ) ;
151+ }
152+
153+ if ( ImGui . TreeNode ( "Advanced & Close Button" ) )
154+ {
155+ // Expose a couple of the available flags. In most cases you may just call BeginTabBar() with no flags (0).
156+ ImGui . CheckboxFlags ( "ImGuiTabBarFlags_Reorderable" , ref s_tab_bar_flags , ( uint ) ImGuiTabBarFlags . Reorderable ) ;
157+ ImGui . CheckboxFlags ( "ImGuiTabBarFlags_AutoSelectNewTabs" , ref s_tab_bar_flags , ( uint ) ImGuiTabBarFlags . AutoSelectNewTabs ) ;
158+ ImGui . CheckboxFlags ( "ImGuiTabBarFlags_NoCloseWithMiddleMouseButton" , ref s_tab_bar_flags , ( uint ) ImGuiTabBarFlags . NoCloseWithMiddleMouseButton ) ;
159+ if ( ( s_tab_bar_flags & ( uint ) ImGuiTabBarFlags . FittingPolicyMask ) == 0 )
160+ s_tab_bar_flags |= ( uint ) ImGuiTabBarFlags . FittingPolicyDefault ;
161+ if ( ImGui . CheckboxFlags ( "ImGuiTabBarFlags_FittingPolicyResizeDown" , ref s_tab_bar_flags , ( uint ) ImGuiTabBarFlags . FittingPolicyResizeDown ) )
162+ s_tab_bar_flags &= ~ ( ( uint ) ImGuiTabBarFlags . FittingPolicyMask ^ ( uint ) ImGuiTabBarFlags . FittingPolicyResizeDown ) ;
163+ if ( ImGui . CheckboxFlags ( "ImGuiTabBarFlags_FittingPolicyScroll" , ref s_tab_bar_flags , ( uint ) ImGuiTabBarFlags . FittingPolicyScroll ) )
164+ s_tab_bar_flags &= ~ ( ( uint ) ImGuiTabBarFlags . FittingPolicyMask ^ ( uint ) ImGuiTabBarFlags . FittingPolicyScroll ) ;
165+
166+ // Tab Bar
167+ string [ ] names = { "Artichoke" , "Beetroot" , "Celery" , "Daikon" } ;
168+
169+ for ( int n = 0 ; n < s_opened . Length ; n ++ )
170+ {
171+ if ( n > 0 ) { ImGui . SameLine ( ) ; }
172+ ImGui . Checkbox ( names [ n ] , ref s_opened [ n ] ) ;
173+ }
174+
175+ // Passing a bool* to BeginTabItem() is similar to passing one to Begin(): the underlying bool will be set to false when the tab is closed.
176+ if ( ImGui . BeginTabBar ( "MyTabBar" , ( ImGuiTabBarFlags ) s_tab_bar_flags ) )
177+ {
178+ for ( int n = 0 ; n < s_opened . Length ; n ++ )
179+ if ( s_opened [ n ] && ImGui . BeginTabItem ( names [ n ] , ref s_opened [ n ] ) )
180+ {
181+ ImGui . Text ( $ "This is the { names [ n ] } tab!") ;
182+ if ( ( n & 1 ) != 0 )
183+ ImGui . Text ( "I am an odd tab." ) ;
184+ ImGui . EndTabItem ( ) ;
185+ }
186+ ImGui . EndTabBar ( ) ;
187+ }
188+ ImGui . Separator ( ) ;
189+ ImGui . TreePop ( ) ;
190+ }
191+ ImGui . TreePop ( ) ;
192+ }
193+
123194 ImGuiIOPtr io = ImGui . GetIO ( ) ;
124195 SetThing ( out io . DeltaTime , 2f ) ;
125196
0 commit comments