Boost.UI
User Interface Boost library
cpp11/beman.cpp

Beman's challenge

See also
N3791 Lightweight Drawing Library ideas
// Copyright (c) 2017 Kolya Kosenko
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Beman's challenge:
// "Display Hello C++ World in a window and allow the user to drag that text
// around inside the window with a program that is only slightly more complex
// that the traditional hello world program."
// http://isocpp.org/files/papers/n3791.html
#include <boost/ui.hpp>
namespace ui = boost::ui;
int ui_main()
{
ui::dialog dlg("Boost.UI Beman's challenge");
ui::canvas canvas(dlg);
ui::point paint_pos(20, 20);
auto repaint = [&]
{
canvas.painter()
.clear_rect(0, 0, canvas.width(), canvas.height())
.font(canvas.font())
.fill_text("Hello C++ World", paint_pos)
;
};
ui::point drag_start_pos;
canvas
.on_resize(repaint)
.on_left_mouse_down_event([&](ui::mouse_event& e)
{
drag_start_pos = e.pos();
})
.on_mouse_drag_event([&](ui::mouse_event& e)
{
paint_pos += e.pos() - drag_start_pos;
repaint();
drag_start_pos = e.pos();
})
;
dlg.show_modal();
return 0;
}
int main(int argc, char* argv[])
{
return ui::entry(&ui_main, argc, argv);
}
boost::ui
Boost.UI library namespace.
Definition: window.hpp:20
boost::ui::point
basic_point< coord_type > point
2D point coordinates
Definition: coord.hpp:420
boost::ui::entry
int entry(int(*ui_main)(int, char *[]), int argc, char *argv[])
UI application entry.
ui.hpp
Master Boost.UI file.