[Modules] ListEx (all OS / DPI)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] ListEx (all OS / DPI)

Post by Thorsten1867 »

Paul wrote: Mon May 23, 2022 5:06 pm Yes those PB commands work on a 4K monitor but there seems to be issues with how you calculate positions and offsets and I guess you are not going to see them without using a high DPI 4K monitor.
Please try this:

Code: Select all

EnableExplicit

Define.i Event

Enumeration 
  #Window
  #Canvas
EndEnumeration

#X      = 60
#Y      = 50
#Width  = 80
#Height = 50


Procedure.i dpiX(Num.i)
  ProcedureReturn DesktopScaledX(Num) 
EndProcedure

Procedure.i dpiY(Num.i)
  ProcedureReturn DesktopScaledY(Num)  
EndProcedure

Procedure _MouseMoveHandler()
  Define.i X, Y 
  Define.i Gadget = EventGadget()
  
  If Gadget = #Canvas
    
    X = GetGadgetAttribute(Gadget, #PB_Canvas_MouseX)
    Y = GetGadgetAttribute(Gadget, #PB_Canvas_MouseY)
    
    If X > dpiX(#X) And X < dpiX(#X + #Width)
      If Y > dpiY(#Y) And Y <= dpiY(#Y + #Height)
        SetGadgetAttribute(Gadget, #PB_Canvas_Cursor, #PB_Cursor_Hand)
        GadgetToolTip(Gadget, "X: " + Str(X) + " (" + Str(DesktopUnscaledX(X)) +  ") / Y: "+Str(Y) + " (" + Str(DesktopUnscaledY(Y)) + ")")
        ProcedureReturn #True
      EndIf 
    EndIf  
    
  EndIf
  
  SetGadgetAttribute(Gadget, #PB_Canvas_Cursor, #PB_Cursor_Default)
EndProcedure  

;- ----- Main -----

If OpenWindow(#Window, 0, 0, 220, 170, "Module - Example", #PB_Window_SystemMenu|#PB_Window_Tool|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  
  If CanvasGadget(#Canvas, 10, 10, 200, 150)
    
    If StartDrawing(CanvasOutput(#Canvas)) 

      DrawingMode(#PB_2DDrawing_Outlined )
      Box(dpiX(#X), dpiY(#Y), dpiX(#Width), dpiY(#Height), #Red)
      Debug "Box X: " + Str(dpiX(#X)) + " / Y: "+ Str(dpiY(#Y))
      
      DrawingMode(#PB_2DDrawing_Outlined)
      Box(0, 0, dpiX(GadgetWidth(#Canvas)), dpiY(GadgetHeight(#Canvas)), $808080)
      
      StopDrawing()
    EndIf
    
    BindGadgetEvent(#Canvas, @_MouseMoveHandler(), #PB_EventType_MouseMove)
  EndIf

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow

  CloseWindow(#Window)
EndIf
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
blueb
Addict
Addict
Posts: 1041
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: [Modules] ListEx (all OS / DPI)

Post by blueb »

Hi Thorsten,
Is this the result you were expecting?

https://www.dropbox.com/s/qpdhp5ppi6jzi ... 1.jpg?dl=0
- It was too lonely at the top.

System : PB 6.10 Beta 9 (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: [Modules] ListEx (all OS / DPI)

Post by Paul »

Image

Hi Thorsten,
Your test code looks fine. As shown in my previous videos, the problem occurs when things are offset with either the scrollbars or resizing the columns. The calculations become incorrect.

Cheers.
Image Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] ListEx (all OS / DPI)

Post by Thorsten1867 »

The data on the picture cannot be correct.
The bottom right corner should be:
X: 245 (140) / Y: 176 (100)
However, the mouse cursor is below and to the right of this corner.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: [Modules] ListEx (all OS / DPI)

Post by Paul »

Thorsten1867 wrote: Tue May 24, 2022 6:28 pm The data on the picture cannot be correct.
The bottom right corner should be:
X: 245 (140) / Y: 176 (100)
However, the mouse cursor is below and to the right of this corner.
If I where in the exact bottom right corner it would have been 245/176 but it was difficult to hit the exact corner and the number you see in the tooltip is the last position before I bumped the cursor out of the box when hitting Print Screen ;)
Image Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] ListEx (all OS / DPI)

Post by Thorsten1867 »

Paul wrote: Tue May 24, 2022 8:05 pm If I where in the exact bottom right corner it would have been 245/176 but it was difficult to hit the exact corner and the number you see in the tooltip is the last position before I bumped the cursor out of the box when hitting Print Screen ;)
I think I found something.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
lgb-this
User
User
Posts: 28
Joined: Sat Aug 30, 2014 9:00 pm
Location: Switzerland
Contact:

Re: [Modules] ListEx (all OS / DPI)

Post by lgb-this »

Bug with #ResizeColumn:

ListExModule.pbi - date 17.7.2022 (latest version from download)

#Example = 4

1) Start test application in the module
2) Scroll down in the list with the mouse to the bottom
3) Change witdh of a column with the mouse

Problem: The list shows immediately the first row. The scrollbar stays at the correct position.

Any idea how to fix this bug ?
Post Reply