Widgets in C++ with xeus and cling

Slider


In [1]:
#include "xwidgets/xslider.hpp"

In [2]:
xw::slider<double> slider;

slider.display()



In [3]:
slider.value = 20;

In [4]:
slider.value()


(double) 20.000000

In [5]:
slider.max = 40;

In [6]:
slider.style().handle_color = "blue";

In [7]:
slider.orientation = "vertical";

In [8]:
slider.description = "A slider";

Button widget


In [9]:
#include "xwidgets/xbutton.hpp"

In [10]:
xw::button button;

In [11]:
void foo()
{
    std::cout << "Clicked!" << std::endl;
}

In [12]:
button.on_click(foo);
    
button.display()



In [13]:
button.description = "button";

Value semantics


In [14]:
auto button_copy = button;

In [15]:
button_copy.display()



In [16]:
button.style().button_color = "red";
button_copy.style().button_color = "green";

In [17]:
#include "xwidgets/xslider.hpp"
#include "xwidgets/xlink.hpp"

In [18]:
xw::slider<double> s1, s2;

In [19]:
auto l = xw::make_link(s1, "value", s2, "value");

In [20]:
s1.display()



In [21]:
s2.display()



In [22]:
s1.value = 10.;

Box Widgets


In [23]:
#include "xwidgets/xbutton.hpp"
#include "xwidgets/xslider.hpp"
#include "xwidgets/xbox.hpp"

In [24]:
xw::vbox b;
xw::button but;
xw::slider<double> slid;

In [25]:
b.add(but);
b.add(slid);
b.display()


Numerical widgets

Progress


In [26]:
#include "xwidgets/xprogress.hpp"

In [27]:
xw::progress<double> progress;

In [28]:
progress.display()



In [29]:
progress.value = 60;

In [30]:
progress.style().bar_color = "red";

In [31]:
progress.description = "Completion";

Numerical input


In [32]:
#include "xwidgets/xnumeral.hpp"

In [33]:
xw::numeral<double> numeral;
numeral.display()



In [34]:
numeral.value = 4;

In [35]:
numeral.value()


(double) 4.000000

Timer


In [36]:
#include "xwidgets/xplay.hpp"

In [37]:
xw::play play;
play.display()


Boolean widgets

Checkbox


In [38]:
#include "xwidgets/xcheckbox.hpp"

In [39]:
xw::checkbox checkbox;

In [40]:
checkbox.display()



In [41]:
checkbox.value = true;

In [42]:
checkbox.indent = false;

Toggle button


In [43]:
#include "xwidgets/xtogglebutton.hpp"

In [44]:
xw::togglebutton toggle;

In [45]:
toggle.display()



In [46]:
toggle.value = true;

In [47]:
toggle.description = "toggle";

Valid check


In [48]:
#include "xwidgets/xvalid.hpp"

In [49]:
xw::valid valid;

In [50]:
valid.display()



In [51]:
valid.value = true;

String widgets

Label widget


In [52]:
#include "xwidgets/xlabel.hpp"

In [53]:
xw::label label;

In [54]:
label.display();



In [55]:
label.value = "Some caption";

HTML widget


In [56]:
#include "xwidgets/xhtml.hpp"

In [57]:
xw::html html;

In [58]:
html.value = R"xhtml(
    <div style="
        width: 50%;
        height: 100px;
        background: #323;
        color: white;
        text-align: center;"
        >Some HTML
    </div>
)xhtml";
html.display();


Text widget


In [59]:
#include "xwidgets/xtext.hpp"

In [60]:
xw::text text;
text.value = "Some text";
text.display()



In [61]:
void submit_callback()
{
    std::cout << "submitted" << std::endl;
}

In [62]:
text.on_submit(submit_callback);

Textarea widget


In [63]:
#include "xwidgets/xtextarea.hpp"

In [64]:
xw::textarea textarea;
textarea.value = R"textarea(Lorem ipsum dolor sit amet, consectetur 
adipiscing elit,  sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris  nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa 
qui officia deserunt mollit anim id est laborum.
)textarea";
textarea.display()


Password widget


In [ ]:
#include "xwidgets/xpassword.hpp"

In [ ]:
xw::password password;

In [ ]:
password.display()

Widgets layout


In [ ]:
xw::button buttonl;
buttonl.display()

In [ ]:
buttonl.layout().width = "50%";
buttonl.layout().height = "200px";

In [ ]:
buttonl.style().button_color = "#888";