|
NvDialog 0.10.1
A cross-platform modal dialogs library for C/C++ that uses the native OS theme.
|
This page provides a simple tutorial of the NvDialog library. For more information about the library itself, see https://tseli0s.github.io/nv.dialog. Proper documentation of the API used in this tutorial is also available in the documentation. This tutorial assumes you have already installed NvDialog in your system. If not, visit the GitHub Repo. NvDialog is compiler and platform independent, so this tutorial should work as expected on all platforms.
Skip this step if you aren't interested in the setup. Create a new file named main.c and add the following to it:
This snippet contains a barebones C program which includes NvDialog. You can try compiling this to verify that the headers can be found at compile time.
A dialog box is the simplest and most straightforward feature of NvDialog: It shows a dialog with some parameters given. You will mainly use this for error messages (Although it can be used for literally anything, see NvdDialogType ).
To get started, we first need to initialize NvDialog. This can be done with a single call:
Initialization is mainly required by the backends. Each backend is often required to be initialized first.
Go to your main function, and create a new dialog box object. The title and the message need to be a regular NULL terminated C string. For the sake of simplicity we will create them in seperate variables:
const char *title = "Hello NvDialog!";const char *message = "This dialog box was created with NvDialog.";</blockquote>struct _NvdDialogBox NvdDialogBoxA type to identify a single dialog box.Definition nvdialog_dialog_box.h:49NVD_API NvdDialogBox * nvd_dialog_box_new(const char *title, const char *message, NvdDialogType type)Creates a new dialog object and returns it.nvd_dialog_box_new will return NULL on failure, so you may want to handle that too.
Before
Now, we are technically done. However, we have caused a memory leak here because after all, the NvdDialogBox type like most others is heap-allocated! Which means we need to free() it. Calling free() directly though will cause undefined behavior. So instead, we will use a special function provided by NvDialog, which frees most types. That function is called nvd_free_object .
Your final source file should look like this:
Now let's compile it:
On the terminal, go to the directory where your source file is located (Using cd). Then run the following command to compile your file:
And now running it should give you a dialog box. That's all you need to get started. For other dialogs to use, take a look at the following types: