Old 09-13-2021, 09:54 PM   #1
inframan
Human being with feelings
 
Join Date: Apr 2009
Posts: 43
Default ImGui_IsCloseRequested workaround ?

A while back I built a massive muti-use script based on the wonderful ReaImGui.

Today, after a Reapack update this script won't run - error on ImGui_IsCloseRequested. Has this been deprecated?

Basically all of my script's functionality is run by ReaImGui controls, except in Main(), where I have a function call to "app.CloseTab()" which does some crucial clean-up.

Currently, app.CloseTab() is called when variable called "app.closebutton" is set true by a certain ImGui button-press, or alternatively, as a just-in-case, by a click on the context window's OS close window button, hence my use of ImGui_IsCloseRequested.

Is there a workaround by which I can trigger the same clean-up function app.CloseTab() in case the ctx window gets closed under OS ?

Code:
local r = reaper
local ctx = r.ImGui_CreateContext('My Practice Tools', 800, 200, 800, 200, 0)

{a jillion lines removed for brevity}

function app.main()
  if r.ImGui_IsCloseRequested(ctx) or app.closebutton then
    app.CloseTab()
    r.ImGui_DestroyContext(ctx)
    return
  end

  r.ImGui_SetNextWindowPos(ctx, 0, 0)
  r.ImGui_SetNextWindowSize(ctx, r.ImGui_GetDisplaySize(ctx))
  r.ImGui_Begin(ctx, 'wnd', nil, r.ImGui_WindowFlags_NoDecoration())

  app.ShowTabWindow()

  r.ImGui_End(ctx)
  r.defer(app.main)
end
inframan is offline   Reply With Quote
Old 09-13-2021, 11:29 PM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 3,718
Default

IsCloseRequested was removed in v0.5 to support opening multiple windows per context. See https://forum.cockos.com/showthread.php?p=2455336 for upgrade tips.

Code:
local r = reaper
local ctx = r.ImGui_CreateContext('My Practice Tools')

{a jillion lines removed for brevity}

function app.main()
  r.ImGui_SetNextWindowPos(ctx, 800, 200, reaper.ImGui_Cond_FirstUseEver())
  r.ImGui_SetNextWindowSize(ctx, 800, 200, reaper.ImGui_Cond_FirstUseEver())

  local visible, open = r.ImGui_Begin(ctx, 'My Practice Tools', true)
  if visible then
    app.ShowTabWindow()
    r.ImGui_End(ctx)
  end

  if open and not app.closebutton then
    r.defer(app.main)
  else
    app.CloseTab()
    r.ImGui_DestroyContext(ctx)
  end
end

Last edited by cfillion; 09-13-2021 at 11:34 PM.
cfillion is offline   Reply With Quote
Old 09-14-2021, 06:28 PM   #3
inframan
Human being with feelings
 
Join Date: Apr 2009
Posts: 43
Default

thanks much !

Brilliant - that solves it.
inframan is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:09 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.