def create_and_position_dialog(
        self,
        level_name,
        clamping_rect,
        anchor_rect,
        dialog_pos_from,
        dialog_pos_to,
        dialog_offset_by,
    ):
        """Create image for dialog and position it."""
        ### assign proper icon surface to icon object
        ICON_OBJECT.image = ICON_MAP[level_name]

        ### position message relative to icon
        self.message.rect.midleft = ICON_OBJECT.rect.move(5, 0).midright

        ### group message and icons in same special list
        a_list = List2D([self.message, ICON_OBJECT])

        ### position buttons relative to special list
        self.buttons.rect.midtop = a_list.rect.move(0, 8).midbottom

        ### append buttons to special list
        a_list.append(self.buttons)

        ### position them relative to the given anchor

        offset_anchor_rect = anchor_rect.move(dialog_offset_by)

        pos = getattr(
            offset_anchor_rect,
            dialog_pos_from,
        )

        setattr(a_list.rect, dialog_pos_to, pos)

        ### obtain inflated copy of their area
        inflated_copy = a_list.rect.inflate(20, 20)

        ### move the objects by the different in position
        ### between the inflated copy and a new clamped
        ### copy, if any

        a_list.rect.move_ip(
            [
                a - b
                for a, b in zip(
                    ## topleft of clamped copy
                    inflated_copy.clamp(clamping_rect).topleft,
                    inflated_copy.topleft,
                )
            ]
        )

        ### generate surf

        self.image = render_rect(*inflated_copy.size, WINDOW_BG)

        draw_border(self.image)

        ### assign inflated copy as the rect
        self.rect = inflated_copy

        ### center it on the list, since it
        ### is clamped
        self.rect.center = a_list.rect.center
Create image for dialog and position it.
nodezator/dialog.py