Recent

Author Topic: any component for spinning through a set?  (Read 3984 times)

Weiss

  • Full Member
  • ***
  • Posts: 219
any component for spinning through a set?
« on: October 14, 2023, 06:08:26 pm »
If I want user to be able to scroll through a set of values and pick one, which component, other than menu, could do this job? Spin Edit can only scroll with interval, but I need interval to be a power of 2. Like spinning through set of values 2,4,8,16 etc.
« Last Edit: October 14, 2023, 06:10:04 pm by Weiss »

flowCRANE

  • Hero Member
  • *****
  • Posts: 937
Re: any component for spinning through a set?
« Reply #1 on: October 14, 2023, 06:26:32 pm »
You can use standard SpinEdit control and change its behavior by overriding the SetValue method to control how the value should change. And, of course, methods like SetMinValue and SetMaxValue and other should also be overriden.
Lazarus 4.2 with FPC 3.2.2, Windows 11 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL3.

wp

  • Hero Member
  • *****
  • Posts: 13213
Re: any component for spinning through a set?
« Reply #2 on: October 14, 2023, 06:58:43 pm »
Drop a TEdit and a TUpDown on the form. Do not link them, i.e. do not set the UpDown's Associate to the edit control so that the text displayed by the edit is not overridden by the UpDown steps. Then write an event handler for the UpDown's OnClick:

Code: Pascal  [Select][+][-]
  1. uses
  2.   math;
  3.  
  4. procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
  5. var
  6.   ud: TUpDown;
  7. begin
  8.   if Sender is TUpDown then
  9.   begin
  10.     ud := TUpDown(Sender);
  11.     Edit1.Text := FloatToStr(IntPower(2, ud.Position));
  12.   end;
  13. end;

Weiss

  • Full Member
  • ***
  • Posts: 219
Re: any component for spinning through a set?
« Reply #3 on: October 14, 2023, 07:32:12 pm »
overriding components methods - that would be some furious programming! I will get there one day. I was thinking something along WP's example, up/down and a label. In the end I went with listBox. Looks ugly as sin, but it was quick.

Joanna

  • Hero Member
  • *****
  • Posts: 1400
Re: any component for spinning through a set?
« Reply #4 on: December 29, 2023, 11:51:34 am »
You could also use a combobox and load the values of set into it.

To achieve spinning behavior the selected index of combobox would be set to last item when up arrow is pressed from first item or first item would be selected when down arrow is pressed from last item.

 

TinyPortal © 2005-2018