NvDialog 0.10.1
A cross-platform modal dialogs library for C/C++ that uses the native OS theme.
Loading...
Searching...
No Matches
nvdialog_dialog_box.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2025 Aggelos Tselios
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
26#include "../nvdialog_types.h"
27
28/**
29 * @brief A type to identify a single dialog box.
30 * @note You can only use a dialog box once. Reusing it is undefined behavior.
31 * <b>Example:</b>
32 * @code
33 * #include <nvdialog/nvdialog.h>
34 * int main(int argc, char** argv) {
35 * nvd_init(argv[0]);
36 * NvdDialogBox *dialog = nvd_dialog_box_new("Hello World!",
37 * "A simple dialog box.",
38 * NVD_DIALOG_SIMPLE);
39 * if (!dialog) return -1;
40 *
41 * nvd_show_dialog(dialog);
42 * nvd_free_object(dialog);
43 *
44 * return 0;
45 * }
46 * @endcode
47 * @since v0.1.0
48 */
49typedef struct _NvdDialogBox NvdDialogBox;
50
51/**
52 * @brief A similar struct to @ref NvdDialogBox, but
53 * instead used for question dialogs.
54 * @since v0.1.0
55 * @ingroup QuestionDialog
56 */
57typedef struct _NvdQuestionBox NvdQuestionBox;
58
59/**
60 * @brief Creates a new dialog object and returns it.
61 *
62 * This function creates a simple dialog with the specified arguments,
63 * and returns an opaque handle to it for use with @ref nvd_show_dialog.
64 *
65 * @ingroup QuestionDialog
66 * @return The dialog handle on success, else NULL.
67 * @since v0.1.0
68 */
69NVD_API NvdDialogBox *nvd_dialog_box_new(const char *title, const char *message,
70 NvdDialogType type);
71
72/**
73 * @brief Shows a dialog to the system shell.
74 * @details The dialog given is rendered to the screen when this function is
75 * called. Note that this function works even on headless environments, although it
76 * will not produce any result.
77 * @param dialog The dialog to show.
78 * @ingroup QuestionDialog
79 */
81
82/**
83 * @brief Creates a question dialog box with the given parameters.
84 * This function creates a dialog box containing a question with a few
85 * buttons such as:
86 * - Yes / No
87 * - Yes / No / Cancel
88 * - Yes / Cancel
89 * @ingroup QuestionDialog
90 * @return The NvdReply on success, else -1 -- Check @ref nvd_get_error for
91 * more.
92 * @since v0.1.1
93 */
95 const char *question,
96 NvdQuestionButton button);
97
98/**
99 * @brief Shows the question dialog given to the system and returns the choice given
100 * @param box The box to use to show the reply.
101 * @ingroup QuestionDialog
102 * @return The reply from the dialog box.
103 */
105
106/**
107 * @brief Returns the raw object behind the dialog.
108 * @param dialog The dialog to retrieve the object from.
109 * @ingroup QuestionDialog
110 * @return void* The raw toolkit-created object.
111 * @warning On Windows this will always return NULL, as the dialog is created on the spot upon showing it (See MessageBox for details.)
112 */
114
115/**
116 * @brief Returns the raw object behind the dialog.
117 * @param dialog The dialog to retrieve the object from.
118 * @ingroup QuestionDialog
119 * @return void* The raw toolkit-created object.
120 * @warning On Windows this will always return NULL, as the dialog is created on the spot upon showing it (See MessageBox for details.)
121 */
123
124/**
125 * @brief Sets the accept text for the dialog (The "Ok" button label).
126 * @param dialog The dialog to change the button label.
127 * @ingroup QuestionDialog
128 * @param accept_text The new label of the dialog button. May not be NULL.
129 * @warning This function has no effect on Windows - The system will decide the button's text based on language and user preferences.
130 * @since v0.8.0
131 */
133 const char *accept_text);
#define NVD_API
Definition nvdialog.h:113
NVD_API void nvd_dialog_box_set_accept_text(NvdDialogBox *dialog, const char *accept_text)
Sets the accept text for the dialog (The "Ok" button label).
NVD_API NvdQuestionBox * nvd_dialog_question_new(const char *title, const char *question, NvdQuestionButton button)
Creates a question dialog box with the given parameters. This function creates a dialog box containin...
NVD_API void * nvd_dialog_question_get_raw(NvdQuestionBox *dialog)
Returns the raw object behind the dialog.
struct _NvdQuestionBox NvdQuestionBox
A similar struct to NvdDialogBox, but instead used for question dialogs.
Definition nvdialog_dialog_box.h:57
NVD_API void * nvd_dialog_box_get_raw(NvdDialogBox *dialog)
Returns the raw object behind the dialog.
struct _NvdDialogBox NvdDialogBox
A type to identify a single dialog box.
Definition nvdialog_dialog_box.h:49
NVD_API NvdReply nvd_get_reply(NvdQuestionBox *box)
Shows the question dialog given to the system and returns the choice given.
NVD_API void nvd_show_dialog(NvdDialogBox *dialog)
Shows a dialog to the system shell.
NVD_API NvdDialogBox * nvd_dialog_box_new(const char *title, const char *message, NvdDialogType type)
Creates a new dialog object and returns it.
NvdReply
An enumerator containing a possible returned value by nvd_get_reply, when used with an NvdQuestionBox...
Definition nvdialog_types.h:70
NvdDialogType
Defines what use it the dialog about. Each member of this enum defines what the dialog should represe...
Definition nvdialog_types.h:41
NvdQuestionButton
Enumerator containing the possible arguments for nvd_dialog_question_new().
Definition nvdialog_types.h:59