|
|
Home » Developing U++ » U++ Developers corner » Know what you're using. Size of some common types.
Re: Know what you're using. Size of some common types. [message #57991 is a reply to message #57988] |
Mon, 10 January 2022 21:43   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Buttons established a concept. If implemented with due care, it will arrive at same Ctrl size (eg, ScrollBar, SpinButtons) as when hardcoded (like the way I do ScrollBar). That being said, Buttons interface are not expected to save much work (than hard coded way), if any. Personally I will do without: I don't see the benefit here, except the visual clue that they are doing similar things.
I have performed a simple test on adding SpinButtons to EditField without resorting to a CtrlFrame, and it works like a charm. I know this is not conceptually right, but it will work in practice and save memory of a little over sizeof(Ctrl) for each EditWithSpin object than the Buttons way mirek is considering. The only functionality it lose is when there are multiple frames, you cannot choose to put the SpinButtons frame on anywhere except innermost, because it's not a real CtrlFrame.
The Test is very simple, start a CtrlLib project with a Main Window with a EditField and a EditInt64WithSpin. Now we start to play around with CtrlLib.
In <CtrlLib/EditCtrl.h, add a new virtual function to class EditField
class EditField : public Ctrl, private TextArrayOps {
public:
virtual void Layout();
virtual void Paint(Draw& draw);
virtual void LeftDown(Point p, dword keyflags);
... omitted
virtual void State(int);
// newly introduced
virtual Size GetReducedSize()const{
// EditField::GetReducedSize() should just return GetSize();
// it's the WithSpin derived class that should override this
// function to reserve room for SpinButtons.
//
// here we reduce it as if allocating space for SpinButtons
Size sz = GetSize();
sz.cx -= 30;
if(sz.cx < 0)
sz.cx=0;
return sz;
}[/b]
...
In <CtrlLib/EditField.cpp>, search all occurence of "GetSize()", if it's not "GetSize().cy", and is not "GetParent()->GetSize()", repace it with "GetReducedSize()". Run the test program, notice the room for SpinButton has been allocated, and play with some input in the EditField, see it scroll horizontally properly when the text gets really long. Now we can be certain this route is feasible. And it will come out with more compact EditXXWithSpins than to retain Buttons in a CtrlFrame. I would say the amount of coding involved are quite similar in both ways.
I will otherwise leave EditField (except probably add a spin_visible bitfield member intended for EditXXwithSpin). Then override Paint, relevant mouse event virtual function in WithSpin<> template class. It's quite similar to what I did with ScrollBar. No impact will be felt by libary users except smaller EditXXWithSpin objects---class hierarchy and interfaces remain unchanged.
[Updated on: Mon, 10 January 2022 21:54] Report message to a moderator
|
|
|
 |
|
Know what you're using. Size of some common types.
By: Lance on Mon, 27 December 2021 19:33
|
 |
|
Re: Know what you're using. Size of some common types.
By: Klugier on Mon, 27 December 2021 19:58
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Mon, 27 December 2021 20:32
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Mon, 27 December 2021 20:37
|
 |
|
Re: Know what you're using. Size of some common types.
By: Klugier on Mon, 27 December 2021 21:42
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Tue, 28 December 2021 02:29
|
 |
|
Re: Know what you're using. Size of some common types.
By: Novo on Tue, 28 December 2021 05:17
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Tue, 28 December 2021 20:27
|
 |
|
Re: Know what you're using. Size of some common types.
By: Novo on Tue, 28 December 2021 23:49
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Wed, 29 December 2021 01:42
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Thu, 30 December 2021 02:39
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Fri, 31 December 2021 19:51
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Fri, 31 December 2021 20:20
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Fri, 31 December 2021 20:28
|
 |
|
Re: Know what you're using. Size of some common types.
By: mirek on Wed, 05 January 2022 10:47
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Fri, 07 January 2022 17:25
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Fri, 07 January 2022 17:44
|
 |
|
Re: Know what you're using. Size of some common types.
By: mirek on Fri, 07 January 2022 18:34
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Fri, 07 January 2022 19:01
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Fri, 07 January 2022 19:26
|
 |
|
Re: Know what you're using. Size of some common types.
By: mirek on Fri, 07 January 2022 22:22
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Sun, 09 January 2022 20:36
|
 |
|
Re: Know what you're using. Size of some common types.
By: mirek on Mon, 10 January 2022 01:07
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Mon, 10 January 2022 02:00
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Mon, 10 January 2022 21:43
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Tue, 11 January 2022 02:29
|
 |
|
Re: Know what you're using. Size of some common types.
By: mirek on Tue, 11 January 2022 13:41
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Tue, 11 January 2022 15:19
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Tue, 11 January 2022 17:40
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Tue, 11 January 2022 22:07
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Tue, 11 January 2022 22:25
|
 |
|
Re: Know what you're using. Size of some common types.
By: mirek on Wed, 11 May 2022 09:42
|
 |
|
Re: Know what you're using. Size of some common types.
By: Novo on Thu, 12 May 2022 08:26
|
 |
|
Re: Know what you're using. Size of some common types.
By: Lance on Sat, 14 May 2022 21:30
|
 |
|
Re: Know what you're using. Size of some common types.
By: mirek on Fri, 07 January 2022 18:32
|
Goto Forum:
Current Time: Thu Jul 03 00:14:32 CEST 2025
Total time taken to generate the page: 0.02988 seconds
|
|
|