| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include "../../DFPSR/includeFramework.h"
- using namespace dsr;
- // Global
- const String mediaPath = string_combine(U"media", file_separator());
- bool running = true;
- // GUI handles
- Window window;
- Component buttonClear;
- Component buttonAdd;
- Component myListBox;
- int main(int argn, char **argv) {
- // Create a window
- window = window_create(U"GUI example", 1000, 700);
- // Register your custom components here
- //REGISTER_PERSISTENT_CLASS(className);
- // Load an interface to the window
- window_loadInterfaceFromFile(window, mediaPath + U"interface.lof");
- // Bind methods to events
- window_setCloseEvent(window, []() {
- running = false;
- });
- // Look up components by name
- buttonClear = window_findComponentByName(window, U"buttonClear");
- buttonAdd = window_findComponentByName(window, U"buttonAdd");
- myListBox = window_findComponentByName(window, U"myListBox");
- // Connect components with actions
- component_setPressedEvent(buttonClear, []() {
- // Clear list
- component_call(myListBox, U"ClearAll");
- });
- component_setPressedEvent(buttonAdd, []() {
- // Add to list
- component_call(myListBox, U"PushElement", U"New item");
- });
- component_setKeyDownEvent(myListBox, [](const KeyboardEvent& event) {
- if (event.dsrKey == DsrKey_Delete) {
- // Delete from list
- int64_t index = string_toInteger(component_call(myListBox, U"GetSelectedIndex"));
- if (index > -1) {
- component_call(myListBox, U"RemoveElement", string_combine(index));
- }
- }
- });
- component_setPressedEvent(myListBox, []() {
- int64_t index = string_toInteger(component_call(myListBox, U"GetSelectedIndex"));
- String content = component_call(myListBox, U"GetSelectedText");
- printText("content is (", content, ") at index ", index, "\n");
- });
- // Execute
- while(running) {
- // Wait for actions
- while (!window_executeEvents(window)) {
- time_sleepSeconds(0.01);
- }
- // Busy loop instead of waiting
- //window_executeEvents(window);
- // Draw interface
- window_drawComponents(window);
- // Show the final image
- window_showCanvas(window);
- }
- }
|