Recent

Author Topic: Progress bar in stringgrid  (Read 17154 times)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Progress bar in stringgrid
« Reply #15 on: July 17, 2021, 04:51:03 pm »
Hi!

I have a totaly different suggestion. Without a component. Just UTF8-chars.

There are the UTF8 blockchars:

Code: Pascal  [Select][+][-]
  1. '▏', //       9615    258f    left one eighth blocK      1/8
  2. '▎', //       9614    258e    left one quarter block     2/8
  3. '▍', //       9613    258d    left three eighths block   3/8
  4. '▌', //       9612    258c    left half block            4/8
  5. '▋', //       9611    258b    left five eighths block    5/8
  6. '▊', //       9610    258a    left three quarters block  6/8
  7. '▉', //       9609    2589    left seven eighths block   7/8
  8. '█' //        9608    2588    full block                 8/8      
  9.  

If you for example want to work with integer percents, you can take 1%  as the eights block and 100 %  are 12 full blocks plus one half block.

Very simple. That's the reason why I exspect the most will howl: No we dont't want that.

As always I say: KISS

Winni

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: Progress bar in stringgrid
« Reply #16 on: July 17, 2021, 05:05:57 pm »
I made this animated gif to show how my program is behaving...  the first time around it works great.  But If i process that same list again you will see the custom drawn progress bars still exist...  lol

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: Progress bar in stringgrid
« Reply #17 on: July 17, 2021, 05:11:18 pm »
Hi!

I have a totaly different suggestion. Without a component. Just UTF8-chars.

There are the UTF8 blockchars:

Code: Pascal  [Select][+][-]
  1. '▏', //       9615    258f    left one eighth blocK      1/8
  2. '▎', //       9614    258e    left one quarter block     2/8
  3. '▍', //       9613    258d    left three eighths block   3/8
  4. '▌', //       9612    258c    left half block            4/8
  5. '▋', //       9611    258b    left five eighths block    5/8
  6. '▊', //       9610    258a    left three quarters block  6/8
  7. '▉', //       9609    2589    left seven eighths block   7/8
  8. '█' //        9608    2588    full block                 8/8      
  9.  

If you for example want to work with integer percents, you can take 1%  as the eights block and 100 %  are 12 full blocks plus one half block.

Very simple. That's the reason why I exspect the most will howl: No we dont't want that.

As always I say: KISS

Winni


I love keeping things simple!  And I wish i thought of something like this in the beginning.  Not sure how this can take into account for varying widths of the cell though?  Plus i worked in a little percentage text that I really want to keep now...  but either way this block character is very interesting and may serve me well on some other project!  I am learning quite a bit the past few months playing in Lazarus. 

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Progress bar in stringgrid
« Reply #18 on: July 17, 2021, 05:11:42 pm »
Hi!

Just to show how my simple idea works:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.TestClick(Sender: TObject);
  2. const
  3. Blocks : array[1..8] of string = (
  4. '▏', //       9615    258f    left one eighth blocK      1/8
  5. '▎', //       9614    258e    left one quarter block     2/8
  6. '▍', //       9613    258d    left three eighths block   3/8
  7. '▌', //       9612    258c    left half block            4/8
  8. '▋', //       9611    258b    left five eighths block    5/8
  9. '▊', //       9610    258a    left three quarters block  6/8
  10. '▉', //       9609    2589    left seven eighths block   7/8
  11. '█' //        9608    2588    full block                 8/8
  12. );
  13. var percent, full, modulo,i : integer;
  14.     s: string;
  15. begin
  16. percent := random (101);
  17. full := percent div 8;
  18. modulo := percent mod 8;
  19. s := '';
  20. for i := 1 to full do s := s + Blocks[8];
  21. if modulo >0 then s := s + Blocks[modulo];
  22. s := intToStr(percent)+'%'+s;
  23. StringGrid1.Cells[1,1] := s;
  24. end;
  25.  
  26.  
Winni

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Progress bar in stringgrid
« Reply #19 on: July 17, 2021, 05:19:08 pm »
Plus i worked in a little percentage text that I really want to keep now... 
but either way this block character is very interesting and may serve me well on some other project!  I am learning quite a bit the past few months playing in Lazarus.

There is no problem with little percentage. Just change the 1/8 block base unit from my above example from 1% to 0.1% .  Problem : if you got 100% you get avery long string. But that is the same problem with a component.

Winni

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: Progress bar in stringgrid
« Reply #20 on: July 17, 2021, 05:20:03 pm »
I made this animated gif to show how my program is behaving...  the first time around it works great.  But If i process that same list again you will see the custom drawn progress bars still exist...  lol
The problem is probably that you don't re-initialize some internals in your logic. Old progress?

...
You always should reset the canvas values prior to drawing..

The PrepareCanvas() is called internally before each OnDrawCell(). It resets the canvas according to the cell state. As long there is no OnPrepareCanvas() handler to change it (and DefaultDrawing is true) on each OnDrawCell() the canvas should be right, i.e. no side effects from OnDrawCell() changes.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: Progress bar in stringgrid
« Reply #21 on: July 17, 2021, 05:27:09 pm »
I made this animated gif to show how my program is behaving...  the first time around it works great.  But If i process that same list again you will see the custom drawn progress bars still exist...  lol
The problem is probably that you don't re-initialize some internals in your logic. Old progress?

...
You always should reset the canvas values prior to drawing..

The PrepareCanvas() is called internally before each OnDrawCell(). It resets the canvas according to the cell state. As long there is no OnPrepareCanvas() handler to change it (and DefaultDrawing is true) on each OnDrawCell() the canvas should be right, i.e. no side effects from OnDrawCell() changes.

well there is only one progress variable... and as you can see the next time around as it works through the stringgrid list it just reads the same variable of progress... then resets to 0 and moves onto the next item in the stringgrid.  Which is why I am confused how it starts showing all of those items as being at 97 percent when i am only just starting to process the first item of the stringgrid again.  I AM QUITE SURE i can be doing this in a much cleaner way that would allow me to pinpoint the problem... but for now I will keep poking through my mess of code... i am sure I will figure it out.  I just hope I am not driving people here crazy with questions that may be common sense or easily found elsewhere.

I WILL FIND the 'bug' !  :D

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: Progress bar in stringgrid
« Reply #22 on: July 17, 2021, 05:41:40 pm »
*snip*
Very simple. That's the reason why I exspect the most will howl: No we dont't want that.
Yes!!! I'm a big fan of the ascii-art! (this probably should be an "utf8-art")

But IMO the OP has some misunderstanding of the program flow in the UI app, I doubt this will help ...  ::) 

@Tony Stone,
It is not very clear for me how you distinguish which is your current row (the col is 9). Maybe:
Code: [Select]
if (doCustDrawSG) ...?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: Progress bar in stringgrid
« Reply #23 on: July 17, 2021, 06:07:02 pm »
*snip*
Very simple. That's the reason why I exspect the most will howl: No we dont't want that.
Yes!!! I'm a big fan of the ascii-art! (this probably should be an "utf8-art")

But IMO the OP has some misunderstanding of the program flow in the UI app, I doubt this will help ...  ::) 

@Tony Stone,
It is not very clear for me how you distinguish which is your current row (the col is 9). Maybe:
Code: [Select]
if (doCustDrawSG) ...?


Things are not entirely clear to me either. ;)

But I did just fix my problem....

As for the boolean variable 'doCustDrawSG', I added an additional check wether it should draw the progressbar or just display string value of the cell.  I forget why I came up with that honestly but it solved one of the issues I was having. 

So the PERCENTDONEsingle variable i am using to track progress was my main issue.  I was not resetting it back to 0 when it was done with  file... I think you had suggested looking at that earlier.

I at least have it functioning properly now.  I will continue playing with the canvas properties to get a better understanding.  I have some added complexity where things are being done in seperate threads... At least for me it adds complexity...  In a year from now I will be adding actual value to this forum.  I will get there!  As usual, thanks for your time and replying to my posts!

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: Progress bar in stringgrid
« Reply #24 on: July 17, 2021, 06:09:14 pm »
you guys don't notice the incorrect displays of chars here ?

Looks fine here....

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Progress bar in stringgrid
« Reply #25 on: July 17, 2021, 06:11:53 pm »
No problem with the display of the full block.

Must be your OS or your browser - wherever that happens.

Winni

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: Progress bar in stringgrid
« Reply #26 on: July 17, 2021, 06:15:18 pm »
you guys don't notice the incorrect displays of chars here ?

I am playing with his code sample as well.  I think it is a great idea but it doesnt exactly display as one would expect either.  I think it could work for sure... I think to make it really useful you would need to use space characters in the calculated canter of the progress to continue showing the percentage text.  And it doesnt look quite right even when i got that to partially work.  If it isn't going to take into account for the width of the cell it needs to have a character that represents the beinning and end of the 'progressbar'... so i was just playing with some characters like a | and < and > but i cant come up with much.  I do like this idea though and I think I will try and perfect my own little function of one that can be easily used in text boxes, or memos... i may learn something from it.

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: Progress bar in stringgrid
« Reply #27 on: July 17, 2021, 06:35:38 pm »
Just stick with the Custom Draw code...

If you need a little demo I can provide, because I am just one of those guys!  ::)

I'm gonna hold off on the sample.  I'll seek you out when in need of a sample for something I am very stuck on! Lol...

In this case I'm gonna stick with the custom draw code.  But I love the idea of an ascii art progress bar.  Would be great for command line programs ad well I would imagine.  I'm gonna see if I can perfect a function that returns one as a string... Gonna be a little exercise for me I guess.  :D

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Progress bar in stringgrid
« Reply #28 on: July 17, 2021, 07:26:04 pm »
Hi!

Just an example with the customDraw.

I assume that the percentage has to be drawn in cells[1,1].
The percentage as a float has to be the value of cells[1,1]
As a string  for shure.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1DrawCell(Sender:TObject;aCol,aRow:Integer;aRect:TRect;aState: TGridDrawState);
  2.   var s : string;
  3.       ProgressRect : TRect;
  4.       percent : Single;
  5.       len,x,xd : integer;
  6. begin
  7.     if (acol=1) and (arow=1) then
  8.     begin
  9.     StringGrid1.canvas.Brush.Style:= bsSolid;
  10.     StringGrid1.canvas.Brush.color := clBlack;
  11.     StringGrid1.canvas.FillRect(aRect);
  12.     ProgressRect := aRect;
  13.     InflateRect(ProgressRect,-3,-3);
  14.     StringGrid1.canvas.Brush.color := clWhite;
  15.     StringGrid1.canvas.FillRect(ProgressRect);
  16.  
  17.     if  StringGrid1.Cells[1,1] <> '' then
  18.        percent := StrToFloat(StringGrid1.cells[1,1])
  19.        else percent := 0.0;
  20.     len := ProgressRect.Right-ProgressRect.left;
  21.     x := ProgressRect.left+ round (len * percent/100);
  22.  
  23.     StringGrid1.canvas.pen.color := clWhite;
  24.     StringGrid1.Canvas.Rectangle(ProgressRect);
  25.  
  26.     StringGrid1.canvas.Brush.color := clRed;
  27.     StringGrid1.canvas.FillRect(ProgressRect.left,ProgressRect.Top,
  28.                                             x,ProgressRect.Bottom);
  29.     s := StringGrid1.cells[1,1]+'%';
  30.     xd := (len - StringGrid1.Canvas.TextWidth(s)) div 2 +ProgressRect.left;
  31.    
  32.     StringGrid1.canvas.Brush.Style:= bsClear;
  33.     StringGrid1.canvas.TextOut(xd,ProgressRect.Top+1,s);
  34.   end;
  35. .....
  36.  
  37. end;


Winni

PS Screenshot attached
« Last Edit: July 17, 2021, 07:33:31 pm by winni »

speter

  • Sr. Member
  • ****
  • Posts: 465
Re: Progress bar in stringgrid
« Reply #29 on: July 18, 2021, 03:51:51 am »
you guys don't notice the incorrect displays of chars here ?

I do (Win 10, 64bit).

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

 

TinyPortal © 2005-2018