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::new_gridlayoutmanager dialog_lm;
x::w::create_dialog_args dialog_config{
    "new_dialog@example.com",    // Dialog identifier
    true,                        // Modal dialog.
};

// Dialogs default to using the grid layout manager. This is how this default
// can be adjusted:

dialog_config.dialog_layout=dialog_lm;

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

           // ...
     },
     true);

create_dialog()'s first parameter is the dialog's identifier and other configuration settings. The second parameter is the dialog's creator lambda.

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", true},
     []
     (const auto &args)
     {
          return custom_dialog::create(args);
     });
	

create_custom_dialog()'s first parameter is also the dialog identifier and configuration settings. Its second parameter is a callable object that receives a x::w::dialog_args parameter, and returns a a reference to a subclass of a x::w::dialog; create_custom_dialog() returns what the callable object itself returns.

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 widgets, 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.