#include <boost/config.hpp>
#include <chrono>
#include <boost/ui/native/winmain.cpp>
class button_dialog : public ui::dialog
{
public:
button_dialog() : ui::dialog("Button usage dialog")
{
ui::button(*this, "&Press me")
.on_press(&button_dialog::on_press_me, this);
show_modal();
}
private:
void on_press_me()
{
}
};
class my_dialog : public ui::dialog
{
public:
my_dialog() : ui::dialog("Dialog example")
{
ui::button(*this, "&Close this dialog")
.on_press(&my_dialog::on_close, this);
}
private:
void on_close()
{
close();
}
};
void run_dialog()
{
my_dialog().show_modal();
}
class my_frame : public ui::frame
{
typedef my_frame this_type;
public:
my_frame() : ui::frame("Frame example")
{
ui::button(*this, "&Close this frame")
.on_press(&this_type::on_close, this);
menu_bar()
<< ( ui::menu("&File")
<< ui::menu::item("&Quit")
.on_press(&this_type::on_close, this)
)
;
status_bar().text("Ready");
}
private:
void on_close()
{
close();
}
};
void run_frame()
{
my_frame().show_modal();
}
void run_gui()
{
ui::dialog parent("Boost.UI documentation snippets");
ui::vbox layout(parent);
layout << ui::button(parent, "&Button").on_press([]{ button_dialog(); });
layout << (ui::hbox()
<< ui::button(parent, "&Dialog").on_press([]{ run_dialog(); })
<< ui::button(parent, "&Frame") .on_press([]{ run_frame(); })
);
layout << ui::button(parent, "&Event").on_press([]
{
ui::dialog dlg("Example dialog");
ui::button(dlg, "&Quit")
.on_press(&ui::dialog::close, &dlg);
dlg.show_modal();
});
layout << ui::button(parent, "&Timeout").on_press([]
{
);
});
ui::string_box string_box = ui::string_box(parent, "Initial text");
string_box.on_edit([&]
{
ui::log::info() << "Edited text: " << string_box.text();
});
layout << string_box.layout().justify();
ui::combo_box combo_box = ui::combo_box(parent,
"Initial text",
{ "Option 1", "Option 2", "Option 3" })
.on_select_event([&](ui::index_event& e)
{
ui::log::info() << "Selected option index: " << e.index()
<< ", text: " << combo_box.text();
});
layout << combo_box.layout().justify();
ui::choice choice = ui::choice(parent,
{ "Option 1", "Option 2", "Option 3" })
.on_select_event([&](ui::index_event& e)
{
ui::log::info() << "Selected option index: " << e.index()
<< ", text: " << choice.text();
});
layout << choice.layout().justify();
ui::list_box list_box = ui::list_box(parent,
{ "Option 1", "Option 2", "Option 3" })
.on_select_event([&](ui::index_event& e)
{
ui::log::info() << "Selected option index: " << e.index();
})
.on_activate_event([&](ui::index_event& e)
{
ui::log::info() << "Activated option index: " << e.index();
})
;
layout << list_box.layout().justify();
parent.resize(400, 600);
parent.show_modal();
}
int ui_main()
{
run_gui();
return 0;
}
int main(int argc, char* argv[])
{
}