The code below gets pretty close once I click in the top, left corner, but there's increasing drift when I move right and/or down over the listicon, suggesting I am having a scaling issue??
Can't figure it out. Any suggestion on how to achieve this are greatly appreciated!
Code: Select all
EnableExplicit
Enumeration
#MainWindow
#Popup_Window
#ListIcon
#Popup_Text
EndEnumeration
Global Popup_Active.i = #False;, i
If OpenWindow(#MainWindow, 0, 0, 400, 300, "Right-click on listicon", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(#ListIcon, 10, 10, 380, 280, "Column 1", 100)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
If EventGadget() = #ListIcon And EventType() = #PB_EventType_RightClick
; Close previous popup if it's open
If Popup_Active
CloseWindow(#Popup_Window)
Popup_Active = #False
EndIf
; Calculate screen position based on mouse location in the window
Define finalX.i = WindowX(#MainWindow) + WindowMouseX(#MainWindow)
Define finalY.i = WindowY(#MainWindow) + WindowMouseY(#MainWindow)
; Create popup window at calculated position
If OpenWindow(#Popup_Window, finalX, finalY, 150, 70, "", #PB_Window_BorderLess | #PB_Window_Tool)
SetWindowColor(#Popup_Window, RGB(240, 240, 240))
TextGadget(#Popup_Text, 10, 10, 130, 50, "Custom popup window")
Popup_Active = #True
EndIf
EndIf
Case #PB_Event_DeactivateWindow
; Close popup if it loses focus
If Popup_Active And EventWindow() = #Popup_Window
CloseWindow(#Popup_Window)
Popup_Active = #False
EndIf
Case #PB_Event_CloseWindow
If EventWindow() = #MainWindow
Break
EndIf
EndSelect
ForEver
EndIf