{"id":3905,"date":"2021-12-19T09:08:37","date_gmt":"2021-12-19T09:08:37","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=3905"},"modified":"2021-12-19T09:08:39","modified_gmt":"2021-12-19T09:08:39","slug":"5b-3-wxwidgets-gridsizer","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2021\/12\/19\/5b-3-wxwidgets-gridsizer\/","title":{"rendered":"5b-3. wxWidgets &#8211; GridSizer"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>wxGridSizer lets you place controls in the form of a grid using rows and columns. All the cells in the grid will have the same size. The constructor method is in the form of wxGridSizer(rows, columns, vertical gap, horizontal gap)<\/p>\n\n\n\n<p>In the sample code below, we will create a mini spreadsheet layout with buttons for the row and column headings and text controls for the actual cells. When you resize the window, the cells will stretch to fill the empty space.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>wxgridsizer.h<\/strong><\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n    #include &lt;wx\/wx.h&gt;\n#endif\n\nclass GridSizer: public wxFrame {\n\n    public:\n      GridSizer(const wxString &amp;title);\n \n};\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">wxgridsizer.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;wxgridsizer.h&quot;\n\n\nGridSizer::GridSizer(const wxString &amp;title):\n\n    wxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,200)) {\n    wxPanel *basePanel = new wxPanel(this, -1);\n    wxGridSizer *baseSizer = new wxGridSizer(5,5,0,0);\n    basePanel-&gt;SetSizer(baseSizer);\n\n\n    wxButton *btnHome = new wxButton(basePanel, -1, wxT(&quot;&quot;));\n    baseSizer-&gt;Add(btnHome,1, wxEXPAND);\n\n    wxButton *btnCol1 = new wxButton(basePanel, -1, wxT(&quot;A&quot;));\n    baseSizer-&gt;Add(btnCol1,1, wxEXPAND);\n\n    wxButton *btnCol2 = new wxButton(basePanel, -1, wxT(&quot;B&quot;));\n    baseSizer-&gt;Add(btnCol2,1, wxEXPAND);\n\n    wxButton *btnCol3 = new wxButton(basePanel, -1, wxT(&quot;C&quot;));\n    baseSizer-&gt;Add(btnCol3,1, wxEXPAND);\n\n    wxButton *btnCol4 = new wxButton(basePanel, -1, wxT(&quot;D&quot;));\n    baseSizer-&gt;Add(btnCol4,1, wxEXPAND);\n\n    for (int row = 1; row &lt;=4; row++) {\n    \tfor(int col = 1; col &lt;=5; col++) {\n\t  if (col == 1) {\n\t  \twxButton *col = new wxButton(basePanel, -1, wxString::Format(wxT(&quot;%d&quot;),row));\n\t\tbaseSizer-&gt;Add(col,1, wxEXPAND);\n\t  } else {\n\t  \twxTextCtrl *txt = new wxTextCtrl(basePanel, -1);\n\t\ttxt-&gt;SetMaxLength(10);\n\t\tbaseSizer-&gt;Add(txt,1, wxEXPAND);\n\t  }\n\t}\n    }\n\n    Center();\n\n}\n\n<\/pre><\/div>\n\n\n<p>The output is shown below<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"243\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-19-14-37-11.png\" alt=\"\" class=\"wp-image-3908\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-19-14-37-11.png 533w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-19-14-37-11-300x137.png 300w\" sizes=\"auto, (max-width: 533px) 100vw, 533px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW wxGridSizer lets you place controls in the form of a grid using rows and columns. All the cells in the grid will have the <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2021\/12\/19\/5b-3-wxwidgets-gridsizer\/\" title=\"5b-3. wxWidgets &#8211; GridSizer\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,365],"tags":[],"class_list":["post-3905","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cc","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=3905"}],"version-history":[{"count":5,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3905\/revisions"}],"predecessor-version":[{"id":3911,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3905\/revisions\/3911"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/3595"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=3905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=3905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=3905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}