Skip to content

Commit deabe41

Browse files
authored
Update ReaImGui Markdown v0.1.5 > v0.1.6 (#1654)
1 parent 06a4512 commit deabe41

7 files changed

Lines changed: 1128 additions & 256 deletions

File tree

‎Development/talagan_ReaImGui Markdown.lua‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
--[[
22
@description ReaImGui Markdown : A Markdown rendering library for ReaImGui
3-
@version 0.1.5
3+
@version 0.1.6
44
@author Ben 'Talagan' Babut
55
@license MIT
66
@donation https://www.paypal.com/donate/?business=3YEZMY9D6U8NC&no_recurring=1&currency_code=EUR
77
@links
88
Forum Thread https://forum.cockos.com/showthread.php?t=301055
99
@changelog
10-
- [Bug Fix] Port to ImGui 0.10 was not finished.
10+
- [Feature] Introducing first interactive widget : checkbox
11+
- [Demo] Added checkboxes to illustrate options
12+
- [Bug Fix] Better handling of interleaved inline elements
13+
- [Rework] Cleaned the AST parser a little bit
1114
@metapackage
1215
@provides
1316
[nomain] talagan_ReaImGui Markdown/reaimgui_markdown/**/*.lua

‎Development/talagan_ReaImGui Markdown/actions/talagan_ReaImGui Markdown Demo.lua‎

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,20 @@
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
118
local use_profiler = false
129
local use_debugger = false
1310
local 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

3223
if 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
6455
end
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)
7876
end
7977

80-
81-
82-
83-
8478
local 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

185179
local 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

188182
imgui_md:setText(entry)
189183

190184
local 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

‎Development/talagan_ReaImGui Markdown/reaimgui_markdown.lua‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ function ReaImGuiMd:new(ctx, id, options, style)
3838
return instance
3939
end
4040

41+
-- Possible options
42+
-------------------
43+
-- wrap (true | false)
44+
-- autopad (true | false)
45+
-- horizontal_scrollbar (true | false)
46+
-- skip_last_whitespace (true | false)
47+
-- width (0 == auto, use remaining)
48+
-- height (0 == auto, use remaining)
4149
function ReaImGuiMd:_initialize(ctx, id, options, partial_style)
4250
self.id = id
4351
self.options = { wrap = true, horizontal_scrollbar = true , width = 0, height = 0 }
@@ -122,9 +130,11 @@ function ReaImGuiMd:render(ctx)
122130
end
123131

124132
if ImGui.BeginChild(ctx, "##" .. self.id, self.options.width, self.options.height, child_flags, window_flags) then
125-
self.max_x, self.max_y = ImGuiMdCore.ASTToImgui(ctx, self.ast, self.fonts, self.style, self.options)
133+
self.max_x, self.max_y, self.interaction = ImGuiMdCore.ASTToImgui(ctx, self.ast, self.fonts, self.style, self.options)
126134
ImGui.EndChild(ctx)
127135
end
136+
137+
return self.max_x, self.max_y, self.interaction
128138
end
129139

130140
return ReaImGuiMd

0 commit comments

Comments
 (0)