Recent

Author Topic: [SOLVED] Horizontal TSpinEdit?  (Read 1895 times)

del

  • Sr. Member
  • ****
  • Posts: 258
[SOLVED] Horizontal TSpinEdit?
« on: January 20, 2023, 07:48:56 pm »
Is there a way to make TSpinEdit horizontal, with the arrows pointing left and right? Obviously I have my reasons for wanting this. Is it possible? Do I need to make one out of existing parts?
« Last Edit: January 21, 2023, 05:55:49 am by del »

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Horizontal TSpinEdit?
« Reply #1 on: January 20, 2023, 08:08:58 pm »
I thought there's a property Orientation or so, which rotates the spin buttons, but I was wrong - no, this is not possible, not even in Delphi...

The TUpDown control, however, has it: Orientation = udVertical or udHorizontal. You can combine it with a TEdit (Edit.Associate = Updown) to get a spinedit-like control. However, it does not support floating point numbers.

[EDIT]
Ok... Looked in the T(Float)SpinEditEx sources and found that it uses a TUpDown control internally. Therefore, it must by possible to switch it to horizontal Orientation. I tried the following code, and it works:

Code: Pascal  [Select][+][-]
  1. type
  2.   TFloatSpinEditEx = class(SpinEx.TFloatSpinEditEx)
  3.   public
  4.     constructor Create(AOwner: TComponent); override;
  5.   end;
  6.  
  7. constructor TFloatSpinEditEx.Create(AOwner: TComponent);
  8. begin
  9.   inherited;
  10.   UpDown.Orientation := udHorizontal;
  11.   UpDown.Width := UpDown.Width * 2;
  12. end;

Put this into a separate unit and add this to the END of the uses clause of the units in which you need it.

Of course, I could submit a bug report and request adding this to the official component...
« Last Edit: January 20, 2023, 08:16:34 pm by wp »

del

  • Sr. Member
  • ****
  • Posts: 258
Re: Horizontal TSpinEdit?
« Reply #2 on: January 20, 2023, 08:28:04 pm »
I thought there's a property Orientation or so, which rotates the spin buttons, but I was wrong - no, this is not possible, not even in Delphi...

The TUpDown control, however, has it: Orientation = udVertical or udHorizontal. You can combine it with a TEdit (Edit.Associate = Updown) to get a spinedit-like control. However, it does not support floating point numbers.

[EDIT]
Ok... Looked in the T(Float)SpinEditEx sources and found that it uses a TUpDown control internally. Therefore, it must by possible to switch it to horizontal Orientation. I tried the following code, and it works:

Code: Pascal  [Select][+][-]
  1. type
  2.   TFloatSpinEditEx = class(SpinEx.TFloatSpinEditEx)
  3.   public
  4.     constructor Create(AOwner: TComponent); override;
  5.   end;
  6.  
  7. constructor TFloatSpinEditEx.Create(AOwner: TComponent);
  8. begin
  9.   inherited;
  10.   UpDown.Orientation := udHorizontal;
  11.   UpDown.Width := UpDown.Width * 2;
  12. end;

Put this into a separate unit and add this to the END of the uses clause of the units in which you need it.

Of course, I could submit a bug report and request adding this to the official component...

This is just what I was looking for. I'll give it a try - thanks !!  :)

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Horizontal TSpinEdit?
« Reply #3 on: January 20, 2023, 10:29:21 pm »
Just committed a new version of T(Float)SpinEditEx to Laz/main in which the Orientation property of the embedded UpDown control is accessible from the outside.

As it is a new feature, however, it will only be available in the next full release v2.4 (or use Laz/main). However, it is not difficult to patch a release version (but make a backup copy of the files to be modified):
  • In folder component/lazcontrols of your Lazarus installation, open the file spinex.pp.
  • Find the declaration of TSpinEditExBase
    • Add "FOrientation: TUDOrientation;" to the declarations in the private section.
    • Add "function GetOrientation: TUDOrientation;" and "procedure SetOrientation(AValue: TUDOrientation);" to the setter/getter methods in the private section.
    • Add "property Orientation: TUDOrientation read GetOrientation write SetOrientation default udVertical;" to the end of
      the property declarations in the protected section.
  • Find the declaration of TFloatSpinEditEx
    • Add "property Orientation;" to the published properties.
  • Find the declaration of TSpinEditEx
    • Add "property Orientation;" to the published properties.
  • Open file spinex.inc from the same folder.
  • Add the following two methods to the file somewhere and then rebuild the IDE:
Code: Pascal  [Select][+][-]
  1. function TSpinEditExBase.GetOrientation: TUDOrientation;
  2. begin
  3.   Result := UpDown.Orientation;
  4. end;
  5.  
  6. procedure TSpinEditExBase.SetOrientation(AValue: TUDOrientation);
  7. var
  8.   w: Integer;
  9. begin
  10.   if GetOrientation = AValue then
  11.     exit;
  12.   w := UpDown.Width;
  13.   UpDown.Orientation := AValue;
  14.   case GetOrientation of
  15.     udVertical: UpDown.Width := w div 2;
  16.     udHorizontal: UpDown.Width := w * 2;
  17.   end;
  18. end;

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Horizontal TSpinEdit?
« Reply #4 on: January 20, 2023, 11:19:29 pm »
@wp: thanks.

Bart

del

  • Sr. Member
  • ****
  • Posts: 258
Re: Horizontal TSpinEdit?
« Reply #5 on: January 20, 2023, 11:50:34 pm »
Wow - that was fast. Faster than it took me to implement the suggestion. Here's what I did ... (I made it wider)

Code: Pascal  [Select][+][-]
  1. unit HorzSpin;
  2.  
  3. {$mode objfpc}
  4.  
  5. interface
  6.  
  7. uses
  8.         SpinEx, Classes;
  9.  
  10. type
  11.         TFloatSpinEditEx = class(SpinEx.TFloatSpinEditEx)
  12.         public
  13.                 constructor Create(AOwner: TComponent); override;
  14.         end;
  15.  
  16. implementation
  17.  
  18. uses
  19.         ComCtrls;
  20.  
  21. constructor TFloatSpinEditEx.Create(AOwner: TComponent);
  22. begin
  23.         inherited;
  24.         UpDown.Orientation := udHorizontal;
  25.         UpDown.Width := UpDown.Width * 8;
  26. end;
  27.  
  28. end.
  29.  

And it produced a horizontal spin edit (float) which I converted to integer in order to index through and display a bunch of images in memory (see attached).
« Last Edit: January 21, 2023, 08:14:03 am by del »

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: [SOLVED] Horizontal TSpinEdit?
« Reply #6 on: January 21, 2023, 06:02:48 pm »
Hmm, how about the layout property giving us a Top or bottom ?

I do that now with two controls.
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: [SOLVED] Horizontal TSpinEdit?
« Reply #7 on: January 21, 2023, 06:16:36 pm »
Similar to a scrollbar: the left button decreases, the right button increases the value.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: [SOLVED] Horizontal TSpinEdit?
« Reply #8 on: January 21, 2023, 06:37:53 pm »
basically, but split the left/right arrows and allow them to be on top or bottom stretched to the full size of the spin control.


 Edit.

  What I do is use a TUpDown and associate it with another control and use the AignButton property.

  Unless I overlooked something, I don't see that in the recent spinEditex etc.
« Last Edit: January 21, 2023, 06:51:54 pm by jamie »
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: [SOLVED] Horizontal TSpinEdit?
« Reply #9 on: January 21, 2023, 06:55:51 pm »
No idea what you mean...

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: [SOLVED] Horizontal TSpinEdit?
« Reply #10 on: January 21, 2023, 07:36:21 pm »
  What I do is use a TUpDown and associate it with another control and use the AlignButton property.
That just sets the position relative to the Associate control.
There is a very good reason why the UpDown for T(Float)SpinEditEx is NOT associated with the TEdit.
Just look what happens to the TEdit if you associate it with a TUpDown and you'll instantly see that it is going to behave in a manner that is undesired (just take a look at TUpDown's Min/Max properties).

Bart

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: [SOLVED] Horizontal TSpinEdit?
« Reply #11 on: January 21, 2023, 07:51:07 pm »
Example

The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: [SOLVED] Horizontal TSpinEdit?
« Reply #12 on: January 21, 2023, 07:56:16 pm »
Yeah well, I just thought it to be a nice addition to the existing control.
The only true wisdom is knowing you know nothing

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: [SOLVED] Horizontal TSpinEdit?
« Reply #13 on: January 21, 2023, 08:16:08 pm »
Unfortunately, on macOS a TUpDown is always vertical.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: [SOLVED] Horizontal TSpinEdit?
« Reply #14 on: January 21, 2023, 08:47:23 pm »
Unfortunately, on macOS a TUpDown is always vertical.

Hi!

Replace the spinEdit with an  Edit
Take a left arrow and a right arrow.
Place the arrows next to the edit
Change  the the value of the edit according to left or right.

Winni

 

TinyPortal © 2005-2018