Jump to content
igors233

ShowDialog improvement

Recommended Posts

Application.ShowDialog creates TW3AlertDialog and specifies fixed size (280x200), in lot of cases that size isn't good (text is clipped). It's necessary to have a mechanism to customize this dialog (change dialog size mostly, text size and font and buttons caption).

It would be also good that dialog dynamically change to accomodate text size (shrinks for small texts and grows for large)

Share this post


Link to post
Share on other sites

In case someone needs a auto adjust size solution, change TW3CustomApplication.ShowDialog to

 

 

procedure TW3CustomApplication.ShowDialog(aCaption: String;aText: String; aOptions: TW3AlertOptions);
var
  dx, dy: Integer;
  Temp: TW3TextMetric;
begin
  if not GetDialogActive then
  begin
    FBlockBox := TW3BlockBox.Create(Display);
    FBlockBox.SetBounds(0, 0, Display.Width, Display.Height);

    (* We want to center our dialog should the blockbox be
       resized. So we hook into the resize mechanism *)
    FBlockBox.OnResize := HandleDialogBlockerReSize;

    FDialog := TW3AlertDialog.Create(FBlockBox);
    FDialog.OnSelect := HandleDialogFeedBack;

    if Length(aText) > 0 then
    begin
      Temp := W3FontDetector.MeasureText(W3FontDetector.getFontInfo(FDialog.Handle), aText);
      FDialog.Width := Max(280, Temp.tmWidth);
      FDialog.Height := Max(200, Temp.tmHeight);
    end;

//    FDialog.Width := 280;
  //  FDialog.Height := 200;

    dx := (FBlockBox.Width - FDialog.Width) div 2;
    dy := (FBlockBox.Height - FDialog.Height) div 2;

    FDialog.SetBounds(dx,dy,FDialog.Width,FDialog.Height);
    (FDialog as IW3AlertDialog).SetupDialog(aCaption, aText, aOptions);
  end else
    raise EW3Application.Create('A dialog is already active error');
end;
 

Share this post


Link to post
Share on other sites

+1 Would also appreciate a more dynamic box to use.

What do you mean? Do you mean that the RTL should include an overloaded version with specifyable dimensions?

Share this post


Link to post
Share on other sites

Thanks! it's been a while since i last used it but i did recall wanting an easier way access the internal components of the dialog to do things like set the style-class for the components used in it too, (I believe they were called something like .TW3AlertDialog and .TW3AlertButton in the style sheet so i just replaced those instead).

Share this post


Link to post
Share on other sites

Just as a notification: The overloaded ShowDialog() method has been implemented to the RTL and will be available with the next update. With it, you'll be able to define the dimensions of the dialog window. For additional customization like the font you'll however still need to stick to the OOP TW3AlertDialog way. ;)

Share this post


Link to post
Share on other sites

PS: You can run SmartUpdate.exe in your SMS Alpha directory to get the latest Alpha update. This should contain this change, aside with other improvements and additions. ;)

Share this post


Link to post
Share on other sites

The ShowDialog function could do with a bit more love. Currently it is not possible to entirely style the box and contents. Which limits the effectiveness of the dialog when it doesn't play nice with the form styling. In our case we all often have CSS applied to labels and form etc that are not suitable for a more business like dialog box.

 

For example I get the following result. The image shows that the title has the bottom cut off the letter "g"

 

dialogs.jpg

 

Can you please open it up so that we can style the entire dialog using css. Cheers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×