{"id":4113,"date":"2022-01-13T14:38:10","date_gmt":"2022-01-13T14:38:10","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4113"},"modified":"2022-01-13T14:38:11","modified_gmt":"2022-01-13T14:38:11","slug":"9c-wxwidgets-wxscrolledwindow","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/13\/9c-wxwidgets-wxscrolledwindow\/","title":{"rendered":"9c. wxWidgets &#8211; wxScrolledWindow"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>wxWidgets provides a class called wxScrolled&lt;T> which is a template for specialized scrolling classes. It has two implementations of this class:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>wxScrolledCanvas<\/li><li>wxScrolledWindow<\/li><\/ul>\n\n\n\n<p>In this section, we look at wxScrolledWindow. wxScrolledWindow is actually wxScrolled(wxPanel) in that, it wraps a wxPanel into wxScroll.<\/p>\n\n\n\n<p>In the sample code below, we add 50 labels to a wxScrolledWindow, which is only vertically scrollable.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">scrolledwindow.h<\/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\t#include &lt;wx\/wx.h&gt;\n#endif\n\n\nclass ScrolledWindow: public wxFrame {\n\tpublic:\n\t\tScrolledWindow(const wxString &amp;title);\t\n\n\tprivate:\n\t\twxStaticText  *mText&#x5B;50];\n};\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">scrolledwindow.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;scrolledwindow.h&quot;\n\nScrolledWindow::ScrolledWindow(const wxString &amp;title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(700,550)) {\n\twxScrolledWindow *sw = new wxScrolledWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxVSCROLL);\n\n\twxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);\n\tsw-&gt;SetSizer(vbox);\n\n\twxString text = wxT(&quot;&quot;);\n\tfor(int i =0; i &lt; 50; i++) {\n\t  text = wxT(&quot;This is row &quot;);\n\t  mText&#x5B;i] = new wxStaticText(sw, -1, text.Append(wxString::Format(wxT(&quot;%d&quot;), (i+1))));\n\t  vbox-&gt;Add(mText&#x5B;i],1, wxEXPAND);\n\t}\n\n\tCenter();\n\tint w=0, h=0;\n\tGetSize(&amp;w, &amp;h);\n\tsw-&gt;SetScrollbars(0,10,0, h\/10);\n}\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.h<\/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\t#include &lt;wx\/wx.h&gt;\n#endif\n\nclass Main: public wxApp {\n\n\tpublic:\n\t\tvirtual bool OnInit();\n};\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;main.h&quot;\n#include &quot;scrolledwindow.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tScrolledWindow *app = new ScrolledWindow(wxT(&quot;Scrolled Window&quot;));\n\tapp-&gt;Show(true);\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=\"700\" height=\"550\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-13-20-07-02.png\" alt=\"\" class=\"wp-image-4115\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-13-20-07-02.png 700w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-13-20-07-02-620x487.png 620w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-13-20-07-02-300x236.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW wxWidgets provides a class called wxScrolled&lt;T> which is a template for specialized scrolling classes. It has two implementations of this class: wxScrolledCanvas wxScrolledWindow In <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/13\/9c-wxwidgets-wxscrolledwindow\/\" title=\"9c. wxWidgets &#8211; wxScrolledWindow\">[&#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-4113","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\/4113","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=4113"}],"version-history":[{"count":3,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4113\/revisions"}],"predecessor-version":[{"id":4117,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4113\/revisions\/4117"}],"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=4113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}