{"id":4087,"date":"2022-01-06T13:14:52","date_gmt":"2022-01-06T13:14:52","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4087"},"modified":"2022-01-06T13:14:56","modified_gmt":"2022-01-06T13:14:56","slug":"8f-wxwidgets-wxslider","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/06\/8f-wxwidgets-wxslider\/","title":{"rendered":"8f.wxWidgets &#8211; wxSlider"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>wxSliders allow the user to control a range of values , which represent the starting and ending point of the slider. Every time the slider value changes it triggers an event. This event can be handled to do whatever processing we need. The sample code below updates a wxStaticText to show the current value of the wxSlider, when it slides.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">slider.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    #include &lt;wx\/wx.h&gt;\n#endif\n#include &lt;wx\/slider.h&gt;\n\n\nclass Slider: public wxFrame {\n\n    public:\n      Slider(const wxString &amp;title);\n      void onScroll(wxCommandEvent &amp;event);\n\n    private:\n      wxSlider *mSlider;\n      wxStaticText *mLabel;\n\n};\n\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">slider.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;slider.h&quot;\n\nSlider::Slider(const wxString &amp;title):\n\n    wxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,200)) {\n \n    wxPanel *panel = new wxPanel(this, -1);   \n    wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);\n    panel-&gt;SetSizer(vbox);\n\n    mSlider = new wxSlider(panel, -1, 0,0,100,wxDefaultPosition, wxDefaultSize);\n    mLabel = new wxStaticText(panel, -1, wxT(&quot;&quot;));\n    vbox-&gt;Add(mSlider,1,wxEXPAND);\n    vbox-&gt;Add(mLabel, 1, wxEXPAND);\n\n    mSlider-&gt;Bind(wxEVT_SLIDER, &amp;Slider::onScroll, this);\n    \n    Center();\n\n}\n\nvoid Slider::onScroll(wxCommandEvent &amp;event) {\n\tint val = mSlider-&gt;GetValue();\n\tmLabel-&gt;SetLabel(wxString::Format(wxT(&quot;%d&quot;), val));\n}\n\n\n\n\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    #include &lt;wx\/wx.h&gt;\n#endif\n\nclass Main: public wxApp {\n\n\tpublic:\n\t        virtual 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;slider.h&quot;\n \nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\n    Slider *app = new Slider(wxT(&quot;Slider&quot;));\n    app-&gt;Show(true);\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=\"500\" height=\"200\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-06-18-43-50.png\" alt=\"\" class=\"wp-image-4090\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-06-18-43-50.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-06-18-43-50-300x120.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW wxSliders allow the user to control a range of values , which represent the starting and ending point of the slider. Every time the <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/06\/8f-wxwidgets-wxslider\/\" title=\"8f.wxWidgets &#8211; wxSlider\">[&#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-4087","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\/4087","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=4087"}],"version-history":[{"count":3,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4087\/revisions"}],"predecessor-version":[{"id":4091,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4087\/revisions\/4091"}],"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=4087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}