Comments (34)
Another demo? do we need it? Ok, i will review it.
from atflatcontrols.
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.
Better new demo with memo
from atflatcontrols.
Stan, my latest task is CudaText, so I welcome you to test/report it.
(closing ussue, over heat)
from atflatcontrols.
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.
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.
Will see it soon, I forgot about it..
from atflatcontrols.
No problem. When you have time. I hate to bother you with it but I'm out of ideas.
from atflatcontrols.
Guess that internal Rect fields for Ui parts don’t consider this value
from atflatcontrols.
Do you agree that MinThumbSize must be inside Theme record? So it can affect all scrollbars in app
from atflatcontrols.
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.
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.
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.
I see the thumb size problem with big Max. Struggled with it for an hour, cannot solve yet..
from atflatcontrols.
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.
I tried to change CoordToPos with PosToCoord— decreased there rect size by MinSizeOfThumb- that gave new not correct behavior
from atflatcontrols.
Then I tried to change that delta from MinSizeOfThumb to smaller.. cannot guess delta
from atflatcontrols.
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.
I Have an idea..
from atflatcontrols.
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.
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.
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.
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.
Moved 2 props into ATScrollbarTheme:
MinSizeToShowThumb
MinSizeOfThumb
from atflatcontrols.
So far so good. I'll keep testing.
from atflatcontrols.
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:
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.
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.
from atflatcontrols.
Wrong assumption, coz page size has not screen pixel siZe, but it has logical units like Min, Max have logical units
from atflatcontrols.
Did you try to set PageSize to count of columns of memo? Visible columns
from atflatcontrols.
On resize you must
Set PageSize to count of visible columns
Set Max to maximal column index of longest line
from atflatcontrols.
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.
Ok, for variable font-
Set PageSize to pixel width of memo
Set Max to pixel width of longest line
from atflatcontrols.
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:
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.
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)
- Drag/drop from other controls not working HOT 7
- Font scaling correction HOT 8
- Question about buttons placed on the left side and tabwidth of the leftmost tab after scrolling HOT 4
- Can't compile ATCanvasPrimitives in 10.4 HOT 4
- How put a form insde tTab or controls like tpage HOT 3
- Prob with DragDrop (unexpected exchange of tabs)? HOT 14
- TATTabs: Missing Event while reordering Tabs HOT 7
- Little problem again HOT 4
- Small problem
- Little problem in Delphi
- How to change the position of dropdown list of a ATComboEdit? HOT 6
- Bug report in TabChangeQuery HOT 3
- Case where changed Data.TabHint is not reliably propagated to tab's hint HOT 9
- Problem HOT 2
- Delphi 11 + TAntialiasingMode HOT 8
- ATStatusBar.pas - Delphi 10.2 HOT 1
- Option for right click HOT 2
- OptMouseDragOutEnabled broken? HOT 3
- Drag marker shown after context menu HOT 21
- Drag marker shown at left click on active tab HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from atflatcontrols.