In ReaImGui, which is Reaper's adaptation of Dear ImGui for creating graphical user interfaces within the context of REAPER scripts, the concept of "being redrawn" aligns with the way ImGui inherently operates. ImGui is an immediate-mode GUI library, meaning it redraws the UI every frame based on the current state and user interactions. This approach simplifies the process of creating dynamic, interactive GUIs.
To directly address the question of how to know if a ReaImGui item is being redrawn: In the context of ImGui's programming model, you don't explicitly check if an item is being redrawn in the same way you might in a traditional retained-mode GUI framework. Instead, you ensure that your rendering code (which describes the GUI) executes every frame, and ImGui takes care of the rest, determining what needs to be redrawn based on interactions and state changes.
However, if you want to track or manage updates to specific items based on user interaction or other events (which could be thought of as "knowing when an item should be redrawn"), you can do so by utilizing the return values and states of widgets. Many widgets return a value that indicates whether they have been interacted with (e.g., a button being clicked, a slider being moved). You can use these return values to determine if an item has changed state and react accordingly in your code.
Here's a simplified example of how you might use this approach to perform specific actions when a widget state changes, which indirectly relates to knowing when an item is being 'redrawn' due to interaction:
local reaper = require("reaper")
local ctx = reaper.ImGui_CreateContext('My Script')
-- Example variable to track the state of a slider
local sliderValue = 0
function loop()
-- Begin rendering the window
local visible, open = reaper.ImGui_Begin(ctx, 'My Window', true)
if visible then
-- Slider widget
local changed, newValue = reaper.ImGui_SliderInt(ctx, 'My Slider', sliderValue, 0, 100)
if changed then
-- The slider was interacted with; update the value and react to the change
sliderValue = newValue
-- Perform actions or mark that the item is effectively being 'redrawn' due to this change
end
-- Additional GUI code...
reaper.ImGui_End(ctx)
end
if open then
reaper.defer(loop)
else
reaper.ImGui_DestroyContext(ctx)
end
end
loop()
In the example above, changed will be true when the user interacts with the slider, effectively making it the point where you know the slider is being 'redrawn' due to this interaction. By utilizing such return values, you can manage and track the interaction-driven redraws of specific ReaImGui items.
Remember, in immediate-mode GUIs like ImGui/ReaImGui, your approach to GUI design focuses more on the current state and handling interactions rather than manually managing redraw operations for specific items.