@@ -3,7 +3,7 @@ package demo
33import (
44 "fmt"
55
6- "github.com/inkyblackness/imgui-go/v3 "
6+ "github.com/inkyblackness/imgui-go/v4 "
77)
88
99type windowFlags struct {
@@ -18,8 +18,8 @@ type windowFlags struct {
1818 noBringToFront bool
1919}
2020
21- func (f windowFlags ) combined () int {
22- flags := 0
21+ func (f windowFlags ) combined () imgui. WindowFlags {
22+ flags := imgui . WindowFlagsNone
2323 if f .noTitlebar {
2424 flags |= imgui .WindowFlagsNoTitleBar
2525 }
@@ -58,6 +58,7 @@ var window = struct {
5858 layout layout
5959 popups popups
6060 columns columns
61+ tables tables
6162 misc misc
6263}{}
6364
@@ -153,6 +154,7 @@ func Show(keepOpen *bool) {
153154 window .layout .show ()
154155 window .popups .show ()
155156 window .columns .show ()
157+ window .tables .show ()
156158 window .misc .show ()
157159
158160 // End of ShowDemoWindow()
@@ -226,6 +228,102 @@ func (widgets *widgets) show() {
226228 }
227229}
228230
231+ type tables struct {
232+ background bool
233+ borders bool
234+ noInnerBorders bool
235+ header bool
236+ }
237+
238+ var demoTableHeader = []string {
239+ "Name" , "Favourite Food" , "Favourite Colour" ,
240+ }
241+
242+ var demoTable = [][]string {
243+ {"Eric" , "Bannana" , "Yellow" },
244+ {"Peter" , "Apple" , "Red" },
245+ {"Bruce" , "Liquorice" , "Black" },
246+ {"Aaron" , "Chocolates" , "Blue" },
247+ }
248+
249+ func (tables * tables ) show () {
250+ if ! imgui .CollapsingHeader ("Tables" ) {
251+ return
252+ }
253+
254+ if imgui .TreeNode ("Rows & Columns" ) {
255+ if imgui .BeginTable ("tableRowsAndColumns" , 3 ) {
256+ for row := 0 ; row < 4 ; row ++ {
257+ imgui .TableNextRow ()
258+ for column := 0 ; column < 3 ; column ++ {
259+ imgui .TableSetColumnIndex (column )
260+ imgui .Text (fmt .Sprintf ("Row %d Column %d" , row , column ))
261+ }
262+ }
263+ imgui .EndTable ()
264+ }
265+ imgui .TreePop ()
266+ }
267+
268+ if imgui .TreeNode ("Options" ) {
269+ // tables are useful for more than tabulated data. we use tables here
270+ // to facilitate layout of the option checkboxes
271+ if imgui .BeginTable ("tableOptions" , 2 ) {
272+ imgui .TableNextRow ()
273+ if imgui .TableNextColumn () {
274+ imgui .Checkbox ("Background" , & tables .background )
275+ }
276+ if imgui .TableNextColumn () {
277+ imgui .Checkbox ("Header Row" , & tables .header )
278+ }
279+
280+ imgui .TableNextRow ()
281+ if imgui .TableNextColumn () {
282+ imgui .Checkbox ("Borders" , & tables .borders )
283+ }
284+ if tables .borders {
285+ if imgui .TableNextColumn () {
286+ imgui .Checkbox ("No Inner Borders" , & tables .noInnerBorders )
287+ }
288+ }
289+
290+ imgui .EndTable ()
291+ }
292+
293+ // set flags according to the options that have been selected
294+ flgs := imgui .TableFlagsNone
295+ if tables .background {
296+ flgs |= imgui .TableFlagsRowBg
297+ }
298+ if tables .borders {
299+ flgs |= imgui .TableFlagsBorders
300+ if tables .noInnerBorders {
301+ flgs |= imgui .TableFlagsNoBordersInBody
302+ }
303+ }
304+
305+ if imgui .BeginTableV ("tableRowsAndColumns" , len (demoTableHeader ), flgs , imgui.Vec2 {}, 0.0 ) {
306+ if tables .header {
307+ imgui .TableHeadersRow ()
308+ for column := 0 ; column < len (demoTableHeader ); column ++ {
309+ imgui .TableSetColumnIndex (column )
310+ imgui .Text (demoTableHeader [column ])
311+ }
312+ }
313+
314+ for row := 0 ; row < len (demoTable ); row ++ {
315+ imgui .TableNextRow ()
316+ for column := 0 ; column < len (demoTableHeader ); column ++ {
317+ imgui .TableSetColumnIndex (column )
318+ imgui .Text (demoTable [row ][column ])
319+ }
320+ }
321+ imgui .EndTable ()
322+ }
323+ imgui .TreePop ()
324+ }
325+ }
326+
229327type layout struct {
230328}
231329
0 commit comments