Skip to content

Commit

Permalink
limit context menu size based on num items
Browse files Browse the repository at this point in the history
  • Loading branch information
aquietone committed Dec 10, 2022
1 parent c89eb39 commit 33fca1a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -0,0 +1,4 @@
0.2
- Limit context menu size based on number of items
0.1
- Initial release
62 changes: 34 additions & 28 deletions condbuilder.lua
@@ -1,4 +1,4 @@
-- Macro Condition Builder v0.1 - aquietone
-- Macro Condition Builder v0.2 - aquietone
local mq = require('mq')

local isOpen = true
Expand Down Expand Up @@ -35,35 +35,41 @@ local function drawReferenceLink()
end

local function drawContextMenu()
if ImGui.BeginPopupContextItem() then
if expression:len() >= 2 and expression:sub(-2) == '${' then
-- The string ends with ${ so we can offer up some TLOs as hints
for _,tlo in ipairs(TLOOptions) do
if ImGui.Selectable(tlo) then
expression = expression .. tlo
end
local menuitems = {}
if expression:len() >= 2 and expression:sub(-2) == '${' then
-- The string ends with ${ so we can offer up some TLOs as hints
for _,tlo in ipairs(TLOOptions) do
table.insert(menuitems, tlo)
end
elseif expression:len() > 1 and expression:sub(-1) == '.' then
-- determine TLO name before the . to lookup members
local tlo = expression:match('.*[{.](.*)%.')
if mq.TLO[tlo] then
-- The string before the trailing . is a valid TLO, so we can offer up
-- the TLOs members as hints
local tlotype = mq.gettype(mq.TLO[tlo])
for i=0,300 do
local tlomember = mq.TLO.Type(tlotype).Member(i)()
table.insert(menuitems, tlomember)
end
elseif expression:len() > 1 and expression:sub(-1) == '.' then
-- determine TLO name before the . to lookup members
local tlo = expression:match('.*[{.](.*)%.')
if mq.TLO[tlo] then
-- The string before the trailing . is a valid TLO, so we can offer up
-- the TLOs members as hints
local tlotype = mq.gettype(mq.TLO[tlo])
for i=0,300 do
local tlomember = mq.TLO.Type(tlotype).Member(i)()
if tlomember and ImGui.Selectable(tlomember) then
expression = expression .. tlomember
end
end
end
if #menuitems > 20 then
ImGui.SetNextWindowSize(-1, ImGui.GetTextLineHeight()*20)
end
if ImGui.BeginPopupContextItem() then
if #menuitems == 0 then
-- Not a TLO. It could be a member or a parameter like
-- Me.CleanName. or Spawn[id 123].
-- Or it could just be something incomplete / invalid
ImGui.Text('No Suggestions')
else
for _,item in ipairs(menuitems) do
if ImGui.Selectable(item) then
expression = expression .. item
end
else
-- Not a TLO. It could be a member or a parameter like
-- Me.CleanName. or Spawn[id 123].
-- Or it could just be something incomplete / invalid
ImGui.Text('No Suggestions')
end
else
ImGui.Text('No Suggestions')

end
ImGui.EndPopup()
end
Expand Down Expand Up @@ -120,4 +126,4 @@ mq.imgui.init('condbuilder', expressionBuilder)

while isOpen do
mq.delay(1000)
end
end

0 comments on commit 33fca1a

Please sign in to comment.