Old 04-13-2021, 09:44 AM   #121
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by amagalma View Post
ImGui_InputTextFlags_CharsDecimal() allows 0123456789.+-*/

Is it possible to allow only 0123456789.-? (not allow +, *, / that is)
I don't know in ImGUI functions but if there is not, you can parse the string to see if it end with + * / and remove that bit if it match. would take 1 defer cycle to be seen the effect tho.
daniellumertz is offline   Reply With Quote
Old 04-13-2021, 02:19 PM   #122
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by elcalen View Post
I've encountered a glitch while experimenting with docking my ReaImGui window. If I open a new Reaper instance, then open a script which immediately docks itself (after creating the context, before starting the main defer loop), large parts of the Reaper window suddenly turn black. Mousing over some of the black areas makes them visible again, and if I hide and re-open the docker, everything is fine again. As far as I can tell, this only happens the first time I open the script in a new Reaper session, and doesn't happen if I dock the script after it's been running for a while.
Just to be sure, are you using GNOME under Wayland or X11?

EDIT: Hmm... can't duplicate here with either. Enabling docking internally before the window is created might help. I'll edit this post with a test build later.

EDIT2: Here's a build that docks internally. It's just for testing so it always docks the context. Don't use REAPER's Dock functions with it. Do you get the same bug with that build when running the demo script? https://ci.appveyor.com/api/buildjob...mgui-x86_64.so

Quote:
Originally Posted by amagalma View Post
Is it possible to allow only 0123456789.-? (not allow +, *, / that is)
ImGui_InputDouble (with step/step_fast nil to disable the +/- buttons). +*/ are still allowed, but instead used to do math on the value.

Last edited by cfillion; 04-13-2021 at 06:07 PM.
cfillion is offline   Reply With Quote
Old 04-13-2021, 02:25 PM   #123
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by cfillion View Post
ImGui_InputDouble (with step/step_fast nil to disable the +/- buttons). +*/ are still allowed, but instead used to do math on the value.

This thing is magical wtf
daniellumertz is offline   Reply With Quote
Old 04-13-2021, 04:56 PM   #124
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

https://www.extremraym.com/cloud/rea..._PlotHistogram
I think is missing a comma there, also notice using edgemeal snipets, so maybe it is in the docs?
daniellumertz is offline   Reply With Quote
Old 04-13-2021, 05:10 PM   #125
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Is possible to change this number to a string ?

EDIT: just found that no. It can't. can't wait for people start importing ImGUI lib like ImPlot

Sorry the triple post

Last edited by daniellumertz; 04-13-2021 at 05:19 PM.
daniellumertz is offline   Reply With Quote
Old 04-14-2021, 01:26 AM   #126
elcalen
Human being with feelings
 
elcalen's Avatar
 
Join Date: Sep 2019
Location: Finland
Posts: 765
Default

Quote:
Originally Posted by cfillion View Post
Just to be sure, are you using GNOME under Wayland or X11?

EDIT: Hmm... can't duplicate here with either. Enabling docking internally before the window is created might help. I'll edit this post with a test build later.
I'm on X11. I guess it could depend on your video card/driver/OpenGL version, etc? (I'm on Nvidia, and the proprietary Nvidia drivers use their own version of OpenGL, not Mesa...)

Quote:
Originally Posted by cfillion View Post
EDIT2: Here's a build that docks internally. It's just for testing so it always docks the context. Don't use REAPER's Dock functions with it. Do you get the same bug with that build when running the demo script? https://ci.appveyor.com/api/buildjob...mgui-x86_64.so
This version appears to work without the visual glitches! So it does seem like the issue is specifically with docking the window immediately after creating a floating context.
elcalen is offline   Reply With Quote
Old 04-14-2021, 01:45 AM   #127
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Quote:
Originally Posted by daniellumertz View Post
Does the native doc also miss a comma ?
X-Raym is offline   Reply With Quote
Old 04-18-2021, 04:52 AM   #128
Rodilab
Human being with feelings
 
Rodilab's Avatar
 
Join Date: Jan 2021
Location: Paris
Posts: 255
Default JS_Dialog_BrowseFor and ReaImGui on Windows

Hi,

I take the liberty of reporting a bug with JS_Dialog_BrowseFor (Folder, OpenFiles and SaveFile) inside ReaImGui context.
It's work fin on macOs, but script crash on Windows when call JS_Dialog_BrowseFor.

Script exemple :
Code:
r = reaper
script_name = 'Test ImGui Browser'

function loop()
  -- Close Window ?
  if r.ImGui_IsCloseRequested(ctx) then
    r.ImGui_DestroyContext(ctx)
    return
  end
  
  display_w, display_h = r.ImGui_GetDisplaySize(ctx)
  r.ImGui_SetNextWindowPos(ctx,0,0)
  r.ImGui_SetNextWindowSize(ctx,display_w,display_h)
  r.ImGui_Begin(ctx,'Browse')
  
  if r.ImGui_Button(ctx,'Open File') then
    retval, fileName = r.JS_Dialog_BrowseForOpenFiles('Open File',nil,nil,nil,false)
  end
  
  if fileName then
    r.ImGui_TextWrapped(ctx,fileName)
  end
  
  -- End loop
  r.ImGui_End(ctx)
  r.defer(loop)
end

ctx = r.ImGui_CreateContext(script_name,400,150)
r.defer(loop)
Crash report :
Code:
ImGui assertion failed: (g.CurrentWindowStack.Size == 1) && "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?"
I found a solution, but it is not ideal: destroy the ImGui context before calling the JS function, then start the context again.

Code:
r = reaper
script_name = 'Test ImGui Browser'
JS_Dialog = false

function start_context()
  ctx = r.ImGui_CreateContext(script_name,400,150)
end

function loop()
  -- JS_Dialog
  if JS_Dialog == true then
    JS_Dialog = false
    r.ImGui_DestroyContext(ctx)
    retval, fileName = r.JS_Dialog_BrowseForOpenFiles('Open File',nil,nil,nil,false)
    start_context()
  end

  -- Close Window ?
  if r.ImGui_IsCloseRequested(ctx) then
    r.ImGui_DestroyContext(ctx)
    return
  end
  
  display_w, display_h = r.ImGui_GetDisplaySize(ctx)
  r.ImGui_SetNextWindowPos(ctx,0,0)
  r.ImGui_SetNextWindowSize(ctx,display_w,display_h)
  r.ImGui_Begin(ctx,'Browse')
  
  if r.ImGui_Button(ctx,'Open File') then
    JS_Dialog = true
  end
  
  if fileName then
    r.ImGui_TextWrapped(ctx,fileName)
  end
  
  -- End loop
  r.ImGui_End(ctx)
  r.defer(loop)
end

start_context()
r.defer(loop)
Any issue ?
Thanks
Rodilab is offline   Reply With Quote
Old 04-18-2021, 08:19 AM   #129
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by Rodilab View Post
I take the liberty of reporting a bug with JS_Dialog_BrowseFor (Folder, OpenFiles and SaveFile) inside ReaImGui context.
It's work fin on macOs, but script crash on Windows when call JS_Dialog_BrowseFor.
That happens because the function pauses the script but ReaImGui keeps ticking (on Windows & Linux). ReaImGui then thinks the script suddenly crashed and destroys the context. v0.2 added a check for this and pauses ReaImGui while a modal dialog blocks REAPER's main window.

That works for ShowMessageBox/GetUserInputs, however here it looks like the dialog JS_Dialog_BrowseForOpenFiles opens is not properly modal as it does not set the main window as parent.

A better approach would probably be to replace that with a manual function that suspends rendering and garbage collection until the next call (but let users destroy the context by closing the window during that time)...

EDIT: Here's a build that implements the idea above.
Code:
if r.ImGui_Button(ctx,'Open File') then
  r.ImGui_Freeze(ctx) -- for any contexts owned by this script
  retval, fileName = r.JS_Dialog_BrowseForOpenFiles('Open File',nil,nil,nil,false)
end

Last edited by cfillion; 04-18-2021 at 10:06 AM.
cfillion is offline   Reply With Quote
Old 04-20-2021, 11:46 AM   #130
kartalex
Human being with feelings
 
Join Date: Dec 2015
Posts: 172
Default

Hi, guys!

Cfillion, thank you for your awesome work!

By the way, could you help me?
When I insert several GUI elements into Table, the 1st cell doesn't look right, elements are not aligned with others. It works but it just looks not right..
Why this could be so?



Code:
textArr={}
local ctx = reaper.ImGui_CreateContext('My script', 300, 200)

function loop()
  local rv
  if reaper.ImGui_IsCloseRequested(ctx) then
     reaper.ImGui_DestroyContext(ctx)
     return
  end

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

    if reaper.ImGui_BeginTable(ctx, 'table1', 4, flags) then
    c=0

        for row = 0, 3 do 
            reaper.ImGui_TableNextRow(ctx)
            for column = 0, 3 do 
                c=c+1 
                reaper.ImGui_TableSetColumnIndex(ctx, column)
                reaper.ImGui_Text(ctx, row * 4  +column + 1)
                reaper.ImGui_PushID(ctx, c)
                w = reaper.ImGui_GetContentRegionAvail(ctx)
                reaper.ImGui_SetNextItemWidth(ctx, w)
                _, textArr[c] = reaper.ImGui_InputText(ctx, '##b' .. c, textArr[c]) 
                reaper.ImGui_SameLine(ctx) 
                reaper.ImGui_PopID(ctx)
            end
        end
   end
  reaper.ImGui_EndTable(ctx) 
  reaper.ImGui_End(ctx) 
  reaper.defer(loop)
end

reaper.defer(loop)

Last edited by kartalex; 04-20-2021 at 12:11 PM.
kartalex is offline   Reply With Quote
Old 04-20-2021, 02:23 PM   #131
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

I messed with you code things I found

1 If there is no text they align
2 Removing Same_Line() will make the out align repeat every line.
3 Instead of Same_Line use reaper.ImGui_NewLine(ctx) will work

I don't know why, I haven't seen the Table function good to know them!
daniellumertz is offline   Reply With Quote
Old 04-20-2021, 04:46 PM   #132
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by kartalex View Post
When I insert several GUI elements into Table, the 1st cell doesn't look right, elements are not aligned with others. It works but it just looks not right..
Why this could be so?
The text baseline is propagated for the entire row, however it is taken from the last line of the cell. There's a "FIXME" note about this in the Dear ImGui source code: https://github.com/ocornut/imgui/blo...bles.cpp#L1971.

If you're fine with a bit of extra space at the top, try calling ImGui_AlignTextToFramePadding before the first Text (see Demo > Layout & Scrolling > Text Baseline Alignment).

(Side note: because you're using PushID to add c to the ID stack, there's no need to concatenate c to '##b' for the InputText. That's what the PushID does.)

Last edited by cfillion; 04-20-2021 at 05:00 PM.
cfillion is offline   Reply With Quote
Old 04-20-2021, 06:41 PM   #133
kartalex
Human being with feelings
 
Join Date: Dec 2015
Posts: 172
Default

Quote:
Originally Posted by cfillion View Post
The text baseline is propagated for the entire row, however it is taken from the last line of the cell. There's a "FIXME" note about this in the Dear ImGui source code: https://github.com/ocornut/imgui/blo...bles.cpp#L1971.

If you're fine with a bit of extra space at the top, try calling ImGui_AlignTextToFramePadding before the first Text (see Demo > Layout & Scrolling > Text Baseline Alignment).

(Side note: because you're using PushID to add c to the ID stack, there's no need to concatenate c to '##b' for the InputText. That's what the PushID does.)
Thanks! Now it works!

Quote:
Originally Posted by daniellumertz View Post
I messed with you code things I found

1 If there is no text they align
2 Removing Same_Line() will make the out align repeat every line.
3 Instead of Same_Line use reaper.ImGui_NewLine(ctx) will work

I don't know why, I haven't seen the Table function good to know them!
Thank you! This works too!
Wonderful!
kartalex is offline   Reply With Quote
Old 04-23-2021, 02:37 AM   #134
Rodilab
Human being with feelings
 
Rodilab's Avatar
 
Join Date: Jan 2021
Location: Paris
Posts: 255
Default

Quote:
Originally Posted by cfillion View Post
That happens because the function pauses the script but ReaImGui keeps ticking (on Windows & Linux). ReaImGui then thinks the script suddenly crashed and destroys the context. v0.2 added a check for this and pauses ReaImGui while a modal dialog blocks REAPER's main window.

That works for ShowMessageBox/GetUserInputs, however here it looks like the dialog JS_Dialog_BrowseForOpenFiles opens is not properly modal as it does not set the main window as parent.

A better approach would probably be to replace that with a manual function that suspends rendering and garbage collection until the next call (but let users destroy the context by closing the window during that time)...

EDIT: Here's a build that implements the idea above.
Code:
if r.ImGui_Button(ctx,'Open File') then
  r.ImGui_Freeze(ctx) -- for any contexts owned by this script
  retval, fileName = r.JS_Dialog_BrowseForOpenFiles('Open File',nil,nil,nil,false)
end
Wow ! Great ! Thank you cfillion.
I just tested it, indeed it works.
But there are error when the dialog is open and the ImGui window is closed. I should probably forbid the destruction of context during the freeze.

Will this feature be added in the next versions of ReaImGui?
Rodilab is offline   Reply With Quote
Old 04-23-2021, 06:15 AM   #135
Rodilab
Human being with feelings
 
Rodilab's Avatar
 
Join Date: Jan 2021
Location: Paris
Posts: 255
Default Don't block keys

When the focus is on the ImGui window, all the keyboard keys are intercepted by the script and do not arrive in Reaper.
However, if the script only needs clicks, you may want to keep using Reaper keyboard shortcuts at the same time...

How can we do it ?
Thanks in advance
Rodilab is offline   Reply With Quote
Old 04-23-2021, 07:01 AM   #136
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Actually this is not because of ImGUI. Any gfx window will intercept the keys to it.

I don't know if there is a way to pass the keys back to reaper
daniellumertz is offline   Reply With Quote
Old 04-23-2021, 02:37 PM   #137
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by Rodilab View Post
Wow ! Great ! Thank you cfillion.
I just tested it, indeed it works.
But there are error when the dialog is open and the ImGui window is closed. I should probably forbid the destruction of context during the freeze.

Will this feature be added in the next versions of ReaImGui?
Yes, this will be in the next version. It will also have a new ValidatePtr function to check whether a given context still exists.

The reason I allow users to destroy frozen contexts by closing the window is to prevent zombie contexts remaining forever open (until REAPER is restarted). Otherwise that would easily happen if a script crashes or exits between the ImGui_Freeze call and the next ImGui function call.

Quote:
Originally Posted by Rodilab View Post
When the focus is on the ImGui window, all the keyboard keys are intercepted by the script and do not arrive in Reaper.
However, if the script only needs clicks, you may want to keep using Reaper keyboard shortcuts at the same time...

How can we do it ?
Thanks in advance
Global shortcuts are not intercepted.

Last edited by cfillion; 04-23-2021 at 02:50 PM.
cfillion is offline   Reply With Quote
Old 04-23-2021, 08:37 PM   #138
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Docs problem: I think ImGui_BeginTabItem returns 2 values insterad of 1

1 an bool to say if it is open in the tab Bar
2 an bool if false user clicked in the x. to close item tab

https://www.extremraym.com/cloud/rea...i_BeginTabItem

In the line 1450 of the big exemple it is being used to say which tabs should hide

Ps: every time I use this I can't believe how fast and easy things are now, can't stop thank you enough, looking forward to the new updated O.O


Edit :

Just wanted to post a exemple of a tab if anyone want:
Code:
function GUI()
    if reaper.ImGui_IsCloseRequested(ctx) then
        reaper.ImGui_DestroyContext(ctx)
    return
    end

    local window_flags = reaper.ImGui_WindowFlags_MenuBar() | reaper.ImGui_WindowFlags_NoDecoration()
    reaper.ImGui_SetNextWindowPos(ctx, 0, 0)-- Don't really need but it makes it at 0 0 "Lock it"
    reaper.ImGui_SetNextWindowSize(ctx, reaper.ImGui_GetDisplaySize(ctx))-- Don't really need but it makes it the size of the screen
    reaper.ImGui_Begin(ctx, 'wnd', nil, window_flags)

    local gui_w, gui_h = reaper.ImGui_GetDisplaySize(ctx)
    local gui_w = gui_w - 15
    local gui_h = gui_h - 45


    ---GUI 
 
    if not groups then groups = {}; groups[1] = {} end
    if reaper.ImGui_BeginTabBar(ctx, 'Groups', reaper.ImGui_TabBarFlags_Reorderable() | reaper.ImGui_TabBarFlags_AutoSelectNewTabs() ) then
        for i,v in pairs(groups) do
            local open, keep = reaper.ImGui_BeginTabItem(ctx, i, true)
            if open then
                reaper.ImGui_Text(ctx, 'This is the '..i..' tab!\nblah blah blah blah blah')
                reaper.ImGui_EndTabItem(ctx)
            end

            if not keep then
                groups[i] = nil
                --table.remove(groups,i)
            end
        end

        if reaper.ImGui_TabItemButton(ctx, '+', reaper.ImGui_TabItemFlags_Trailing() | reaper.ImGui_TabItemFlags_NoTooltip()) then
            table.insert(groups, {})
        end
        reaper.ImGui_EndTabBar(ctx)
    end

    ----
    reaper.ImGui_End(ctx)
    reaper.defer(GUI)

end

Last edited by daniellumertz; 04-23-2021 at 08:56 PM.
daniellumertz is offline   Reply With Quote
Old 04-23-2021, 08:41 PM   #139
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

This is the case for all p_* arguments. They are read/write, but cannot be marked as such in the documentation because that would disable them from receiving nil.

See "Workarounds for REAPER API limitations" in the first post:
Quote:
Originally Posted by cfillion View Post
Read/write optional arguments are never null. To let the extension receive null, such arguments have been marked as read-only in the documentation (but are in fact modified and returned). Example: p_* arguments, such as ImGui_Begin's p_open.
cfillion is offline   Reply With Quote
Old 04-24-2021, 12:20 AM   #140
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Ahh thanks for the explanation!!

I created a renamed tab

Code:
function ChangeColorTab(H,S,V,A)
    reaper.ImGui_PushID(ctx, 3)
    local button = reaper.ImGui_ColorConvertHSVtoRGB( H, S, V, A)
    local act_hover =  reaper.ImGui_ColorConvertHSVtoRGB( H, S , (V+0.4 < 1) and V+0.4 or 1 , A)
    reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Tab(),  button)
    reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_TabHovered(), act_hover)
    reaper.ImGui_PushStyleColor(ctx,  reaper.ImGui_Col_TabActive(),  act_hover)
end

BlankGroup = {} -- To create a group with all things it needs
BlankGroup.__index = BlankGroup
function BlankGroup:Create(name)
    local temp = {
        name = name or "Gteste"  
    }
    setmetatable(temp,BlankGroup)
    return temp
end
--[[ 
function CreateGroup() -- Not used REMOVE
    local blank_groups = {}
    blank_groups.name= "G"..#groups+1
    return blank_groups
end ]]

function GUI()
    if reaper.ImGui_IsCloseRequested(ctx) then
        reaper.ImGui_DestroyContext(ctx)
    return
    end

    local window_flags = reaper.ImGui_WindowFlags_MenuBar() | reaper.ImGui_WindowFlags_NoDecoration()
    reaper.ImGui_SetNextWindowPos(ctx, 0, 0)-- Don't really need but it makes it at 0 0 "Lock it"
    reaper.ImGui_SetNextWindowSize(ctx, reaper.ImGui_GetDisplaySize(ctx))-- Don't really need but it makes it the size of the screen
    reaper.ImGui_Begin(ctx, 'wnd', nil, window_flags)

    local gui_w, gui_h = reaper.ImGui_GetDisplaySize(ctx)
    local gui_w = gui_w - 15
    local gui_h = gui_h - 45


    ---GUI 
    
    if not groups then groups = {}; groups[1] = BlankGroup:Create('G1') end
    if reaper.ImGui_BeginTabBar(ctx, 'Groups', reaper.ImGui_TabBarFlags_Reorderable() | reaper.ImGui_TabBarFlags_AutoSelectNewTabs() ) then
        for i,v in pairs(groups) do
            ChangeColorTab((0.05*i),1,0.4,1)
            local open, keep = reaper.ImGui_BeginTabItem(ctx, ('%s###tab%d'):format(groups[i].name, i), true)
            if reaper.ImGui_BeginPopupContextItem(ctx) then
                reaper.ImGui_Text(ctx, 'Edit name:')
                retorno, groups[i].name = reaper.ImGui_InputText(ctx, "", groups[i].name)
                reaper.ImGui_EndPopup(ctx)
            end

            if open then
                reaper.ImGui_Text(ctx, 'This is the '..i..' tab!\nblah blah blah blah blah')
                reaper.ImGui_EndTabItem(ctx)
            end

            if not keep then
                groups[i] = nil
            end
            reaper.ImGui_PopStyleColor(ctx, 3); reaper.ImGui_PopID(ctx)

            
        end

        if reaper.ImGui_TabItemButton(ctx, '+', reaper.ImGui_TabItemFlags_Trailing() | reaper.ImGui_TabItemFlags_NoTooltip()) then
            groups[Tlen(groups)+1] = BlankGroup:Create('G'..Tlen(groups)+1)
        end
        reaper.ImGui_EndTabBar(ctx)
    end

    ----
    reaper.ImGui_End(ctx)
    reaper.defer(GUI)

end

GUI()


POST EDITED!

PS: the BlankGroup is for my script, if you wanna reuse you might want to understand how it work and make a simple version just deleting this part

Last edited by daniellumertz; 04-24-2021 at 06:30 PM.
daniellumertz is offline   Reply With Quote
Old 04-24-2021, 01:41 AM   #141
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

TabBarFlags_Reorderable puts new tabs to the end. Tabs are identified by their ID which is their label (by default).

There is a syntax for specifying an ID separate from the label: label###id
Code:
reaper.ImGui_BeginTabItem(ctx, ('%s###tab%d'):format(groups[i].name, i))
(Not to be confused with the label##id syntax, which uses both sides to compute the ID.)
cfillion is offline   Reply With Quote
Old 04-24-2021, 02:53 AM   #142
Rodilab
Human being with feelings
 
Rodilab's Avatar
 
Join Date: Jan 2021
Location: Paris
Posts: 255
Default

Hi

When I set SWS "Startup actions" option with a ImGui script, script crash.
This doesn't happen with a "gfx" script.

For example, this simple script :
Code:
r = reaper

function loop()
  if r.ImGui_IsCloseRequested(ctx) or r.ImGui_IsKeyDown(ctx,53) then
    r.ImGui_DestroyContext(ctx)
    return
  end
  
  r.defer(loop)
end

ctx = r.ImGui_CreateContext('Test ImGui Start',100,100)
r.defer(loop)
Return this error :
Code:
ImGui_IsCloseRequested: expected valid ImGui_Context*, got 0x6000013d41c0
ImGui_IsKeyDown: expected valid ImGui_Context*, got 0x6000013d41c0
Basically, all ImGui functions return an error.
Do you know why ?

Thanks
Rodilab is offline   Reply With Quote
Old 04-24-2021, 02:54 PM   #143
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by cfillion View Post
TabBarFlags_Reorderable puts new tabs to the end. Tabs are identified by their ID which is their label (by default).

There is a syntax for specifying an ID separate from the label: label###id
Code:
reaper.ImGui_BeginTabItem(ctx, ('%s###tab%d'):format(groups[i].name, i))
(Not to be confused with the label##id syntax, which uses both sides to compute the ID.)
ohhh I have stumble across the ### in the ReaImGui_Demo yesteday doing this, I should have notice it better, thanks a lot for pointing it out to me ! Will update de code in the post above in one sec. Thankssss
daniellumertz is offline   Reply With Quote
Old 04-24-2021, 05:15 PM   #144
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by Rodilab View Post
When I set SWS "Startup actions" option with a ImGui script, script crash.

Basically, all ImGui functions return an error.
Do you know why ?
Fixing for next version, thanks!

This is what happens:
Code:
Timer cycle 1 (T=0ms)
|- Script defer callbacks
|- SWS startup action
|- |- Run script, create context
|- ReaImGui frame
|- |- Destroy unused context

Timer cycle 2 (T=30ms)
|- Script defer callbacks
|- |- Invalid ReaImGui context error
|- ReaImGui frame
Another way to trigger the problem:
Code:
reaper.defer(function()
  reaper.Main_OnCommand(reaper.NamedCommandLookup('_RS6b4644d86854e10895485f184942fb69ecc26177'), 0)
end)
As a temporary workaround until v0.3 is released, you could do something like GetTime right after the CreateContext call.

Last edited by cfillion; 04-26-2021 at 07:24 PM.
cfillion is offline   Reply With Quote
Old 04-24-2021, 06:53 PM   #145
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by X-Raym View Post
Another demo (work in progress):
A Get User Input made with ReaImGui





Compared to the regular GetUserInput window, here we have!

  • hints
  • helper question marks and tooltips
  • aligned input
  • flexible field size
Also, we have access there in other input types (like numbers, etc) which can prevent some sanitization steps.
Hey xraym when you end can you post the code here? I can recreate this but would like to study how you made
daniellumertz is offline   Reply With Quote
Old 04-24-2021, 07:16 PM   #146
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

cfillion: I swear I looked at the ImGUI git to try to understand, I now get the Push/Pop ID, but what the Push/PopStyleColor serves for? I am just adding it in the code but I might be best to me understand them first...

And why the second input of ImGui_PopStyleColor is normally 3 ?
daniellumertz is offline   Reply With Quote
Old 04-24-2021, 07:27 PM   #147
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

PushStyleColor changes a color (eg. button background) and saves the previous value. PopStyleColor restores the saved value. The second argument of PopStyleColor is a shortcut for undoing multiple PushStyleColor at once.

Code:
red   = 0xFF0000FF
green = 0x00FF00FF
blue  = 0x0000FFFF

reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), red)
reaper.ImGui_Button(ctx, 'Red##r1')
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), green)
reaper.ImGui_Button(ctx, 'Green')
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), blue)
reaper.ImGui_Button(ctx, 'Blue')
reaper.ImGui_PopStyleColor(ctx, 2) -- undo blue and green
reaper.ImGui_Button(ctx, 'Red##r2')
reaper.ImGui_PopStyleColor(ctx)    -- undo red
reaper.ImGui_Button(ctx, 'Default')
EDIT: Tweaking the documentation to read "Modify a style color. Call ImGui_PopStyleColor to undo after use (before the end of the frame). See ImGui_Col_* for available style colors.".

Last edited by cfillion; 04-24-2021 at 08:26 PM.
cfillion is offline   Reply With Quote
Old 04-24-2021, 08:21 PM   #148
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Ohhh got it so I always need to undo before the next frame. I think I might do something like
Code:
CounterStyle = 0 -- to undo Styles
function ChangeColor(H,S,V,A)
    local button = reaper.ImGui_ColorConvertHSVtoRGB( H, S, V, A)
    local hover =  reaper.ImGui_ColorConvertHSVtoRGB( H, S , (V+0.4 < 1) and V+0.4 or 1 , A)
    local active = reaper.ImGui_ColorConvertHSVtoRGB( H, S, (V+0.2 < 1) and V+0.2 or 1 , A)
    reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(),  button)
    reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_ButtonHovered(), hover)
    reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_ButtonActive(),  active)
    CounterStyle = CounterStyle + 3
end

--and at the end of the GUI 

reaper.ImGui_PopStyleColor(ctx,CounterStyle )
CounterStyle  = 0
So I don't need to keep calling PopStyleColor in the middle

Last edited by daniellumertz; 04-24-2021 at 08:52 PM.
daniellumertz is offline   Reply With Quote
Old 04-24-2021, 08:44 PM   #149
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Yeah, that works fine. For complex code the best practice would be to undo the changes after use (eg. at the end of a function, section or window). This is so that subsequent parts of the script don't have to deal with leftover settings from a previous section. Also to reserve less memory if doing thousands of pushes per frame (it's 20 bytes per active color change + headroom).

Last edited by cfillion; 04-24-2021 at 09:18 PM.
cfillion is offline   Reply With Quote
Old 04-24-2021, 08:51 PM   #150
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Oh, I was wondering what drawbacks I might get from this, I might decide per case then what should I do, the worst scenario would be end up in a macaronni of code pushing and poping styles
daniellumertz is offline   Reply With Quote
Old 04-25-2021, 12:57 AM   #151
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

I just discovered by accident

I was doing some simple math to get the precise width to a widget have the whole window and be resizable.

Like
Code:
 
gui_w = reaper.ImGui_GetWindowContentRegionWidth(ctx)
reaper.ImGui_Button(ctx, "but", gui_w- reaper.ImGui_GetCursorPosX( ctx ), 0) --  reaper.ImGui_GetCursorPosX( ctx ) is the current indention
but I just discovered, I can use a negative value to the width and it will calculate it from the window end !!

Code:
reaper.ImGui_Button(ctx, "but", -10, 0) -- Button that have the width of the window -10 pixels the 10 pixels indent looks nice :)



PS: Post 1000
PSS: Sorry flooding here I am doing a lot of exploration xD would be great if the imgui side release a doc, instead of having to experiment like crazy.
daniellumertz is offline   Reply With Quote
Old 04-25-2021, 05:23 AM   #152
Rodilab
Human being with feelings
 
Rodilab's Avatar
 
Join Date: Jan 2021
Location: Paris
Posts: 255
Default

Quote:
Originally Posted by cfillion View Post
Fixing for next version, thanks!

This is what happens:
Code:
Timer cycle 1 (T=0ms)
|- Script defer callbacks
|- SWS startup action
|- |- Run script, create context
|- ReaImGui frame
|- |- Destroy unused context

Timer cycle 2 (T=33ms)
|- Script defer callbacks
|- |- Invalid ReaImGui context error
|- ReaImGui frame
Another way to trigger the problem:
Code:
reaper.defer(function()
  reaper.Main_OnCommand(reaper.NamedCommandLookup('_RS6b4644d86854e10895485f184942fb69ecc26177'), 0)
end)
(As a temporary workaround until v0.3 is released, you could do something like IsKeyDown right after the CreateContext call.)
Thank you cfillion

Another 0.3 question :
You told me that v0.3 will change how contexts should be docked, making the current way of using the REAPER dock functions unsupported.
Could you explain how it’s will work ?
And when is the 0.3 going to release?
This is to prepare my script to be compatible when v0.3 is released
Rodilab is offline   Reply With Quote
Old 04-25-2021, 08:09 AM   #153
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by Rodilab View Post
You told me that v0.3 will change how contexts should be docked, making the current way of using the REAPER dock functions unsupported.
Could you explain how it’s will work ?
CreateContext gains an extra optional integer dock parameter and there are new GetDock/SetDock(integer) functions. The format is the same as gfx.dock: first bit is dock enable, remaining bits are docker index. Undocking by clearing the first bit rather than creating a new context (= no UI state reset).

https://github.com/cfillion/reaimgui....lua#L226-L232

Release shouldn't be far after Dear ImGui v1.83 gets released, or early May if it takes too long.

Last edited by cfillion; 04-25-2021 at 08:39 AM.
cfillion is offline   Reply With Quote
Old 04-25-2021, 10:08 AM   #154
Rodilab
Human being with feelings
 
Rodilab's Avatar
 
Join Date: Jan 2021
Location: Paris
Posts: 255
Default

Thanks
Nice feature !

I've been experimenting with ReaImGui for a few weeks now, and it's really an amazing tool, simple and powerful.
I wouldn't have been able to do the same things without it.
Thanks a lot for your work, really
Rodilab is offline   Reply With Quote
Old 04-26-2021, 07:16 AM   #155
Rodilab
Human being with feelings
 
Rodilab's Avatar
 
Join Date: Jan 2021
Location: Paris
Posts: 255
Default

Bug report :
All ReaImGui based scripts crash when launched with "Radial menu" from Lokasenna.
It seems to be the same bug as mentioned before.
Rodilab is offline   Reply With Quote
Old 04-26-2021, 12:56 PM   #156
kartalex
Human being with feelings
 
Join Date: Dec 2015
Posts: 172
Default

Hi, Guys!

Do we have some kind of circular knob widget?

Is it possible to make it?

Sliders are not always suitable..

Any ideas?
kartalex is offline   Reply With Quote
Old 04-26-2021, 01:41 PM   #157
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by kartalex View Post
Do we have some kind of circular knob widget?

Is it possible to make it?
Sure. Here's an example adapted from https://github.com/ocornut/imgui/iss...ment-268369298:



Code:
local ctx = reaper.ImGui_CreateContext('My script', 300, 120)

-- Implementing a simple custom widget using the public API.
local function MyKnob(ctx, label, p_value, v_min, v_max)
  local radius_outer = 20.0
  local pos = {reaper.ImGui_GetCursorScreenPos(ctx)}
  local center = {pos[1] + radius_outer, pos[2] + radius_outer}
  local line_height = reaper.ImGui_GetTextLineHeight(ctx)
  local draw_list = reaper.ImGui_GetWindowDrawList(ctx)
  local item_inner_spacing = {reaper.ImGui_GetStyleVar(ctx, reaper.ImGui_StyleVar_ItemInnerSpacing())}
  local mouse_delta = {reaper.ImGui_GetMouseDelta(ctx)}

  local ANGLE_MIN = 3.141592 * 0.75
  local ANGLE_MAX = 3.141592 * 2.25

  reaper.ImGui_InvisibleButton(ctx, label, radius_outer*2, radius_outer*2 + line_height + item_inner_spacing[2])
  local value_changed = false
  local is_active = reaper.ImGui_IsItemActive(ctx)
  local is_hovered = reaper.ImGui_IsItemHovered(ctx)
  if is_active and mouse_delta[1] ~= 0.0 then
    local step = (v_max - v_min) / 200.0
    p_value = p_value + (mouse_delta[1] * step)
    if p_value < v_min then p_value = v_min end
    if p_value > v_max then p_value = v_max end
    value_changed = true
  end

  local t = (p_value - v_min) / (v_max - v_min)
  local angle = ANGLE_MIN + (ANGLE_MAX - ANGLE_MIN) * t
  local angle_cos, angle_sin = math.cos(angle), math.sin(angle)
  local radius_inner = radius_outer*0.40
  reaper.ImGui_DrawList_AddCircleFilled(draw_list, center[1], center[2], radius_outer, reaper.ImGui_GetColor(ctx, reaper.ImGui_Col_FrameBg()), 16)
  reaper.ImGui_DrawList_AddLine(draw_list, center[1] + angle_cos*radius_inner, center[2] + angle_sin*radius_inner, center[1] + angle_cos*(radius_outer-2), center[2] + angle_sin*(radius_outer-2), reaper.ImGui_GetColor(ctx, reaper.ImGui_Col_SliderGrabActive()), 2.0)
  reaper.ImGui_DrawList_AddCircleFilled(draw_list, center[1], center[2], radius_inner, reaper.ImGui_GetColor(ctx, is_active and reaper.ImGui_Col_FrameBgActive() or is_hovered and reaper.ImGui_Col_FrameBgHovered() or reaper.ImGui_Col_FrameBg()), 16)
  reaper.ImGui_DrawList_AddText(draw_list, pos[1], pos[2] + radius_outer * 2 + item_inner_spacing[2], reaper.ImGui_GetColor(ctx, reaper.ImGui_Col_Text()), label)

  if is_active or is_hovered then
    local window_padding = {reaper.ImGui_GetStyleVar(ctx, reaper.ImGui_StyleVar_WindowPadding())}
    reaper.ImGui_SetNextWindowPos(ctx, pos[1] - window_padding[1], pos[2] - line_height - item_inner_spacing[2] - window_padding[2])
    reaper.ImGui_BeginTooltip(ctx)
    reaper.ImGui_Text(ctx, ('%.3f'):format(p_value))
    reaper.ImGui_EndTooltip(ctx)
  end

  return value_changed, p_value
end

function loop()
  local rv

  if reaper.ImGui_IsCloseRequested(ctx) then
    reaper.ImGui_DestroyContext(ctx)
    return
  end

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

  reaper.ImGui_NewLine(ctx)
  rv,foo = MyKnob(ctx, "Foo", foo or 0, - 50,  50)
  reaper.ImGui_SameLine(ctx)
  rv,bar = MyKnob(ctx, "Bar", bar or 0, -120, 120)
  reaper.ImGui_SameLine(ctx)
  rv,baz = MyKnob(ctx, "Baz", baz or 0,    0, 255)
  
  reaper.ImGui_End(ctx)
  
  reaper.defer(loop)
end

reaper.defer(loop)

Last edited by cfillion; 04-26-2021 at 01:51 PM.
cfillion is offline   Reply With Quote
Old 04-26-2021, 02:45 PM   #158
kartalex
Human being with feelings
 
Join Date: Dec 2015
Posts: 172
Default

Quote:
Originally Posted by cfillion View Post
Sure. Here's an example adapted from https://github.com/ocornut/imgui/iss...ment-268369298:


Cool!!!

Thanks, CFillion!
kartalex is offline   Reply With Quote
Old 04-26-2021, 02:48 PM   #159
kartalex
Human being with feelings
 
Join Date: Dec 2015
Posts: 172
Default

What about pictures (bitmaps)? We don't have them yet, right?
kartalex is offline   Reply With Quote
Old 04-26-2021, 03:58 PM   #160
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Ohhhh cool way to do lowlevel GUI inside ImGUI, thanks!!!
daniellumertz 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 10:15 PM.


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