55
66-- This file is the Demo that comes with ReaImGui:Markdown
77
8- package.path = reaper .ImGui_GetBuiltinPath () .. ' /?.lua'
9-
10- local use_dev_folder = false
118local use_profiler = false
129local use_debugger = false
1310local do_unit_tests = false
1411
1512---- -------------
1613
17- if not use_dev_folder then
18- package.path = package.path .. " ;" .. (reaper .GetResourcePath () .. " /Scripts/ReaTeam Scripts/Development/talagan_ReaImGui Markdown" ) .. ' /?.lua'
19- else
20- package.path = package.path .. " ;" .. (reaper .GetResourcePath () .. " /Scripts/Talagan Dev/talagan_ReaImGui Markdown" ) .. ' /?.lua'
21- end
14+ local ACTION = debug.getinfo (1 ," S" ).source
15+ local ACTION_DIR = (ACTION :match [[ ^@?(.*[\/])[^\/]-$]] ):gsub (" talagan_ReaImGui Markdown/actions/$" ," /" ) -- Works both in dev and prod
2216
23- local ImGui = require " reaimgui_markdown/ext/imgui "
24- local ImGuiMd = require " reaimgui_markdown "
17+ package.path = package.path .. " ; " .. reaper . ImGui_GetBuiltinPath () .. ' /?.lua '
18+ package.path = package.path .. " ; " .. ACTION_DIR .. " talagan_ReaImGui Markdown/?.lua "
2519
26- if do_unit_tests then
27- -- Reqiore stuff for the profiler to work.
28- local UnitTest = require " reaimgui_markdown/markdown-test"
29- UnitTest ()
30- end
20+ local ImGui = require " reaimgui_markdown/ext/imgui"
21+ local ImGuiMd = require " reaimgui_markdown"
3122
3223if use_profiler then
3324 local profiler = dofile (reaper .GetResourcePath () .. ' /Scripts/ReaTeam Scripts/Development/cfillion_Lua profiler.lua' )
@@ -63,6 +54,13 @@ if use_debugger then
6354 end
6455end
6556
57+
58+ if do_unit_tests then
59+ -- Reqiore stuff for the profiler to work.
60+ local UnitTest = require " reaimgui_markdown/markdown-test"
61+ UnitTest ()
62+ end
63+
6664-- We override Reaper's defer method for two reasons :
6765-- We want the full trace on errors
6866-- We want the debugger to pause on errors
@@ -77,10 +75,6 @@ reaper.defer = function(c)
7775 end )
7876end
7977
80-
81-
82-
83-
8478local entry = [[
8579# This is a header level 1
8680## This is a header level 2
@@ -183,24 +177,47 @@ This library is **`:orange:powered`** by [ReaImGui](https://forum.cockos.com/sho
183177]]
184178
185179local ctx = ImGui .CreateContext (' ReaImGui:Markdown Demo' )
186- local imgui_md = ImGuiMd :new (ctx , " markdown_widget_1" , { wrap = true , autopad = false }, {} )
180+ local imgui_md = ImGuiMd :new (ctx , " markdown_widget_1" , { wrap = true , autopad = false , skip_last_whitespace = false , horizontal_scrollbar = true }, {} )
187181
188182imgui_md :setText (entry )
189183
190184local function loop ()
191185 ImGui .SetNextWindowSize (ctx , 600 , 800 , ImGui .Cond_FirstUseEver )
192186 local ret , open = ImGui .Begin (ctx , " ReaImGui:Markdown Demo" , true )
193-
194187 if ret then
195188
196- local b
189+ local b ,v
190+
191+ -- Option header
192+ ImGui .BeginGroup (ctx )
193+ b , v = ImGui .Checkbox (ctx , " Line wrap" , imgui_md .options .wrap )
194+ if b then imgui_md .options .wrap = v end
195+ ImGui .SameLine (ctx )
196+ b , v = ImGui .Checkbox (ctx , " Auto-Pad" , imgui_md .options .autopad )
197+ if b then imgui_md .options .autopad = v end
198+ ImGui .SameLine (ctx )
199+ b , v = ImGui .Checkbox (ctx , " Horizontal Scrollbar" , imgui_md .options .horizontal_scrollbar )
200+ if b then imgui_md .options .horizontal_scrollbar = v end
201+ ImGui .SameLine (ctx )
202+ b , v = ImGui .Checkbox (ctx , " Skip last whitespace" , imgui_md .options .skip_last_whitespace )
203+ if b then imgui_md .options .skip_last_whitespace = v end
204+ ImGui .EndGroup (ctx )
197205
198206 b , entry = ImGui .InputTextMultiline (ctx , " ##mardown_input_1" , entry , ImGui .GetContentRegionAvail (ctx ) , 200 )
199207 if b then
200208 imgui_md :setText (entry )
201209 end
202210
203- imgui_md :render (ctx )
211+ -- The rendering returns some metrics info (max_x, max_y) in case you want to resize the container
212+ -- It may also return an interaction object, when the markdown triggers auto-edit events
213+ -- So that you can patch your original string and handle the event (currently only checkboxes are handled)
214+ local max_x , maxy , interaction = imgui_md :render (ctx )
215+
216+ if interaction then
217+ local before = entry .sub (entry , 1 , interaction .start_offset - 1 )
218+ local after = entry .sub (entry , interaction .start_offset + interaction .length )
219+ entry = before .. interaction .replacement_string .. after
220+ end
204221
205222 ImGui .End (ctx )
206223 end
0 commit comments