-
-
Notifications
You must be signed in to change notification settings - Fork 7
Undo Redo module
The undo/redo module provides support for undo/redo operations
To enable the plotting module, you can either hardcode the USE_UNDO_MODULE option in your CMakeLists.txt file by finding the following line:
option(USE_UNDO_MODULE "Use the undo module" OFF)and modifying the line to look like this
option(USE_UNDO_MODULE "Use the undo module" ON)Alternatively, you can also generate your project files using CMake options by running the following CMake command:
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DUSE_UNDO_MODULE=ONFinally, update your uvproj.yaml so that the undo-redo key under enabled-modules is set to true like this:
name: "MyProject"
version: "1.0.0.0"
engine-version: "1.0.0.0"
enabled-modules:
undo-redo: trueNext, in your source file, include the Modules.hpp header in your components like this:
#include <Modules/Modules.hpp>The entire module is flagged as event safe at Post-begin
The module stores data in the Transaction data type, as can be seen below:
struct UIMGUI_PUBLIC_API Transaction
{
std::function<void(TransactionPayload&)> undofunc;
std::function<void(TransactionPayload&)> redofunc;
TransactionPayload payload;
};The 2 functions are the events to be called on undo and redo respectively
The payload member is of type TransactionPayload which is a simple struct storing a void* for a buffer and its size like this:
struct UIMGUI_PUBLIC_API TransactionPayload
{
void* payload;
size_t size;
};So to push a transaction create a transaction, initialize the events and the payload and push it as an argument to the push function like this
Transaction transaction =
{
.undofunc = [](TransactionPayload&){ Logger::log("Undo", UVKLog::UVK_LOG_TYPE_NOTE); },
.redofunc = [](TransactionPayload&){ Logger::log("Redo", UVKLog::UVK_LOG_TYPE_NOTE); },
.payload =
{
.payload = nullptr,
.size = 0,
}
};
UImGui::StateTracker::push(transaction);and now you have added an action that can be undone.
To undo or redo an action, simply call the undo or redo member functions of the StateTracker class like this
UImGui::StateTracker::undo();
UImGui::StateTracker::redo();and you should get the appropriate output logged to the console
This project is supported by all the people who joined our discord server and became beta testers. If you want to join the discord you can click here.
- Home
- Beginner content
- Install guide
- Creating and using the UI components
- The Instance
- The Init Info struct
- Building better titlebar menus
- Textures
- Logging
- Unicode support
- Additional features
- Client-side bar
- Custom type definitions
- Memory management
- C API development
- Config files and Folders
- Interfaces
- Internal Event safety
- Customising the build system
- Modules system
- Collaborating with others
- Advanced content
- Loading dynamic libraries at runtime
- Understanding the library layout
- Compilation mode modifiers
- Supporting plugins
- Production export and deployment
- OS integration tips
- Targeting WASM
- Using a custom rendering engine:
- Using a custom windowing backend:
- Developer and contributor resources
- Misc