Recent

Author Topic: Animated toggle switch  (Read 4626 times)

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1932
Animated toggle switch
« on: October 15, 2023, 11:49:49 am »
Hi

Is there an "animated toggle switch" component for Lazarus?
Does BGRAControls have something like that?
I have not found anything.

The closest thing is the TOnOffSwitch in the Industrial package, but it is rectangular.


Thanks!

cdbc

  • Hero Member
  • *****
  • Posts: 2220
    • http://www.cdbc.dk
Re: Animated toggle switch
« Reply #1 on: October 15, 2023, 12:22:31 pm »
Hi
Have you looked in "Fresnel"-repo, maybe Michael's got something that can be backported...?
edit: Would be a cool and nifty addition, new style, me likey ;)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

lainz

  • Hero Member
  • *****
  • Posts: 4723
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Animated toggle switch
« Reply #2 on: October 15, 2023, 03:07:10 pm »
Hi, we have in BGRAControls but not animated.

Check test\bcimagebutton toggle

You can provide any bitmap to it, even generate a bitmap on the fly and assign it.
« Last Edit: October 15, 2023, 03:41:05 pm by lainz »

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1932
Re: Animated toggle switch
« Reply #3 on: October 15, 2023, 04:35:19 pm »
Thank you

It looks similar, but I imagine something more "dynamic", with changing background colors, movement, text changes, etc.
It wouldn't have to rotate, as in this example, but I think Lazarus is missing a dedicated component for this modern type of switch, which can be found everywhere today.
And BGRABitmap would have to be involved to make it look nice.
« Last Edit: October 15, 2023, 04:39:00 pm by theo »

wp

  • Hero Member
  • *****
  • Posts: 12873
Re: Animated toggle switch
« Reply #4 on: October 15, 2023, 04:56:03 pm »
Updated the TOnOffSwitch by some new properties:

- FrameStyle extended by fsNoneRounded, fsThinRounded and fsThickRounded options
- replace the built-in drawings by arbitrary images (properties PictureOn and PictureOFF)
- new property FlippedColors to flip background and thumb colors
- new property ShowFocusRect to show/hide the focus rect
« Last Edit: October 15, 2023, 04:59:02 pm by wp »

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1932
Re: Animated toggle switch
« Reply #5 on: October 16, 2023, 09:47:36 am »
Thank you.

Functionally it's good, but the curves don't look good.
Modern UI elements and pixelation don't go together.
That's why I said it won't work without BGRABitmap.
I would still prefer the rectangular version (bsThin3D) in this case. Actually, that one is quite good.

But thanks anyway!

Switchmode smClick is definitely an advantage


TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Animated toggle switch
« Reply #6 on: October 16, 2023, 10:16:59 am »
That's why I said it won't work without BGRABitmap.
Oh, I always thought some proper anti-aliasing would be able to do the job or isn't it possible to draw transparent pixels on a canvas ?
Today is tomorrow's yesterday.

lainz

  • Hero Member
  • *****
  • Posts: 4723
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Animated toggle switch
« Reply #7 on: October 16, 2023, 11:47:56 am »
Hi, it's easy to convert from TCanvas drawing to BGRABitmap, check this video:
https://www.youtube.com/watch?v=HGYSLgtYx-U

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Animated toggle switch
« Reply #8 on: October 16, 2023, 12:04:32 pm »
I have very much respect for BGRABitmap and controls but for me that is similar as using opengl to draw some anti-aliased half circles. Something with flies, guns and elephants  :)

In case relying on bgrabitmap then wouldn't it be a better fit to rewrite in/for bgracontrols ?
Today is tomorrow's yesterday.

lainz

  • Hero Member
  • *****
  • Posts: 4723
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Animated toggle switch
« Reply #9 on: October 16, 2023, 02:12:46 pm »
We accept new controls from any user.

lainz

  • Hero Member
  • *****
  • Posts: 4723
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Animated toggle switch
« Reply #10 on: October 19, 2023, 02:17:00 am »
I have very much respect for BGRABitmap and controls but for me that is similar as using opengl to draw some anti-aliased half circles. Something with flies, guns and elephants  :)

In case relying on bgrabitmap then wouldn't it be a better fit to rewrite in/for bgracontrols ?

Something great you want to say =)

Really I don't hate any library despite it can use a lot of mb on my hard disk.

Else I will not install lazarus and FPC that uses 3 gb.

hedgehog

  • Jr. Member
  • **
  • Posts: 65
Re: Animated toggle switch
« Reply #11 on: May 16, 2025, 07:37:00 am »
Hi all.

It's only been 19 months since the last post, sorry for the necroposting. I saw this thread yesterday.

I made this control a few years ago and forgot about it.
There is no animation yet, but it can be added.

P.S. This is a demo, please don't look at the code, it's terrible.

lainz

  • Hero Member
  • *****
  • Posts: 4723
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Animated toggle switch
« Reply #12 on: June 13, 2025, 01:58:43 am »
Cool hedgehog  :)

Your controls are good

cdbc

  • Hero Member
  • *****
  • Posts: 2220
    • http://www.cdbc.dk
Re: Animated toggle switch
« Reply #13 on: June 13, 2025, 08:41:11 am »
Hi
Cool - Me Likey - Gimme Gimme...  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

 

TinyPortal © 2005-2018