Repository navigation
Window
Let's look at the window interface
enum class window_style : uint32_t
{
resizable = (1 << 0),
moving = (1 << 1),
close_button = (1 << 2),
expand_button = (1 << 3),
minimize_button = (1 << 4),
pin_button = (1 << 5),
title_showed = (1 << 6),
frame = title_showed | close_button | expand_button | minimize_button | resizable | moving,
dialog = title_showed | close_button | moving,
pinned = pin_button | close_button | resizable | moving
};
struct system_context;
struct event;
enum class event_type : uint32_t;
class i_window
{
public:
virtual bool init(const std::wstring &caption, const rect &position, window_style style, std::function<void(void)> close_callback, std::shared_ptr<i_theme> theme_ = nullptr) = 0;
virtual void destroy() = 0;
virtual void add_control(std::shared_ptr<i_control> control, const rect &position) = 0;
virtual void remove_control(std::shared_ptr<i_control> control) = 0;
virtual void redraw(const rect &position, bool clear = false) = 0;
virtual int32_t subscribe(std::function<void(const event&)> receive_callback, event_type event_types, std::shared_ptr<i_control> control = nullptr) = 0;
virtual void unsubscribe(int32_t subscriber_id) = 0;
virtual system_context &context() = 0;
protected:
~i_window() {}
};The init() method is called only to create a stand-alone window (you cannot call this method when creating a window that is a control in another window). It is better to call this method after adding all the controls with add_control(). The method accepts the following arguments:
- caption - Window title.
- position - The position of the window on the screen.
- style - window style defined by a combination of window_style enumeration values.
- close_callback - Callback called when the window is closed or the destroy() method is called.
- theme - Personal window theme. If you leave nullptr the current application theme will be applied.
The destroy() method is called when the window is closed by the user or when the window becomes unnecessary. When this method is called, the window releases its child controls and starts its destruction in the operating system. If the window is needed again, AddControl() and Init() must be called.
The add_control() method is called when you want to add a control to a window. The method accepts the following arguments:
- control - the element you want to add to the window. The window remembers the shared pointer to this control, and will forget it when remove_control() or destroy() is called. This way you don't have to worry about storing window children anywhere else.
- position - position of the control in the window. rect contains 4 parameters - left, top, right and bottom
The redraw() method is used by the controls contained in the window to initiate their own redraw. It can also be invoked by the user to force a rectangular part of the window to update the position defined by the position parameter. The parameter clear defines whether it is necessary to clear when redrawing.