Custom dialogs

Standard dialogs created by create_ok_dialog(), create_ok_cancel_dialog(), and other methods, use a predetermined layout, and content, specified by the current display theme. There are two ways to create a custom dialog. create_dialog() creates a completely empty dialog, using a creator lambda:

#include <x/w/dialog.H>
#include <x/w/gridlayoutmanager.H>

x::w::dialog d=mw->create_dialog
    ("dialog_id",
     []
     (const x::w::dialog &d)
     {
           x::w::gridlayoutmanager lm=d->get_layoutmanager();

           // ...
     },
     true,
     x::w::new_gridlayoutmanager{});

create_dialog()'s first parameter is the dialog's creator lambda. The second parameter specifies the dialog's layout manager. The third optional parameter specifies whether the new dialog is modal.

There's also a second, more complicated approach, that allows creating a custom subclass of x::w::dialogObj (x::w::dialog's underlying reference-counted object). This is the mechanism that creates x::w::input_dialogs, summarized as follows:

class custom_dialogObj : public x::w::dialogObj {

public:

    //! Constructor
    custom_dialogObj(const x::w::dialog_args &)
          : x::w::dialogObj(args)
    {
         auto main_window=this->dialog_window;

         // etc...
    }

    //! Destructor
    ~custom_dialogObj()=default;
};

typedef x::ref<custom_dialogObj> custom_dialog;

// ...
auto new_custom_dialog=mw->create_custom_dialog(
     "new_dialog@example.com",
     []
     (const auto &args)
     {
          return custom_dialog::create(args);
     },
     true, // modal
     x::w::new_gridlayoutmanager{});
	

create_custom_dialog()'s first parameter is the new dialog identifier. It's second parameter is a callable object that receives a x::w::dialog_args parameter, and returns a reference to a reference to a subclass of a x::w::dialog; create_custom_dialog() returns what the callable object itself returns. The remaining parameters are the new dialog's modal flag, and its layout manager.

A custom dialog class inherits from x::w::dialogObj, whose constructor takes a reference to the x::w::dialog_args. The custom callable object is typically a lambda that forwards the x::w::dialog_args to the custom dialog class's constructor, together with any other parameters.

The constructor forwards the x::w::dialog_args to its x::w::dialogObj superclass. The custom dialog class's constructor can, at this point, use the dialog_window to create the new dialog's display elements, and to store them into the custom dialog class itself, for easy access. This is how create_input_dialog() assembles a new x::w::input_dialog with its input_dialog_field class member.