Jump to content

Fading UniPanel In and Out depending on Visible Property


Kattes

Recommended Posts

Hi,
I have a little problem to get a UniPanel "fadeOut" when changing its property "visible" from true to false - the other direction (fadeIn) works fine.

Fade in is programmed as followed:

UniPanelStatus.ClientEvents.ExtEvents.Add('show=function show(sender, eOpts){'+
                                             'sender.el.setOpacity(0); '+
                                             'sender.el.fadeIn({duration: 500});'+
                                             '}'
                                           );

How has  a valid solution for "fadeOut" look like?

I tried the following without success:

UniPanelStatus.ClientEvents.ExtEvents.Add('hide=function hide(sender, eOpts){'+
                                             'sender.el.setOpacity(1); '+
                                             'sender.el.fadeOut({duration: 500});'+
                                             '}'
                                          );

 

Link to comment
Share on other sites

Hi Sherzod,
Yes, I saw this older post and finally was inspired by it, but my goal is that whenever I change the "visible" property of any unigui control that this gets faded in or out (depending if visible is true or false).

Link to comment
Share on other sites

But don not waste too much of your time on it. I also found a different solution which is suitable for me .

unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, uniGUITypes, uniGUIAbstractClasses,
  uniGUIClasses, uniGUIRegClasses, uniGUIForm, uniPanel, uniGUIBaseClasses,
  uniButton, Vcl.Imaging.jpeg, uniImage, uniEdit, uniSpinEdit;

type
  TMainForm = class(TUniForm)
    UniButton1: TUniButton;
    UniPanel1: TUniPanel;
    UniImage1: TUniImage;
    UniEdit1: TUniEdit;
    UniEdit2: TUniEdit;
    UniSpinEdit1: TUniSpinEdit;
    procedure UniButton1Click(Sender: TObject);
  private
    { Private declarations }
    bToggle : boolean;
  public
    { Public declarations }
  end;

function MainForm: TMainForm;

implementation

{$R *.dfm}

uses
  uniGUIVars, MainModule, uniGUIApplication;

procedure FadeInOut(xControl: TUniControl; bFadeOut: boolean; const Duration : integer = 300);
begin
  if bFadeOut then
    xControl.JSInterface.JSCode(#1'.el.fadeOut({duration: '+IntToStr(Duration)+'});')
  else
    xControl.JSInterface.JSCode(#1'.el.fadeIn({duration: '+IntToStr(Duration)+'});')
end;

function MainForm: TMainForm;
begin
  Result := TMainForm(UniMainModule.GetFormInstance(TMainForm));
end;

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  bToggle :=  not bToggle;
  FadeInOut(UniPanel1, bToggle, UniSpinEdit1.Value);
  FadeInOut(UniImage1, bToggle, UniSpinEdit1.Value);
end;

initialization
  RegisterAppFormClass(TMainForm);
end.

image.png.ea934d608537dc7f4308d416cc169eff.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...