diff --git a/include/ui.bm b/include/ui.bm index 4ff80dd..216ff42 100644 --- a/include/ui.bm +++ b/include/ui.bm @@ -164,6 +164,7 @@ function link(x,y,label as string) if _mousex>x and _mousey>y and _mousex= ubound(commands) then exit sub + + dim done as integer: done = 0 + dim menuw as integer: menuw = 120 + dim menuh as integer: menuh = 6 * 24 + 4 ' 6 items at 24px layout spacing + + ' Position correction so context panels don't clip outside screens + dim x as integer: x = mx + if x + menuw > _width then x = _width - menuw + dim y as integer: y = my + if y + menuh > _height then y = _height - menuh + + do + ' UI Backdrop reconstruction stack to prevent flickering frames + cls, backgroundcolor1 + canvas + if showtoolbox then toolbox + if showcolorpicker then colorpicker + if state.tool = 12 then drawTextToolPanel + + ' Manual render block for command list data under the active frame + dim lx as integer: lx = _width - 250 + line (lx, 0)-(_width - 1, _height - 1), backgroundcolor1, bf + line (lx, 0)-(lx, _height - 1), backgroundcolor2 + _printmode _keepbackground + dim ly as integer, i as long + for i = ubound(commands) - 1 to 0 step -1 + ly = (ubound(commands) - i) * 16 + if ly < _height - 20 then + _printstring (lx + 5, ly + 5), left$(commands(i), 31) + end if + next i + if button(lx, _height - 25, 60, 23, "redraw") then redraw + + ' Render Context Container Box + line (x, y)-(x + menuw, y + menuh), backgroundcolor1, bf + line (x, y)-(x + menuw, y + menuh), highlightcolor, b + + ' Standard poll for incoming click state loops + while _mouseinput: wend + mouseclicked = 0: rmouseclicked = 0 + if mousedown = -1 and _mousebutton(1) = 0 then mouseclicked = -1 + if rmousedown = -1 and _mousebutton(2) = 0 then rmouseclicked = -1 + mousedown = _mousebutton(1) + rmousedown = _mousebutton(2) + + ' Clicking completely outside the menu closes the context window + if mouseclicked or rmouseclicked then + if not (_mousex > x and _mousex < x + menuw and _mousey > y and _mousey < y + menuh) then + done = -1 + end if + end if + + ' --- RENDER ENTRIES VIA UI BUTTONS --- + dim bx as integer: bx = x + 2 + dim by as integer: by = y + 2 + dim bw as integer: bw = menuw - 4 + dim bh as integer: bh = 22 + + ' Item 1: Delete + if button(bx, by, bw, bh, "Delete") then + dim k as long + for k = index to ubound(commands) - 1 + commands(k) = commands(k + 1) + next k + redim _preserve commands(ubound(commands) - 1) as string + redraw + done = -1 + end if + by = by + 24 + + ' Item 2: Move Up (moves toward end of array visually) + if button(bx, by, bw, bh, "Move Up") then + if index < ubound(commands) - 2 then + dim tempCmd as string + tempCmd = commands(index) + commands(index) = commands(index + 1) + commands(index + 1) = tempCmd + redraw + end if + done = -1 + end if + by = by + 24 + + ' Item 3: Move Down (moves toward array index 0) + if button(bx, by, bw, bh, "Move Down") then + if index > 0 then + tempCmd = commands(index) + commands(index) = commands(index - 1) + commands(index - 1) = tempCmd + redraw + end if + done = -1 + end if + by = by + 24 + + ' Item 4: Insert Above + if button(bx, by, bw, bh, "Insert Above") then + redim _preserve commands(ubound(commands) + 1) as string + for k = ubound(commands) - 1 to index + 2 step -1 + commands(k) = commands(k - 1) + next k + commands(index + 1) = "" + redraw + done = -1 + end if + by = by + 24 + + ' Item 5: Insert Below + if button(bx, by, bw, bh, "Insert Below") then + redim _preserve commands(ubound(commands) + 1) as string + for k = ubound(commands) - 1 to index + 1 step -1 + commands(k) = commands(k - 1) + next k + commands(index) = "" + redraw + done = -1 + end if + by = by + 24 + + ' Item 6: Copy to OS Clipboard + if button(bx, by, bw, bh, "Copy") then + _clipboard$ = commands(index) + done = -1 + end if + + _limit 30 + _display + loop until done or _keydown(27) + + ' Flush trailing triggers so the next loop cycle doesn't draw accidental strokes + mouseclicked = 0 + rmouseclicked = 0 +end sub + sub drawTextToolPanel dim panelWidth as integer: panelWidth = 160 dim x as integer: x = _width - panelWidth