### Build imgui_example_glfw_wgpu with Emscripten Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_glfw_wgpu/CMakeLists.txt Guide for compiling the example for the web using Emscripten. Requires installing the Emscripten SDK and Ninja. The build process utilizes `emcmake` for CMake commands and `emrun` to execute the resulting HTML file. ```bash # Install Emscripten SDK following the instructions: https://emscripten.org/docs/getting_started/downloads.html # Install Ninja build system emcmake cmake -G Ninja -B build # (optional) -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path/to/emdawnwebgpu_package/emdawnwebgpu.port.py", see ReadMe.md cmake --build build emrun build/index.html ``` -------------------------------- ### Build Example with Visual Studio CLI on Windows (64-bit) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_opengl3/README.md Compiles the project using the Visual Studio C++ compiler for a 64-bit executable. Requires SDL2 to be installed and its directories to be specified. ```batch set SDL2_DIR=path_to_your_sdl2_folder cl /Zi /MD /utf-8 /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl2_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x64 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console ``` -------------------------------- ### Build Example on macOS Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_opengl3/README.md Compiles the project on macOS, requiring SDL2 to be installed via Homebrew. It links against SDL2 and OpenGL frameworks. ```bash brew install sdl2 c++ `sdl2-config --cflags` -I .. -I ../.. -I ../../backends main.cpp ../../backends/imgui_impl_sdl2.cpp ../../backends/imgui_impl_opengl3.cpp ../../imgui*.cpp `sdl2-config --libs` -framework OpenGl -framework CoreFoundation ``` -------------------------------- ### Build Example with Visual Studio CLI on Windows (32-bit) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_opengl3/README.md Compiles the project using the Visual Studio C++ compiler for a 32-bit executable. Requires SDL2 to be installed and its directories to be specified. ```batch set SDL2_DIR=path_to_your_sdl2_folder cl /Zi /MD /utf-8 /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl2_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console ``` -------------------------------- ### Dear ImGui Initialization, Frame, and Shutdown Sequence (C++) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/EXAMPLES.md This snippet outlines the core sequence for integrating Dear ImGui into an application. It covers the necessary calls for initialization, starting a new frame, rendering the UI, and shutting down the library. This pattern is crucial for any application using Dear ImGui. ```cpp At initialization: call ImGui::CreateContext() call ImGui_ImplXXXX_Init() for each backend. At the beginning of your frame: call ImGui_ImplXXXX_NewFrame() for each backend. call ImGui::NewFrame() At the end of your frame: call ImGui::Render() call ImGui_ImplXXXX_RenderDrawData() for your Renderer backend. At shutdown: call ImGui_ImplXXXX_Shutdown() for each backend. call ImGui::DestroyContext() ``` -------------------------------- ### Build Example with Emscripten Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_opengl3/README.md Builds the project for the Emscripten platform (WebAssembly). Requires Emscripten SDK installation and environment variables to be set. Uses a specific Makefile. ```bash make -f Makefile.emscripten ``` -------------------------------- ### Build for Emscripten (Web) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_wgpu/CMakeLists.txt Builds the ImGui example for the web using Emscripten. Requires installing the Emscripten SDK and Ninja. CMake is invoked with `emcmake`, and the application is run using `emrun`. Optional flags can be used to specify WebGPU package paths. ```bash # Install Emscripten SDK following the instructions: https://emscripten.org/docs/getting_started/downloads.html # Install Ninja build system emcmake cmake -G Ninja -B build # (optional) -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path/to/emdawnwebgpu_package/emdawnwebgpu.port.py", see ReadMe.md cmake --build build emrun build/index.html ``` -------------------------------- ### Build for Emscripten Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl3_wgpu/CMakeLists.txt Instructions for compiling the ImGui SDL3 WGPU example for the web using Emscripten. This requires installing the Emscripten SDK and Ninja build system. CMake commands are prefixed with 'emcmake'. An optional flag can be used to specify a custom emdawnwebgpu package. ```bash emcmake cmake -G Ninja -B build # Optional: emcmake cmake -G Ninja -B build -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path/to/emdawnwebgpu_package/emdawnwebgpu.port.py" cmake --build build emrun build/index.html ``` -------------------------------- ### Build Native Desktop with Dawn (WebGPU) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_wgpu/CMakeLists.txt Builds the ImGui example for desktop using WebGPU with the Dawn library. Requires cloning the Dawn repository and using CMake with specific build flags. The output binary is located in the build directory. ```bash git clone https://github.com/google/dawn dawn cmake -B build -DIMGUI_DAWN_DIR=dawn cmake --build build # The resulting binary will be found at one of the following locations: # * build/Debug/example_sdl2_wgpu[.exe] # * build/example_sdl2_wgpu[.exe] ``` -------------------------------- ### Build Example on Linux/Unix Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_opengl3/README.md Compiles the project on Linux or similar Unix-like systems using g++. It links against SDL2 and OpenGL libraries. Requires sdl2-config to be in the PATH. ```bash c++ `sdl2-config --cflags` -I .. -I ../.. -I ../../backends main.cpp ../../backends/imgui_impl_sdl2.cpp ../../backends/imgui_impl_opengl3.cpp ../../imgui*.cpp `sdl2-config --libs` -lGL -ldl ``` -------------------------------- ### Build Native Desktop with WGPU-Native Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_wgpu/CMakeLists.txt Compiles the ImGui example for desktop using WGPU-Native. This method involves downloading pre-compiled WGPU-Native binaries and specifying their location via CMake. The output binary is found in the build directory. ```bash # download WGPU-Native autogenerated binary modules for your platform/compiler from: https://github.com/gfx-rs/wgpu-native/releases # unzip the downloaded file in your_preferred_folder cmake -B build -DIMGUI_WGPU_DIR=your_preferred_folder ("full path" or "relative" starting from current directory) cmake --build build # The resulting binary will be found at one of the following locations: # * build/Debug/example_sdl2_wgpu[.exe] # * build/example_sdl2_wgpu[.exe] ``` -------------------------------- ### Build for Desktop with WGPU-Native Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl3_wgpu/CMakeLists.txt Steps to build the ImGui SDL3 WGPU example using WGPU-Native for desktop applications. This involves downloading pre-compiled WGPU-Native binary modules and configuring CMake to point to the unzipped folder. Ensure you download the correct modules for your platform and compiler. ```bash unzip downloaded_wgpu_native.zip -d your_preferred_folder cmake -B build -DIMGUI_WGPU_DIR=your_preferred_folder cmake --build build ``` -------------------------------- ### Configure ImGui Example Source Files (CMake) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl3_wgpu/CMakeLists.txt Sets the list of source files for ImGui example commons. This includes main application file, backend implementations for SDL3 and WGPU, and core Dear ImGui files. This configuration is fundamental for building the ImGui examples. ```cmake set(IMGUI_EXAMPLE_SOURCE_FILES main.cpp # backend files ${IMGUI_DIR}/backends/imgui_impl_sdl3.cpp ${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp # Dear ImGui files ${IMGUI_DIR}/imgui.cpp ${IMGUI_DIR}/imgui_draw.cpp ${IMGUI_DIR}/imgui_demo.cpp ${IMGUI_DIR}/imgui_tables.cpp ${IMGUI_DIR}/imgui_widgets.cpp ) ``` -------------------------------- ### Set up Executable Target and Include Directories (CMake) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_wgpu/CMakeLists.txt This CMake snippet defines the main executable for the ImGui example and specifies the necessary include directories. It ensures that ImGui headers and backend headers are accessible during compilation. ```cmake add_executable(${IMGUI_EXECUTABLE} ${IMGUI_EXAMPLE_SOURCE_FILES}) target_include_directories(${IMGUI_EXECUTABLE} PUBLIC ${IMGUI_DIR} ${IMGUI_DIR}/backends ${SDL2_INCLUDE_DIRS} ) ``` -------------------------------- ### SDL3 Example Initialization Update Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/CHANGELOG.txt Updates the SDL3 examples to reflect API changes where SDL_Init() now returns 0 on failure. This ensures correct error handling during SDL initialization in the examples. ```c++ Examples: SDL3: Update for API changes: SDL_Init() returns 0 on failure. ``` -------------------------------- ### Update SDL3 Example Backend Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/CHANGELOG.txt This update modifies the SDL3 example backend to align with the latest changes in the WIP SDL3 branch. This ensures that the example code remains compatible with ongoing development of the SDL3 library. ```c++ // Updated for latest WIP SDL3 branch. ``` -------------------------------- ### Traditional Toolkit Button and Slider Example Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/FAQ.md Illustrates idiomatic code for creating a button and a slider using a traditional UI toolkit. This method involves object instantiation, explicit event handling (OnClick), and data binding, requiring more setup and state management compared to Dear ImGui. ```cpp UiButton* button = new UiButton("Save"); button->OnClick = &MySaveFunction; parent->Add(button); UiSlider* slider = new UiSlider("Slider"); slider->SetRange(0.0f, 1.0f); slider->BindData(&m_MyValue); parent->Add(slider); ``` -------------------------------- ### ImGui Example Commons Source Files Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_wgpu/CMakeLists.txt Defines the list of source files for the ImGui example commons. This includes the main C++ file, backend implementations for SDL2 and WGPU, and core ImGui source files. These files are essential for compiling and running ImGui examples. ```cmake set(IMGUI_EXAMPLE_SOURCE_FILES main.cpp # backend files ${IMGUI_DIR}/backends/imgui_impl_sdl2.cpp ${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp # Dear ImGui files ${IMGUI_DIR}/imgui.cpp ${IMGUI_DIR}/imgui_draw.cpp ${IMGUI_DIR}/imgui_demo.cpp ${IMGUI_DIR}/imgui_tables.cpp ${IMGUI_DIR}/imgui_widgets.cpp ) ``` -------------------------------- ### Emscripten Platform Layer Example Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/TODO.txt This snippet references an example demonstrating how to provide a direct `imgui_emscripten` platform layer, particularly when refactoring examples. It points to an external GitHub Gist as a reference for implementation, suggesting a flexible approach for Emscripten integration. ```c++ // see eg. https://github.com/floooh/sokol-samples/blob/master/html5/imgui-emsc.cc#L42 ``` -------------------------------- ### Win32+OpenGL3 Example Update for Window Procedure Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/CHANGELOG.txt The Win32+OpenGL3 example has been updated to use DefWindowProcW() instead of DefWindowProc(). This change ensures consistency with other examples and provides support for compiling the example app without UNICODE. ```cpp // Examples: Win32+OpenGL3: Changed DefWindowProc() to DefWindowProcW() to match other examples // and support the example app being compiled without UNICODE. (#6516, #5725, #5961, #5975) [@yenixing] ``` -------------------------------- ### Serve Emscripten Build Locally Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_opengl3/README.md Starts a local web server using Python 3 to serve the Emscripten build output. Allows testing the WebAssembly application in a browser. ```bash make -f Makefile.emscripten serve ``` -------------------------------- ### mimgui Essential Dependencies and Setup in Lua Source: https://github.com/votingllm-max/blastlibs/blob/main/mimgui/mimguillms.txt This snippet demonstrates how to load the necessary mimgui library and its dependencies like ffi, vkeys, windows.message, and encoding. It also shows the basic setup for initializing mimgui, disabling INI file saving, and defining the main window's visibility condition. ```lua local imgui = require 'mimgui' local ffi = require 'ffi' local vkeys = require 'vkeys' local wm = require 'windows.message' local encoding = require 'encoding' encoding.default = 'CP1251' local u8 = encoding.UTF8 local new = imgui.new local renderWindow = new.bool(false) imgui.OnInitialize(function() imgui.GetIO().IniFilename = nil end) ``` -------------------------------- ### Makefile for Apple Examples Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/CHANGELOG.txt Addition of Makefiles for Apple+Metal and Apple+OpenGL examples, improving their compatibility with CLion and other build environments. ```makefile /* Examples: Apple+Metal, Apple+OpenGL: add Makefile (CLion opens them nicely). */ ``` -------------------------------- ### ImGui Backend Refactoring Example Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/CHANGELOG.txt Illustrates the refactoring of ImGui example backends to separate platform and renderer code. This change aims to reduce redundancy and improve reusability, making it easier to combine and maintain backends for features like multi-viewport support. ```text before: imgui_impl_dx11.cpp --> after: imgui_impl_win32.cpp + imgui_impl_dx11.cpp before: imgui_impl_dx12.cpp --> after: imgui_impl_win32.cpp + imgui_impl_dx12.cpp before: imgui_impl_glfw_gl3.cpp --> after: imgui_impl_glfw.cpp + imgui_impl_opengl2.cpp before: imgui_impl_glfw_vulkan.cpp --> after: imgui_impl_glfw.cpp + imgui_impl_vulkan.cpp before: imgui_impl_sdl_gl3.cpp --> after: imgui_impl_sdl2.cpp + imgui_impl_opengl2.cpp before: imgui_impl_sdl_gl3.cpp --> after: imgui_impl_sdl2.cpp + imgui_impl_opengl3.cpp ``` -------------------------------- ### Serve Emscripten Build with Python 2 Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_opengl3/README.md Manually starts a local web server using Python 2's built-in SimpleHTTPServer module to serve files from the 'web' directory. ```bash cd web && python -m SimpleHTTPServer ``` -------------------------------- ### CMake Configuration for ImGui Example SDL3 WGPU Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl3_wgpu/CMakeLists.txt Core CMake configuration file for the ImGui Example SDL3 WGPU project. It sets the minimum CMake version, project name, and C++ standard. It also configures Dear ImGui's directory and ensures a build type is set if not specified. ```cmake cmake_minimum_required(VERSION 3.22) project(imgui_example_sdl3_wgpu C CXX) set(IMGUI_EXECUTABLE example_sdl3_wgpu) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE) endif() set(CMAKE_CXX_STANDARD 17) # Dear ImGui set(IMGUI_DIR "../../") ``` -------------------------------- ### Serve Emscripten Build with Python 3 Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_opengl3/README.md Manually starts a local web server using Python 3's built-in http.server module to serve files from the 'web' directory. ```bash python -m http.server -d web ``` -------------------------------- ### CMake Configuration for ImGui Example SDL2 WGPU Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_wgpu/CMakeLists.txt This CMakeLists.txt file configures the build for the ImGui example SDL2 WGPU application. It sets the minimum CMake version, project name, executable name, build type, C++ standard, and specifies the Dear ImGui directory. ```cmake cmake_minimum_required(VERSION 3.22) # Dawn requires CMake >= 3.22 project(imgui_example_sdl2_wgpu C CXX) set(IMGUI_EXECUTABLE example_sdl2_wgpu) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE) endif() set(CMAKE_CXX_STANDARD 17) # Dawn requires C++17 # Dear ImGui set(IMGUI_DIR ../../) ``` -------------------------------- ### Configure WGPU-Native Libraries (CMake) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_wgpu/CMakeLists.txt This snippet configures the build for WGPU-Native, finding the necessary library and setting up platform-specific OS libraries. It's used when building for native platforms without Emscripten. ```cmake set(WGPU_NATIVE_LIB_DIR ${IMGUI_WGPU_DIR}/lib) find_library(WGPU_LIBRARY NAMES libwgpu_native.a wgpu_native.lib wgpu_native HINTS ${WGPU_NATIVE_LIB_DIR} REQUIRED) if(WIN32) set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32 Propsys RuntimeObject) elseif(UNIX AND NOT APPLE) set(OS_LIBRARIES "-lm -ldl") endif() set(LIBRARIES ${WGPU_LIBRARY} ${OS_LIBRARIES}) ``` -------------------------------- ### RakLua API Overview Source: https://github.com/votingllm-max/blastlibs/blob/main/RakLua/rakluallms.txt This section provides an overview of the RakLua library, its purpose, and how to get started. ```APIDOC ## RakLua Library Overview A Lua library for MoonLoader that replaces SAMPFUNCS events and functions for interacting with RakNet and BitStream. Uses `sol3` for C++ binding and supports multiple SAMP versions (0.3.7 R1, R2, R3-1, R4-2, R5-1) without SAMPFUNCS dependency. ### Dependencies To use RakLua, you need to require it: ```lua local RakLua = require 'RakLua' ``` ### Boilerplate Example This example demonstrates how to register an incoming RPC handler and process a server message: ```lua local RakLua = require 'RakLua' function main() -- Register Incoming RPC Handler RakLua.registerHandler(RakLuaEvents.INCOMING_RPC, function(id, bs) if id == 93 then -- RPC_ClientMessage local color = bs:readInt32() local len = bs:readInt32() local text = bs:readString(len) print("Server Message: " .. text) -- Block specific message if text:find("BlockMe") then return false end -- Modify message (Example: Change color) bs:resetWritePointer() bs:writeInt32(-1) -- White color bs:writeInt32(len) bs:writeString(text) -- No return needed if modifying in-place without return table logic end end) wait(-1) end ``` ``` -------------------------------- ### MoonBot Library Boilerplate Example Source: https://github.com/votingllm-max/blastlibs/blob/main/moonbot/moonllms.txt A fundamental Lua example demonstrating the setup and usage of the MoonBot library. It includes registering callbacks for RPCs and packets, defining chat commands to add and remove bots, and preventing script termination. ```lua local mb = require('MoonBot') -- Callback for incoming RPCs to the BOT function onBotRPC(bot, rpcId, bs) -- bot: Bot Handle -- rpcId: Integer -- bs: BitStream object (must be read using MoonBot's bs methods) print(string.format('Bot %s received RPC: %d', bot.name, rpcId)) end -- Callback for incoming Packets to the BOT function onBotPacket(bot, packetId, bs) if packetId == 41 then print(string.Format("Bot %s connected with ID %d", bot.name, bot.playerID)) end end function main() -- Register commands sampRegisterChatCommand('bot.add', cmdAddBot) sampRegisterChatCommand('bot.remove', cmdRemoveBot) -- Prevent script termination wait(-1) end function cmdAddBot(arg) -- Add a bot (name is optional, generates "UnnamedINDEX" if empty) local bot = mb.add(arg) -- Connect the bot (auto-detects server IP/Port) bot:connect() -- Optional: Connect as NPC (Bypass anti-cheat) -- bot:connectAsNPC(true) print(string.Format('Connecting bot: %s (Index: %d)', bot.name, bot.index)) end function cmdRemoveBot(arg) local index = tonumber(arg) if index then local bot = mb.getBotHandleByIndex(index) if bot then print("Removing bot: " .. bot.name) mb.remove(index) end end end ``` -------------------------------- ### Moon ImGui Boilerplate and Basic Window Example Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/imguillms.txt A foundational code snippet demonstrating how to set up Moon ImGui, initialize global variables for GUI state, and create a simple window with text, a button, and an input field. It also includes logic for toggling the GUI's visibility and processing its events. ```lua local imgui = require 'imgui' local key = require 'vkeys' -- Initialize pointer-like variables globally local main_window_state = imgui.ImBool(false) local text_buffer = imgui.ImBuffer(256) function imgui.OnDrawFrame() -- Only render if state is true if main_window_state.v then -- Set window size/pos (Optional) imgui.SetNextWindowSize(imgui.ImVec2(300, 200), imgui.Cond.FirstUseEver) -- Pass the boolean object to Begin to handle the "X" close button imgui.Begin('My Window', main_window_state) imgui.Text('Hello World') if imgui.Button('Press Me') then print('Button pressed') end imgui.InputText('Input', text_buffer) imgui.Text('You wrote: ' .. text_buffer.v) imgui.End() end end function main() while true do wait(0) -- Toggle GUI visibility if wasKeyPressed(key.VK_X) then main_window_state.v = not main_window_state.v end -- Link imgui processing to the window state -- When false, OnDrawFrame is not called imgui.Process = main_window_state.v end end ``` -------------------------------- ### Build imgui_example_glfw_wgpu with WGPU-Native Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_glfw_wgpu/CMakeLists.txt Steps to build the example using WGPU-Native, a cross-platform native implementation of the WebGPU API. This involves downloading pre-built binaries for your platform and specifying their location using the IMGUI_WGPU_DIR CMake variable. ```bash # Download WGPU-Native autogenerated binary modules for your platform/compiler from: https://github.com/gfx-rs/wgpu-native/releases # unzip the downloaded file in your_preferred_folder cmake -B build -DIMGUI_WGPU_DIR=your_preferred_folder cmake --build build ``` -------------------------------- ### Dear ImGui Button and Slider Example Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/FAQ.md Demonstrates idiomatic Dear ImGui code for creating a button and a slider. This approach is characterized by its simplicity and direct integration within the application's logic loop, where UI elements are issued on every update. ```cpp if (ImGui::Button("Save")) MySaveFunction(); ImGui::SliderFloat("Slider", &m_MyValue, 0.0f, 1.0f); ``` -------------------------------- ### Basic ImGui Widgets Example (C++) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/README.md Demonstrates the usage of fundamental Dear ImGui widgets such as Text, Button, InputText, and SliderFloat. These functions are called within the application's main loop to display and interact with UI elements. No specific input/output is defined beyond the visual display and user interaction. ```cpp ImGui::Text("Hello, world %d", 123); if (ImGui::Button("Save")) MySaveFunction(); ImGui::InputText("string", buf, IM_COUNTOF(buf)); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); ``` -------------------------------- ### Win32+DirectX12 Example Warning Ignore Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/CHANGELOG.txt The Win32+DirectX12 example now ignores a specific D3D12_MESSAGE_ID_FENCE_ZERO_WAIT warning that can appear on startup on certain configurations. ```c++ // Win32+DirectX12: ignore seemingly incorrect D3D12_MESSAGE_ID_FENCE_ZERO_WAIT warning on startups on some setups. (#9084, #9093) ``` -------------------------------- ### Native/Desktop Build Configuration for Dear ImGui (Dawn/WGPU) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_glfw_wgpu/CMakeLists.txt This snippet handles native and desktop builds for Dear ImGui, requiring either the Dawn or WGPU base directory to be specified. It includes checks to ensure only one directory is provided and sets up platform-specific libraries and compile flags, particularly for macOS. ```cmake else() # Native/Desktop build # Check DAWN/WGPU directory if(NOT IMGUI_DAWN_DIR AND NOT IMGUI_WGPU_DIR) # if it's Native/Desktop build, IMGUI_DAWN_DIR or IMGUI_WGPU_DIR must be specified message(FATAL_ERROR "Please specify the Dawn or WGPU base directory") endif() if(IMGUI_DAWN_DIR AND IMGUI_WGPU_DIR) # both IMGUI_DAWN_DIR and IMGUI_WGPU_DIR cannot be set message(FATAL_ERROR "Please specify only one between Dawn / WGPU base directory") endif() if(APPLE) # Add SDL2 module to get Surface, with libs and file property for MacOS build set_source_files_properties(${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++") set(OS_LIBRARIES "-framework CoreFoundation -framework QuartzCore -framework Metal -framework MetalKit -framework Cocoa") endif() find_package(glfw3 REQUIRED) if(IMGUI_DAWN_DIR) # DAWN-Native build options list(APPEND CMAKE_PREFIX_PATH ${IMGUI_DAWN_DIR}) find_package(Dawn) # Search for a Dawn installation using IMGUI_DAWN_DIR in CMAKE_PREFIX_PATH if(Dawn_FOUND) message("Dawn Installation has been found!") set(LIBRARIES dawn::webgpu_dawnglfw ${OS_LIBRARIES}) else() set(IMGUI_DAWN_DIR CACHE PATH "Path to Dawn repository") option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON) set(DAWN_BUILD_MONOLITHIC_LIBRARY "STATIC" CACHE STRING "Build monolithic library: SHARED, STATIC, or OFF.") option(DAWN_USE_GLFW OFF) # disable buildin GLFW in DAWN when we use SDL2 / SDL3 # Dawn builds many things by default - disable things we don't need option(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" OFF) option(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" OFF) option(TINT_BUILD_DOCS "Build documentation" OFF) option(TINT_BUILD_TESTS "Build tests" OFF) if(NOT APPLE) option(TINT_BUILD_MSL_WRITER "Build the MSL output writer" OFF) endif() if(WIN32) option(DAWN_FORCE_SYSTEM_COMPONENT_LOAD "Allow system component fallback" ON) option(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" OFF) option(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON) option(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" OFF) option(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" OFF) option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ON) option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON) endif() # check if WAYLAND is the current Session Type and enable DAWN_USE_WAYLAND Wayland option @compile time endif() endif() endif() ``` -------------------------------- ### DPI Awareness in Examples Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/CHANGELOG.txt Examples are now DPI aware by default. For single-viewport applications, this involves querying monitor DPI scale and using style.ScaleAllSizes() with style.FontScaleDpi. Multi-viewport applications can enable io.ConfigDpiScaleFonts and io.ConfigDpiScaleViewports for font scaling. ```c++ /* Made many examples DPI aware by default. The single-viewport is basically: - Query monitor DPI scale. Helpers are provided in some backends. - Call style.ScaleAllSizes() and set style.FontScaleDpi with this factor. Multi-viewport applications may set both of those flags: - io.ConfigDpiScaleFonts = true; - io.ConfigDpiScaleViewports = true; Which will scale fonts but NOT style padding/spacings/thicknesses yet. */ ``` -------------------------------- ### Dear ImGui Source File List Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_glfw_wgpu/CMakeLists.txt This snippet defines the list of source files for the Dear ImGui library, including example code, backend implementation files for GLFW and WGPU, and core Dear ImGui source files. These are used in the build configuration. ```cmake set(IMGUI_EXAMPLE_SOURCE_FILES # Example code main.cpp # Dear ImGui Backend files ${IMGUI_DIR}/backends/imgui_impl_glfw.cpp ${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp # Dear ImGui files ${IMGUI_DIR}/imgui.cpp ${IMGUI_DIR}/imgui_draw.cpp ${IMGUI_DIR}/imgui_demo.cpp ${IMGUI_DIR}/imgui_tables.cpp ${IMGUI_DIR}/imgui_widgets.cpp ) ``` -------------------------------- ### Native/Desktop Build Configuration for ImGui with Dawn/WGPU Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_wgpu/CMakeLists.txt Configures the build for native/desktop environments, requiring either Dawn or WGPU to be specified. It includes platform-specific adjustments for macOS and handles the discovery and configuration of the Dawn library. Dependencies like SDL2 and Threads are found using CMake's find_package. ```cmake else() # Native/Desktop build if(NOT IMGUI_DAWN_DIR AND NOT IMGUI_WGPU_DIR) # if it's Native/Desktop build, IMGUI_DAWN_DIR or IMGUI_WGPU_DIR must be specified message(FATAL_ERROR "Please specify the Dawn or WGPU base directory") endif() if(IMGUI_DAWN_DIR AND IMGUI_WGPU_DIR) # both IMGUI_DAWN_DIR and IMGUI_WGPU_DIR cannot be set message(FATAL_ERROR "Please specify only one between Dawn / WGPU base directory") endif() if(APPLE) # Add SDL2 module to get Surface, with libs and file property for MacOS build set_source_files_properties(${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++") set(OS_LIBRARIES "-framework CoreFoundation -framework QuartzCore -framework Metal -framework MetalKit -framework Cocoa") endif() find_package(SDL2 REQUIRED) # SDL_MAIN_HANDLED if(IMGUI_DAWN_DIR) # DAWN-Native build options list(APPEND CMAKE_PREFIX_PATH ${IMGUI_DAWN_DIR}) find_package(Threads) # required from Dawn installation find_package(Dawn) # Search for a Dawn installation using IMGUI_DAWN_DIR in CMAKE_PREFIX_PATH if(Dawn_FOUND) message("Dawn Installation has been found!") set(LIBRARIES dawn::webgpu_dawn ${OS_LIBRARIES}) else() set(IMGUI_DAWN_DIR CACHE PATH "Path to Dawn repository") option(DAWN_USE_GLFW OFF) # disable buildin GLFW in DAWN when we use SDL2 / SDL3 option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON) set(DAWN_BUILD_MONOLITHIC_LIBRARY "STATIC" CACHE STRING "Build monolithic library: SHARED, STATIC, or OFF.") # Dawn builds many things by default - disable things we don't need option(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" OFF) option(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" OFF) option(TINT_BUILD_DOCS "Build documentation" OFF) option(TINT_BUILD_TESTS "Build tests" OFF) if(NOT APPLE) option(TINT_BUILD_MSL_WRITER "Build the MSL output writer" OFF) endif() if(WIN32) option(DAWN_FORCE_SYSTEM_COMPONENT_LOAD "Allow system component fallback" ON) option(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" OFF) option(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON) option(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" OFF) option(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" OFF) option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ON) option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON) endif() # check if WAYLAND is the current Session Type and enable DAWN_USE_WAYLAND Wayland option @compile time # You can override this using: cmake -DDAWN_USE_WAYLAND=X (X = ON | OFF) if(LINUX) if($ENV{XDG_SESSION_TYPE} MATCHES wayland) option(DAWN_USE_WAYLAND "Enable support for Wayland surface" ON) endif() endif() add_subdirectory("${IMGUI_DAWN_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/dawn" EXCLUDE_FROM_ALL) set(LIBRARIES webgpu_dawn ${OS_LIBRARIES}) endif() endif() endif() ``` -------------------------------- ### Example Main Loop Rework (Throttling) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/CHANGELOG.txt Reworks the main loop in examples for GLFW, SDL2, SDL3, and Win32+OpenGL3 to properly handle window minimization. The updated loop prevents excessive CPU/GPU usage when minimized by running unthrottled code only when necessary. ```c++ Examples: GLFW (all), SDL2 (all), SDL3 (all), Win32+OpenGL3: rework examples main loop to handle minimization without burning CPU or GPU by running unthrottled code. (#7844) ``` -------------------------------- ### Show Dear ImGui Demo Window (C++) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/README.md The `ImGui::ShowDemoWindow()` function provides a comprehensive demonstration of Dear ImGui's features. This function call will render a built-in window showcasing various widgets, styles, and functionalities. The source code for the demo is located in `imgui_demo.cpp` for reference. ```cpp void ImGui::ShowDemoWindow(bool* p_open = NULL); // Source file: imgui_demo.cpp ``` -------------------------------- ### Define Compiler Options for ImGui Example (CMake) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_wgpu/CMakeLists.txt This CMake code sets compiler options for the ImGui executable, applying warning level 4 on MSVC and detailed warnings on other compilers. This helps catch potential issues during development. ```cmake # compiler option only for IMGUI_EXAMPLE_SOURCE_FILES if (MSVC) target_compile_options(${IMGUI_EXECUTABLE} PUBLIC /W4) # warning level 4 else() target_compile_options(${IMGUI_EXECUTABLE} PUBLIC -Wall) # -Wextra -Wpedantic endif() ``` -------------------------------- ### Scaling UI Sizes in Dear ImGui Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/FAQ.md Illustrates how to scale all UI sizes, including paddings and thicknesses, in a single-viewport Dear ImGui application. For dynamic scaling, it suggests resetting the style and reapplying the scale factor. ```cpp style.ScaleAllSizes(factor); // call once! ``` -------------------------------- ### Remote ImGui Rendering with netImgui, Remote ImGui, and imgui-ws Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/FAQ.md Demonstrates using third-party solutions like netImgui, Remote ImGui, or imgui-ws to render Dear ImGui applications over a network. This allows Dear ImGui to be used on machines without a screen by sending rendering vertices remotely. ```cpp // Conceptual usage with a hypothetical remote ImGui library // Assumes imgui and a remote rendering library are included // Initialize ImGui and backend ImGui::CreateContext(); // ... ImGui_ImplXXX_Init() ... // Initialize remote rendering backend // remote_renderer_init(); while (true) { // ... New frame for ImGui ... ImGui::NewFrame(); // ... Your ImGui UI code ... ImGui::Begin("My Window"); ImGui::Text("Hello, Remote World!"); ImGui::End(); ImGui::Render(); ImDrawData* draw_data = ImGui::GetDrawData(); // Send draw_data to the remote renderer // remote_renderer_send_draw_data(draw_data); } // ... Cleanup ... // ImGui_ImplXXX_Shutdown(); // ImGui::DestroyContext(); // remote_renderer_shutdown(); ``` -------------------------------- ### Setting Font Sizes in Dear ImGui Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/FAQ.md Demonstrates how to set the base font size and scale all fonts in an application using Dear ImGui's style structure. This is useful for handling DPI scaling. ```cpp style.FontSizeBase = 20.0f; style.FontScaleDpi = 2.0f; ImGui::PushFont(NULL, 42.0f); // This will be multiplied by style.FontScaleDpi ImGui::PushFont(new_font, 42.0f); ``` -------------------------------- ### mimgui String Handling and Encoding in Lua Source: https://github.com/votingllm-max/blastlibs/blob/main/mimgui/mimguillms.txt This snippet demonstrates how to handle strings with mimgui, specifically for Cyrillic characters using UTF-8 encoding. It shows an example of an input field where user input is read as a UTF-8 buffer and then decoded back to CP1251 for MoonLoader compatibility. It also includes a button example. ```lua local inputField = imgui.new.char[256]() -- Assuming inputField is declared elsewhere -- Input Widget Example if imgui.InputText(u8"Введите текст", inputField, ffi.sizeof(inputField)) then local text = u8:decode(ffi.string(inputField)) -- Convert UTF-8 buffer to CP1251 print(text) end -- Button with text if imgui.Button(u8"Нажать меня") then imgui.StrCopy(inputField, "") -- Clear buffer end ``` -------------------------------- ### GLFW Subdirectory and Include Paths Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_glfw_vulkan/CMakeLists.txt Integrates the GLFW library into the build by adding its directory as a subdirectory and including its header files. Options are set to disable building examples, tests, and documentation for GLFW itself, focusing solely on its use as a dependency. The GLFW_DIR variable should be set to the correct path of the GLFW repository. ```cmake # GLFW if(NOT GLFW_DIR) set(GLFW_DIR ../../../glfw) # Set this to point to an up-to-date GLFW repo endif() option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" OFF) option(GLFW_BUILD_TESTS "Build the GLFW test programs" OFF) option(GLFW_BUILD_DOCS "Build the GLFW documentation" OFF) option(GLFW_INSTALL "Generate installation target" OFF) option(GLFW_DOCUMENT_INTERNALS "Include internals in documentation" OFF) add_subdirectory(${GLFW_DIR} binary_dir EXCLUDE_FROM_ALL) include_directories(${GLFW_DIR}/include) ``` -------------------------------- ### mimgui API Differences and ListBox Example in Lua Source: https://github.com/votingllm-max/blastlibs/blob/main/mimgui/mimguillms.txt This section highlights key differences between mimgui's API and the C++ Dear ImGui. It points out the use of the `imgui` namespace, the absence of prefixes for enums, and the requirement to use FFI arrays for elements like ListBox. A practical example of using `imgui.ListBoxStr_arr` is provided. ```lua local itemsList = {"One", "Two", "Three"} local items = imgui.new['const char*'][#itemsList](itemsList) local currentInt = imgui.new.int(0) imgui.ListBoxStr_arr("List", currentInt, items, #itemsList) ``` -------------------------------- ### ImGui TreeNodeFlags Example Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/CHANGELOG.txt Demonstrates how to use ImGuiTreeNodeFlags_CollapsingHeader and exclude the ImGuiTreeNodeFlags_NoTreePushOnOpen flag. This is useful when working with internal TreeNodeBehavior() to manage tree node states. ```c++ ImGuiTreeNodeFlags_CollapsingHeader & ~ImGuiTreeNodeFlags_NoTreePushOnOpen ``` -------------------------------- ### DirectX12+Win32 Sleeping Icon Check Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/docs/CHANGELOG.txt Enhanced the DirectX12+Win32 example to check for IsIconic() when the application is sleeping. This addresses scenarios where a DXGI_STATUS_OCCLUDED signal is not received when minimized. ```c++ /* Examples: DirectX12+Win32: also test for IsIconic() for sleeping since we don't seem to get a DXGI_STATUS_OCCLUDED signal when minimized. */ ``` -------------------------------- ### Configure Native WebGPU Backend (Dawn/WGPU) (CMake) Source: https://github.com/votingllm-max/blastlibs/blob/main/imgui/examples/example_sdl2_wgpu/CMakeLists.txt This CMake snippet configures the native build for WebGPU backends. It checks if Dawn or WGPU-Native is available and sets the appropriate compile definitions and link libraries. ```cmake if(NOT EMSCRIPTEN) # WegGPU-Native settings if(IMGUI_DAWN_DIR) target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_DAWN") if(NOT Dawn_FOUND) target_link_libraries(${IMGUI_EXECUTABLE} INTERFACE webgpu_cpp) endif() else() target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_WGPU") target_include_directories(${IMGUI_EXECUTABLE} PUBLIC ${IMGUI_WGPU_DIR}/include) endif() target_link_libraries(${IMGUI_EXECUTABLE} PUBLIC ${LIBRARIES} ${SDL2_LIBRARIES}) endif() ```