Unigine::WidgetDialogFile Class
Header: | #include <UnigineWidgets.h> |
Inherits from: | WidgetDialog |
This class creates dialog window where a file is selected. On the left side file-related information or an image preview is displayed.
Example#
The following code illustrates how to create a file selection dialog widget and use it to select files. Add the code below to the corresponding files of your project (AppWorldLogic.h and AppWorldLogic.cpp).
AppWorldLogic.h
class AppWorldLogic : public Unigine::WorldLogic
{
// ... //
private:
// declaring widgets to be used and callback functions for them
Unigine::WidgetLabelPtr file_name;
Unigine::WidgetButtonPtr open_button;
Unigine::WidgetDialogFilePtr file_dialog;
void on_button_clicked(const Unigine::WidgetPtr & widget, int mouse_buttons);
void dialog_ok_clicked();
void dialog_cancel_clicked();
Unigine::EventConnections connection;
};
AppWorldLogic.cpp
#include "AppWorldLogic.h"
#include <UnigineFileSystem.h>
using namespace Unigine;
// callback to be fired on clicking the button displaying the file dialog
void AppWorldLogic::on_button_clicked(const WidgetPtr & widget, int mouse_buttons)
{
// resetting file selection, showing the dialog and setting permanent focus to it
file_dialog->setFile("");
file_dialog->setHidden(0);
file_dialog->setPermanentFocus();
}
// callback to be fired on clicking the Ok button of the file dialog
void AppWorldLogic::dialog_ok_clicked()
{
// getting the current path selection fron the dialog and checking if the file exists
String path = file_dialog->getFile();
if (!FileSystem::isFileExist(path))
return;
// if the file exists hiding the dialog, displaying the selected file on the "file_name" label and removing focus
file_dialog->setHidden(1);
file_name->setText(path);
file_dialog->removeFocus();
}
// callback to be fired on clicking the Cancel button of the file dialog
void AppWorldLogic::dialog_cancel_clicked()
{
file_dialog->setHidden(1);
file_dialog->removeFocus();
}
int AppWorldLogic::init()
{
// getting a pointer to the system GUI
GuiPtr gui = Gui::getCurrent();
// creating a label widget to display the file selected via the dialog
file_name = WidgetLabel::create(gui, "No file selected yet");
gui->addChild(file_name, Gui::ALIGN_TOP | Gui::ALIGN_BACKGROUND);
// creating a button widget to display the file dialog
open_button = WidgetButton::create(gui, "Select an image file on disk");
gui->addChild(open_button, Gui::ALIGN_TOP | Gui::ALIGN_BACKGROUND);
// setting "on_button_clicked" function to handle CLICKED event for the button
open_button->getEventClicked().connect(connection, this, &AppWorldLogic::on_button_clicked);
// creating a file dialog widget and setting its caption, default path and file extensions filter to display only *.png and *.jpeg files
file_dialog = WidgetDialogFile::create(gui, "File open dialog");
file_dialog->setPath("./");
file_dialog->setFilter(".png.jpeg");
// setting "dialog_ok_clicked" function to handle CLICKED event for dialog Ok button
file_dialog->getOkButton()->getEventClicked().connect(connection, this, &AppWorldLogic::dialog_ok_clicked);
// setting "dialog_cancel_clicked" function to handle CLICKED event for dialog Cancel button
file_dialog->getCancelButton()->getEventClicked().connect(connection, this, &AppWorldLogic::dialog_cancel_clicked);
// adding the created file dialog widget to the system GUI and hiding it
file_dialog->setHidden(1);
gui->addChild(file_dialog, Gui::ALIGN_OVERLAP | Gui::ALIGN_CENTER);
return 1;
}
WidgetDialogFile Class
Members
static WidgetDialogFilePtr create ( const Ptr<Gui> & gui, const char * str = 0 ) #
Constructor. Creates a file picker dialog with given parameters and adds it to the specified GUI.Arguments
- const Ptr<Gui> & gui - GUI, to which the dialog will belong.
- const char * str - Dialog title. This is an optional parameter.
static WidgetDialogFilePtr create ( const char * str = 0 ) #
Constructor. Creates a file picker dialog with given parameters and adds it to the Engine GUI.Arguments
- const char * str - Dialog title. This is an optional parameter.
void setFile ( const char * file ) #
Selects a given file in the file picker.Arguments
- const char * file - Absolute or relative (to the data folder) path.
const char * getFile ( ) const#
Returns the currently selected file.Return value
Path to the file.void setFilter ( const char * filter ) #
Sets a file name filter, which is used to display files of required types only.Arguments
- const char * filter - List of file extensions with leading dots and without additional separators, for example: .mesh.smesh.
const char * getFilter ( ) const#
Returns the currently used file name filter.Return value
List of file extensions with leading dots and without additional separators, for example: .mesh.smesh.void setPath ( const char * path ) #
Sets a path to the folder, contents of which should be displayed in the file picker.Arguments
- const char * path - Absolute or relative (to the data folder) path.
const char * getPath ( ) const#
Returns the current path to the folder, contents of which is displayed in the file picker.Return value
Current path to the folder.void setTabs ( const char * tabs ) #
Adds a set of tabs to the file picker dialog. The tabs allow the user to interact with several folders at once.Arguments
- const char * tabs - List of paths separated with semicolons. Each path corresponds to a tab.
const char * getTabs ( ) const#
Returns a list of tabs in the file picker dialog. The tabs allow the user to interact several folders at once.Return value
List of paths separated with semicolons. Each path corresponds to a tab.Last update:
16.08.2024
Помогите сделать статью лучше
Была ли эта статья полезной?
(или выберите слово/фразу и нажмите Ctrl+Enter