Page 3 of 7

Re: Canvas based Grid gadget

Posted: Fri Mar 29, 2013 4:36 pm
by BorisTheOld
RichardL wrote:When designing a grid to be used as a data entry mechanism it is a good idea to imagine yourself as a super fast typist** who would much rather enter a new line of data without taking a hand away from the keyboard to use the mouse.
Good point, and something that should be considered for any application.

Over the past 30 years we've developed various strategies for allowing our applications to be controlled entirely from the keyboard, as well as with the more normal mouse-oriented approach. Our customers find they can get from 5 to 10 times the throughput, compared to using a mouse/keyboard.

In effect, our programs are state machines that dynamically change the functions of keys to suit the situation. The idea is to maximize performance with a minimum of hand movement.

Re: Canvas based Grid gadget

Posted: Sun Jul 07, 2013 9:35 am
by fsw
This Canvas based Grid gadget is very nicely done.

If someone needs column names to reflect more "traditional" naming convention (A, B, C.....AA, AB, AC... AAA, AAB, AAC... ZZZ) here is my version of the MyGrid_Reset() procedure:

Code: Select all

; needed for MyGrid_Reset()
#ColumnText = 65 ; "A"
#ColumnSpan = 26 ; "A" to "Z"

Procedure.i _MyGrid_Reset(*mg._MyGrid_Type, Rows, Cols)
    ; Reset everything so Grid can receive/show new data
    Protected i, factor.i, bigfactor.i
    
    If rows <= 0 : rows =1 : EndIf
    If cols <= 0 : cols =1 : EndIf
    
    *mg\Rows = rows          : Dim *mg\RowHeight(rows)
    *mg\Cols = cols          : Dim *mg\ColWidth(cols) :  Dim *mg\ColID(cols)
    
    *mg\LastIndex = (rows+1) * (cols+1) - 1
    Dim *mg\gData(*mg\LastIndex)
    If ArraySize(*mg\gData()) < 0
        Debug "failed to allocate memory for the grid data !... "
        ProcedureReturn
    EndIf
    
    ; initializations
    *mg\TopRow          = 1
    *mg\TopCol          = 1
    *mg\Row             = 1
    *mg\Col             = 1
    
    ;- set column name like a real spread sheet...
    For i=#ColumnText To #ColumnText + cols
      If i < (#ColumnText + #ColumnSpan)
        ; A to Z -> total of 26 columns... enough for small stuff.
        _MyGrid_SetCellText(*mg, 0, i - (#ColumnText -1), Chr(i))
      ElseIf i < (#ColumnText + #ColumnSpan + (#ColumnSpan * #ColumnSpan))
        ; AA to ZZ  -> 676 columns -> total of 702 columns... nice size.
        factor = Int((i - (#ColumnText + #ColumnSpan)) / #ColumnSpan) 
        Debug factor
        _MyGrid_SetCellText(*mg, 0, i - (#ColumnText -1), Chr(#ColumnText + factor) + Chr(i - #ColumnSpan * (factor + 1)))
     ElseIf i < (#ColumnText + #ColumnSpan + (#ColumnSpan * #ColumnSpan) + (#ColumnSpan * #ColumnSpan * #ColumnSpan))
        ; AAA to ZZZ  -> 17576 columns -> total of 18278 columns... that's a lot!
        factor = Int((i - (#ColumnText + #ColumnSpan)) / #ColumnSpan) 
        bigfactor = Int((i - (#ColumnText + (#ColumnSpan * #ColumnSpan) + #ColumnSpan)) / (#ColumnSpan * #ColumnSpan))
        Debug Str(factor) + " : " + Str(bigfactor)
        _MyGrid_SetCellText(*mg, 0, i - (#ColumnText -1), Chr(#ColumnText + bigfactor) + Chr(#ColumnText + factor - (#ColumnSpan * (bigfactor + 1))) + Chr(i - #ColumnSpan * (factor + 1)))
      Else
        ; AAAA to ZZZZ -> 456976 columns -> total of 475254 columns... who needs that?
        ; out of range; or bigger than 18278 columns
        _MyGrid_SetCellText(*mg, 0, i - (#ColumnText -1), "...")
      EndIf
    Next
    
    For i=1 To rows
        _MyGrid_SetCellText(*mg, i, 0, Str(i))
    Next
    
    _MyGrid_ChangeColWidth(*mg, #MyGrid_RC_Any, #MyGrid_Default_ColWidth)
    _MyGrid_ChangeRowHeight(*mg, #MyGrid_RC_Any, #MyGrid_Default_RowHeight)
    
    *mg\FrozenCol           = 0
    *mg\FrozenRow           = 0
    
    *mg\MoveStatus          = #MyGrid_MouseMove_Nothing
    *mg\PreviousX           = 0
    *mg\PreviousY           = 0
    
    *mg\NoRedraw            = #False
    
    *mg\Color_Line          = $CCCCCC
    *mg\Color_BlockBack     = $FFFFBB
    *mg\Color_Background    = $808080
    *mg\Color_FocusBack     = $DBF0E0
    *mg\Color_FocusBorder   = $009AB6
    
    *mg\WrapText            = #True
    
    ; adding the 4 default styles : data-cell/frozen-cells/col-header/row-header
    ClearList( *mg\LstStyle() )
    ClearMap(  *mg\DicStyle() )
    
    AddElement(*mg\LstStyle())      ; data area
    _MyGrid_DefineCurrentStyle(*mg, #MyGrid_Align_Center, $FFFFFF, $000000, Font_A8, 0, 1)
    
    AddElement(*mg\LstStyle())      ; frozen-data area
    _MyGrid_DefineCurrentStyle(*mg, #MyGrid_Align_Center, $D7EBFA, $000000, Font_A8, 0, 1)
    
    AddElement(*mg\LstStyle())      ; col-headers
    _MyGrid_DefineCurrentStyle(*mg, #MyGrid_Align_Center, $EB9E85, $FFFFFF, Font_A8, 0, 0)
    
    AddElement(*mg\LstStyle())      ; row-headers
    _MyGrid_DefineCurrentStyle(*mg, #MyGrid_Align_Center, $EB9E85, $FFFFFF, Font_A8, 0, 0)
    
    ; set min/max/page of scrolls
    _MyGrid_AdjustScrolls(*mg)
    
EndProcedure
For now the code covers 18278 columns...

Re: Canvas based Grid gadget

Posted: Sun Jul 07, 2013 7:32 pm
by said
@fsw: thanks for your addition (nice tip)

For those who are interested in this gadget, it has gone thru a lot of improvement since last update ... now with block selection and combo-cell ... I am just waiting for the final 5.20 to incorporate live scrolling (using BindEvent() ...) and shall soon upload inshAllah the final update!

Said

Re: Canvas based Grid gadget

Posted: Thu Aug 22, 2013 5:07 am
by IdeasVacuum
WinXP x86 PB5.20 Beta12

Hi Said

Few random things I have noticed while playing with your excellent gadget.

[1] MyGrid_SetColorAttribute():

#MyGrid_Color_FocusBack and #MyGrid_Color_FocusBorder are reversed in the *mg structure values

Would it make sense to include the default cell colours?

[2] .... you can put tick-box cells in Column 0 but they do not work.

[3] MyGrid_Col_Freeze()/MyGrid_Row_Freeze() does not?

Re: Canvas based Grid gadget

Posted: Thu Aug 22, 2013 7:07 am
by IdeasVacuum
#PB_Shortcut_Prior is now #PB_Shorcut_PageUp (corrected by Bisonte)
#PB_Shortcut_Next is now #PB_Shorcut_PageDown (corrected by Bisonte)

Edit:
.... I need to work out how to change the cell edit a little bit. If the User types in some text, it shouldn't only require a Return Key hit to confirm (I know most avid keyboard Users would probably be happy, but it's confusing for those that mostly use the mouse - mouse focus on another cell should trigger acceptance of input in previous cell).

#MyGrid_Align_Right works fine with a single line of text, but if the text wraps in the cell to two or more lines, it gets aligned left.

Re: Canvas based Grid gadget

Posted: Thu Aug 22, 2013 7:28 am
by Bisonte
Renamed: #PB_Shorcut_Prior to #PB_Shorcut_PageUp and #PB_Shorcut_Next to #PB_Shorcut_PageDown

Re: Canvas based Grid gadget

Posted: Thu Aug 22, 2013 7:37 am
by IdeasVacuum
Thanks Bisonte :)

Re: Canvas based Grid gadget

Posted: Thu Aug 22, 2013 7:47 am
by IdeasVacuum
Another question - how to define the Grid Gadget without scroll bars?

Re: Canvas based Grid gadget (revised for PB5.20)

Posted: Fri Aug 23, 2013 4:43 am
by said
Hi All,

I have updated this gadget ... see first post. It is now compatible with PB 5.20 and has many new features ....

Hi IdeasVaccum
Few random things I have noticed while playing with your excellent gadget.

[1] MyGrid_SetColorAttribute():

#MyGrid_Color_FocusBack and #MyGrid_Color_FocusBorder are reversed in the *mg structure values

Would it make sense to include the default cell colours?

[2] .... you can put tick-box cells in Column 0 but they do not work.

[3] MyGrid_Col_Freeze()/MyGrid_Row_Freeze() does not?
1. You are right, that was in old version - fixed
2. Yes Col 0 and Row 0 are hearers, you cant access them! However you can still hide them and use Col 1/Row 1 which can be editable ...
3. What is your question ? MyGrid_Col_Freeze(gadget, col) defines the col to freeze on ...
Another question - how to define the Grid Gadget without scroll bars?
While defining the grid via MyGrid_New() you can request not to add scrolls.

See notes included with MyGrid_PB520.PBI for more details about editing cells

Best,
Said

Re: Canvas based Grid gadget (revised for PB5.20)

Posted: Fri Aug 23, 2013 1:32 pm
by IdeasVacuum
Thanks Said!

Concerning the freezing, it was not working (XP x86, PB5.2 Beta12).

Re: Canvas based Grid gadget (revised for PB5.20)

Posted: Fri Aug 23, 2013 3:33 pm
by Kiffi
said wrote:I have updated this gadget
thanks a lot! Image

Greetings ... Kiffi

Re: Canvas based Grid gadget

Posted: Sat Aug 01, 2015 2:24 pm
by said
Hi All,

After 2 years! Some people are still interested in that gadget ... :D :D

Here is a slight update of the same old version (allowing to hide Focus rectangle) and moved the includes to GitHub

* MyGrid_01Aug2015.PBI
* MyGrid_PB520.PBI (the same old release of aug-2013)

Both files can be downloaded here:

https://github.com/said7/PureBasic/tree/master


First post updated as well

Said

Re: Canvas based Grid gadget

Posted: Sat Aug 01, 2015 7:08 pm
by ozzie
Many thanks, Said. Hiding the focus rectangle works perfectly!

Re: Canvas based Grid gadget

Posted: Fri Aug 14, 2015 10:48 am
by LuckyLuke
Great work ! Thanks Said!

Maybe this gadget can be added to the official Purebasic distribution ?

Re: Canvas based Grid gadget

Posted: Fri Aug 14, 2015 12:04 pm
by Fred
It's a nice work.