Canvas based Grid gadget

Share your advanced PureBasic knowledge/code with the community.
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

@davido, Andre and KCC the great, you are welcome and thanks for the nice words :D

A new update of this gadget is available now with help file (which is really needed!), i cleaned the code a lot and fixed few glitches on the way ... see first post for the link download

Said
User avatar
OldSkoolGamer
Enthusiast
Enthusiast
Posts: 143
Joined: Mon Dec 15, 2008 11:15 pm
Location: Nashville, TN
Contact:

Re: Canvas based Grid gadget

Post by OldSkoolGamer »

Yes, this is definitely great!! Thanks for this. I'm going to replace the editable grid I have now in my current project with this one as it's much more powerful and has some features already done I need.
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

In the past days i had the chance to test more thoroughly this gadget, found few bugs and updated the help file :D
Any bug report is most welcome :)
So a revised version is available on the same github page ... see first post

Said
#NULL
Addict
Addict
Posts: 1354
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Canvas based Grid gadget

Post by #NULL »

Great work!
On linux I had to remove the constant at line 5026

Code: Select all

            MessageRequester("Error","Unable to create file ...") ; ,#MB_ICONERROR)
and I had to add a Font at line 3037

Code: Select all

            CompilerCase #PB_OS_Linux
                Protected   Font_T8    = LoadFont(#PB_Any, "Arial",11)
davido
Addict
Addict
Posts: 1847
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Canvas based Grid gadget

Post by davido »

@said,
Nice work, thank you for sharing.

@#NULL,
Also works on the Mac. Thanks for the tip.
DE AA EB
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

#NULL wrote:Great work!
On linux I had to remove the constant at line 5026

Code: Select all

            MessageRequester("Error","Unable to create file ...") ; ,#MB_ICONERROR)
and I had to add a Font at line 3037

Code: Select all

            CompilerCase #PB_OS_Linux
                Protected   Font_T8    = LoadFont(#PB_Any, "Arial",11)
Yes that constant in the test-code is a left over from previous versions, i mostly use windows but the code is made of only PB native code so it should run fine on all supported platforms :)
tangent685
New User
New User
Posts: 1
Joined: Thu Jan 04, 2018 6:00 am

Re: Canvas based Grid gadget

Post by tangent685 »

Looks good as of Jan 3 2018. Hope development continues.
mauriegio
New User
New User
Posts: 7
Joined: Fri Mar 02, 2018 9:48 am

Re: Canvas based Grid gadget

Post by mauriegio »

Hello ,

thank for the grid is very useful wonderful gadget ..

I have a problem with combobox , after resize the example the combo open is non fased
on grid.

i use purebasic 5.62 on MacOs/windows and the problem is the same ...

is possible correct them ...

thank you

Maurizio
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

mauriegio wrote:Hello ,

thank for the grid is very useful wonderful gadget ..

I have a problem with combobox , after resize the example the combo open is non fased
on grid.

i use purebasic 5.62 on MacOs/windows and the problem is the same ...

is possible correct them ...

thank you

Maurizio
Hello,

You are welcome! Can you please show the steps that lead to described 'bug' ... i am unable to see the issue?!

Said
mauriegio
New User
New User
Posts: 7
Joined: Fri Mar 02, 2018 9:48 am

Re: Canvas based Grid gadget

Post by mauriegio »

Thanks,

in the exampe if you open the windows to the max , combo box not fased when click on the arrow...

if you resize is seems ok ... but if go max ...problem

Maurizio
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

Sorry Maurizio, i am still unable to reproduce!

Even installed PB 5.62 for this, still cant reproduce ... Tested on Windows 10 (both PB 32/64) with 200 DPI screen as well

Is anyone else facing this issue? Thanks for reporting
infratec
Always Here
Always Here
Posts: 5471
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Canvas based Grid gadget

Post by infratec »

Hi said,

I just needed your code in a small project, but after implemented a 'fixed' size, I found some confusing things:

Code: Select all

#ColWidth = 40
#RowHeight = 20

#Cols = 20
#Rows = 10

Enumeration
  #Grid1
  #Grid2
EndEnumeration
  
Define.i i

IncludeFile "MyGrid.pbi"

OpenWindow(0, 0, 0, 860, 460, "Test", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)

MyGrid::New(0, #Grid1, 10, 10, (#Cols + 1) * #ColWidth, (#Rows + 1) * #RowHeight, #Rows, #Cols, #False, #False, #False)
MyGrid::SetColWidth(#Grid1, MyGrid::#RC_Any, #ColWidth)
MyGrid::SetRowHeight(#Grid1, MyGrid::#RC_Any, #RowHeight)
MyGrid::Redraw(#Grid1)

MyGrid::New(0, #Grid2, 10, 240, (#Cols + 1) * (#ColWidth - 1), (#Rows + 1) * (#RowHeight - 1), #Rows, #Cols, #False, #False, #False)
MyGrid::SetColWidth(#Grid2, MyGrid::#RC_Any, #ColWidth)
MyGrid::SetRowHeight(#Grid2, MyGrid::#RC_Any, #RowHeight)
MyGrid::Redraw(#Grid2)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
If I set the size calculation to the 'right' values (#Grid1) then it looks to big.
The 'fault' growth when I increase the rows for example.

If I fix it by using a size which is one pixel smaller (#Grid2) (maybe the border pixel),
then it looks good, but...
when I go to the lowest row, via key down, it 'jumps' one row.
Same happens to the end of the cols.

Is this 'normal' behaviour or is there a small bug inside?

Is it an inconsistent usage of ColWidth and RowHeight?
In one case with border in one without.

I use the latest version from your link in post 1.
PB 5.62 x86 on Win10 x64

P.S.: one thing I was struggling about: everywhere it is width, height
In your New it is width, height, ROWS, COLS. I first used width, height, COLS, ROWS, which was wrong :wink:

Bernd
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

Hi Bernd,

You have guessed it right, there is always 1 pixel for the border (be it horizontal or vertical)

I believe, this little jump at the end of rows/cols is due to 1 pixel missing, here is how i would use this grid with a fixed size (your example re-worked):

Code: Select all

#ColWidth = 40
#RowHeight = 20

#Cols = 20
#Rows = 10

Enumeration
  #Grid1
  #Grid2
EndEnumeration
  
Define.i i

IncludeFile "MyGrid.pbi"

OpenWindow(0, 0, 0, 860, 460, "Test", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)

; MyGrid::New(0, #Grid1, 10, 10, (#Cols + 1) * #ColWidth, (#Rows + 1) * #RowHeight, #Rows, #Cols, #False, #False, #False)
; 
; For i = 0 To #Cols
;   MyGrid::SetColWidth(#Grid1, i, #ColWidth)
; Next i
; 
; For i = 0 To #Rows
;   MyGrid::SetRowHeight(#Grid1, i, #RowHeight)
; Next i
; 
; MyGrid::Redraw(#Grid1)

; neededWidth = 

neededWidth.i = (#ColWidth * (#Cols + 1) ) - #Cols
neededHeight.i = (#RowHeight * (#Rows + 1) ) - #Rows


MyGrid::New(0, #Grid2, 10, 240, neededWidth, neededHeight, #Rows, #Cols, #False, #False, #False)

For i = 0 To #Cols
  MyGrid::SetColWidth(#Grid2, i, #ColWidth)
Next i

For i = 0 To #Rows
  MyGrid::SetRowHeight(#Grid2, i, #RowHeight)
Next i

MyGrid::Redraw(#Grid2)


Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
I hope this helps :D

Said
User avatar
the.weavster
Addict
Addict
Posts: 1378
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: Canvas based Grid gadget

Post by the.weavster »

@said

This is excellent!
Thank you very much for sharing :D
User avatar
mk-soft
Addict
Addict
Posts: 3138
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Canvas based Grid gadget

Post by mk-soft »

@said

very nice module.

Combobox works now under MacOS with Workaround for CanvasGadget

Link to FixResizeGadget: viewtopic.php?f=24&t=71269

P.S. MacOS
If the width of ScrollBarGadget to small then change the scrollbar to vertical
Fix:

Code: Select all

  Procedure.i New(WinNbr, Gadget, X, Y, W, H, Rows = 500, Cols = 100, DrawNow = #True, VerScrollBar = #True, HorScrollBar = #True, RowNumbers = #True)
    Protected *mg.TGrid, oldGdtList
    Protected ret,i,j,ttlW,ttlH,xx,yy
    
    If Not IsWindow(WinNbr) : ProcedureReturn -1 : EndIf
    If IsGadget(Gadget)     : ProcedureReturn -1 : EndIf
    
    *mg = AllocateStructure(TGrid)
    
    ; -- sub-gadgets creation
    oldGdtList = UseGadgetList(WindowID(WinNbr)) 
    ret = CanvasGadget(Gadget, X, Y, W, H, #PB_Canvas_Keyboard|#PB_Canvas_Container);|#PB_Canvas_Border)
    If Gadget = #PB_Any : Gadget = ret: EndIf
    
    *mg\RowScroll = -1
    *mg\ColScroll = -1
    If VerScrollBar
      *mg\RowScroll = ScrollBarGadget(#PB_Any,0,0,10,20,0,100,10, #PB_ScrollBar_Vertical)
      SetGadgetData(*mg\RowScroll, *mg)
      BindGadgetEvent(*mg\RowScroll, @_SynchronizeGridRows(), #PB_All)
    EndIf
    
    If HorScrollBar
      *mg\ColScroll = ScrollBarGadget(#PB_Any,0,0,20,10,0,100,10)
      SetGadgetData(*mg\ColScroll, *mg)
      BindGadgetEvent(*mg\ColScroll, @_SynchronizeGridCols(), #PB_All)
    EndIf
[/size]
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
Post Reply