Code Monkey home page Code Monkey logo

Comments (34)

Alexey-T avatar Alexey-T commented on August 24, 2024 1

Another demo? do we need it? Ok, i will review it.

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024 1

Well, this one you may want. One of the things a lot of people want to do is to add custom scrollbars to their apps. Usually they want to control an editor of some sort, but there is very little out there on how to do that. So this would show them. I need to have it for myself for reference in the future anyway so it's valuable to me either way. You can look at it and decide. Thanks again for the help.

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024 1

Better new demo with memo

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024 1

Stan, my latest task is CudaText, so I welcome you to test/report it.
(closing ussue, over heat)

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

Here's the initial code and scroll code for the TMemo:

function GetVisibleLineCount(Memo: TMemo): Integer;
var
  DC: HDC;
  SaveFont: HFONT;
  TextMetric: TTextMetric;
  EditRect: TRect;
begin
  DC := GetDC(0);
  SaveFont := SelectObject(DC, Memo.Font.Handle);
  GetTextMetrics(DC, TextMetric);
  SelectObject(DC, SaveFont);
  ReleaseDC(0, DC);

  Memo.Perform(EM_GETRECT, 0, LPARAM(@EditRect));

  Result := (EditRect.Bottom - EditRect.Top) div TextMetric.tmHeight;
end;
...
  ATScrollbar1.Visible := Form1.Memo1.Lines.Count > (GetVisibleLineCount(Memo1) + 1);

  ATScrollBar1.Min:= 0;
  ATScrollBar1.Max:= Form1.Memo1.Lines.Count+1;

  ATScrollBar1.PageSize:= GetVisibleLineCount(Memo1);

procedure TForm1.ATScrollbar1Change(Sender: TObject);
var
  i, x: integer;
begin

    x := Memo1.Perform(EM_GETFIRSTVISIBLELINE, 0, 0);

    if x > ATScrollbar1.Position then
        i := -(x - ATScrollbar1.Position)
    else
        i := (ATScrollbar1.Position - x) ;

    SendMessage(Memo1.Handle, EM_LINESCROLL, 0 ,i);

end;

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

Alexey, I've tried everything I can think of and I can't fix the behavior. So I made a test app and put it up here:
https://github.com/srd-software/TestScrollApp
If you compile that (in delphi) then run it, you'll see for small files it's OK. Drag and drop the "bigtestfile.pas" file on it and scroll it to the bottom. The TMemo on the right will work since the MinSizeOfThumb is 4. On the left you'll see the problem as that one MinSizeOfThumb is set to GetSystemMetrics(SM_CYVTHUMB). You can see both the native scrollbar and the atscrollbar side by side. They should track exactly but you'll see the atscrollbar "chases" the native scrollbar and arrives at the end of the scroll too early.

If you could take a look at this when you have a minute I would really appreciate it. I'm out of ides on how to work around it.

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

Will see it soon, I forgot about it..

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

No problem. When you have time. I hate to bother you with it but I'm out of ideas.

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

Guess that internal Rect fields for Ui parts don’t consider this value

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

Do you agree that MinThumbSize must be inside Theme record? So it can affect all scrollbars in app

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

I'm assuming that you are trying to get it to do an automatic kind of proportional sizing for the thumb? If so, maybe make MinThumbSize part of the theme and/or create an OptProportionalAuto property or something to turn it on or off. Is your other stuff using it the way it is? I tried the test file in the lazarus editor demo and it's working OK in that.

I do know that I've been using one called ALScrollBar for a long time and that one works with the "proportional code" you see in the one I sent. I can send you that file if it will help. I also have a demo for that one that's about the same thing as what I sent you but using the ALScrollBar (it works as expected; just not as nice a way to set colors in that one compared to yours).

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

In my case, I can't see any situation where I would not want a proportional scrollbar, and I would want all the scrollbars in my app to be the same. So as to your "MinThumbSize in the record" question my answer would always be yes. But I don't know about other users.

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

I uploaded the ALScrollBar.pas for reference. Note that its thumb is set by ScrollWidth which I think is somewhat analogous to Page or PageSize. However, it does no fancy calcs internally for proportional sizing, ScrollWidth is just a get/set var. You have to do all the proportional stuff outside of the component.

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

I see the thumb size problem with big Max. Struggled with it for an hour, cannot solve yet..

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

Yes, I know the feeling! I haven't been feeling well this week so I've had a lot of time to fiddle with it too. No luck so far. Not sure if GH works with exe, but I put the working ALscrollbar Project1.exe up there too. If you can get hold of that and run it you'll see one that works.

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

I tried to change CoordToPos with PosToCoord— decreased there rect size by MinSizeOfThumb- that gave new not correct behavior

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

Then I tried to change that delta from MinSizeOfThumb to smaller.. cannot guess delta

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

Yep. You can probably see in all that commented-out code that I tried all sorts of things on the app side. I also played with both coordinate functions, FMouseDragOffset and DoUpdatePosOnDrag as well. No luck. I could sometimes get it to land at the bottom OK, but then the top position was wrong, and/or the mousecursor was wrong during the drag.

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

I Have an idea..

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

Couple of things I've found in the past when setting Max (on the other scrollbar component): I had to remove the linecount of lines being displayed (inside the ClientHeight rect) from the total lines of text (current demo app does not do this as the scroll is thrown way off if I do it, but it should probably use that).

And when calculating the proportional thumbwidth I usually had to remove the scroll arrow button heights/widths.

    x := ALVScrollBar.ButtonWidth * 2; //SB arrow button widths/heights

    i :=
      round((ALVScrollBar.ClientHeight-x) * ((ALVScrollBar.ClientHeight) /
        ((GetLineCount + extraPage) * TextHeight(0)))) ;

    if i < GetSystemMetrics(SM_CYVTHUMB) then
        i := GetSystemMetrics(SM_CYVTHUMB);

    if ALVScrollBar.ScrollerWidth <> i then
        ALVScrollBar.ScrollerWidth := i;

    ALVScrollBar.Min := 0; //always 0
    ALVScrollBar.Max := (TrueLineNumber(GetLength) + extraPage - LinesOnScreen) + 1 ; //max is num of lines

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

In PosToCoord if I change:

NLen:= FRectMain.Height

to:

NLen:= FRectMain.Height-Math.Min(ThumbSize-4,FMinSizeOfThumb-4);

It seems to track somewhat correctly on large-max files. It is not a fix, as the mouse cursor.X is wrong when you get the end of the scroll, and smaller files don't work correctly. However, maybe this will give you a clue as to how to fix.

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

Stan, after thinking during an hour, i found the solution. some part was guessed. try how it's now. OK here with big Max=10000, MinSizeOfThumb=50

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

OK, yes, so far THAT seems to have done it. I'm assuming it's the EffectiveRectSize function? I know it was a pain to do but this change makes it really useful, more useful than most of the other scrollbars I've tried since you don't even have to put in any proportional code with it now. Very nice.

I'm going to keep working with it and if I run into anything I'll let you know.

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

Moved 2 props into ATScrollbarTheme:
MinSizeToShowThumb
MinSizeOfThumb

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

So far so good. I'll keep testing.

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

I've been testing stuff for hours over the past couple of days and I am, again, out of ideas!

I have a question. Is the atScrollbar PageSize property exactly equivalent to the scrollbar thumb size? I ask because, if it is, then the code below should be producing the exact same scrollbars (if that's an erroneous assumption let me know):

  x := 15 * 2; //account for arrow buttons
  //calculate proportional thumb size 
  //(this is patterned after everything I can find online about this and has worked for me in the past):
  i := round((RichEdit1.ClientWidth - x)
    * (RichEdit1.ClientWidth - x)
    / (ContentRect(RichEdit1).Width - x)) ;

  //works (ALscrollbar component I'm trying to replace at some point):
  ALScrollBar1.Max := (ContentRect(RichEdit1).Width - ALScrollBar1.ClientWidth) + 15;
  ALScrollBar1.ScrollerWidth := i; //sets thumb size directly, i.e., ScrollerWidth = thumbsize

  //doesn't work (atScrollbar I want to use):
  ATScrollbar4.Max := (ContentRect(RichEdit1).Width - ATScrollbar4.ClientWidth) + 15;
  ATScrollbar4.PageSize := i; //does this set thumbsize directly, or is there some calculation affecting it? 

Here's a screenshot of what I'm getting:

ss1

When the scrollbars are actually scrolled the AL works as expected, AT does not (doesn't go to right extent which is not surprising since the thumbsize is off). Here's the OnChange code for both:

procedure TForm1.ALScrollBar1Change(Sender: TObject);
begin
  SendMessage(RichEdit1.Handle, WM_HSCROLL,MAKEWPARAM( SB_THUMBPOSITION, ALScrollBar1.Position )  ,0);
end;

procedure TForm1.ATScrollbar4Change(Sender: TObject);
begin
  SendMessage(RichEdit1.Handle, WM_HSCROLL,MAKEWPARAM( SB_THUMBPOSITION, ATScrollbar4.Position)  ,0);
end;

I can make the AT bar sort of work by setting the PageSize to minimum and keeping it there, but you lose the proportional aspect which is needed.

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

Here it is in use, might make it clearer. Note that the AL bar follows the native bar as expected, both on scroll and on resize.

demo2

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

Wrong assumption, coz page size has not screen pixel siZe, but it has logical units like Min, Max have logical units

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

Did you try to set PageSize to count of columns of memo? Visible columns

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

On resize you must

Set PageSize to count of visible columns
Set Max to maximal column index of longest line

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

OK, I was wondering if I had a size of units issue. TMemo and TRichEdit have no columns as such since they both can use proportional fonts. I can "fake it" by taking the widths involved and multiplying them by the TextMetric.tmAveCharWidth. As long as I use a monospaced font (i.e., "Courier"), this works. (Vertical is not a problem since it's just linecounts and lineheight.)

I'll have to think about that some more but your info helped a lot.

Thanks!

from atflatcontrols.

Alexey-T avatar Alexey-T commented on August 24, 2024

Ok, for variable font-

Set PageSize to pixel width of memo
Set Max to pixel width of longest line

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

Wow. Simple. Easy. And it works. Thanks! Been looking for the solution on my own for HOURS. I wish I had your skills and problem-solving abilities for relational math! Here she is in action (top SB is native, middle SB is AT, bottom SB is (old) AL:

ss2

I'm working on a demo that you can use in your demo section for the flat components. Once I get things tested enough and everything cleaned up I'll upload so you can review it.

from atflatcontrols.

srd-software avatar srd-software commented on August 24, 2024

Oh, another option would be to take the current demo you have and just add a TMemo into that left side panel and make it work there.

from atflatcontrols.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.