TAdvToolbar change button size at runtime

What would be the best practice to change the button size of a TAdvToolbar on a TAdvDockPanel?


Currently I have the TAdvGlowButtons all using a virtual image list and they scale depending on the Windows display scaling.  However, some customers still want larger buttons and images in general, and might want to adjust them during runtime.

I have tried using the ScaleForPPI method but I then also have to change the Width/Height of the virtual image list so that it pulls a larger image which really I do not want to have to do.  Also, switching using the ScaleForPPI sometime does not consistently correct the height of each TAdvToolbar (randomly, some might be slightly taller than others, making it look very uneven).

Any suggestions on the best approach?

On this same subject, is there a method to automatically resize all the toolbars in the dockpanel so they all fit without any "truncation", i.e. all buttons are shown, and toolbars wrap as needed so all fit?  I have used the ArrangeToolBars, but that doesn't seem to do a whole lot other than left justifying all toolbars so there is no white space between toolbars.  This is especially troublesome when changing the button size at runtime to a larger button.


If you want that both the button and the picture used on the button is scaled, I cannot see another solution than adapting the button size as well as the image size on the virtual imagelist.
To automatically position the toolbars, you can use AdvDockPanel.ArrangeToolBars.

I tried using the ArrangeTooBars, but it only seems to move the toolsbars to the left, eliminating any white space between the toolbars on the same line.  It does not seems to wrap them to prevent a toolbar from hiding some buttons that don't fit horizontally due to other toolbars on the same line.  I'd like to have toolbars expand to show all their buttons and force other toolbars that don't fit to move to the next line.  Only hide buttons when it is the only toolbar on the line and still does not fit the width of the dock panel.  Hope that made sense.


I played more with the scaling and this seems to work fairly well (see below).  But as mentioned previously, sometimes when scaling is applied, some of the toolbars have different heights than others.  I'll have to send you an example to better show what I mean.  I also found that Screen.PixlesPerInch remains at 96 even if dragged to another monitor that has different scaling, at least until a reboot.  The new FormBeforeMonitorDpiChanged and FormAfterMonitorDpiChanged events tell me what the DPI is really set to when moving a form to another monitor with different scaling, so I set a form variable to the DPI (fCurrentDPI), for the following code.  I have a popup menu with four sizes to pick from, Standard, Medium, Large and Extra Large (based on their tag)

procedure TfrmWhisperReporter.miTBSizeSelectClick(Sender: TObject);
var
  vStd, vMed, vLrg, vXLrg, vBitmapSize: Integer;
  vFactor: Single;
begin
  vStd := fCurrentPPI;                // 100%
  vMed := Trunc(fCurrentPPI * 1.25);  // 125%
  vLrg := Trunc(fCurrentPPI * 1.5);   // 150%
  vXLrg := Trunc(fCurrentPPI * 1.75); // 175%

  vFactor := fCurrentPPI div 6;
  vBitmapSize := Trunc(vFactor);

  case TMenuItem(Sender).Tag of
    1:
      begin
        tbEditorDockPanel.ScaleForPPI(vStd);  // 100%
        vBitmapSize := Trunc(vFactor);
      end;
    2:
      begin
        tbEditorDockPanel.ScaleForPPI(vMed);  // 125%
        vBitmapSize := Trunc(vFactor * 1.25);
      end;
    3:
      begin
        tbEditorDockPanel.ScaleForPPI(vLrg);  // 150%
        vBitmapSize := Trunc(vFactor * 1.5);
      end;
    4:
      begin
        tbEditorDockPanel.ScaleForPPI(vXLrg); // 175%
        vBitmapSize := Trunc(vFactor * 1.75);
      end;
  end;

  viListTBEditor_Active.Width := vBitmapSize;
  viListTBEditor_Active.Height := vBitmapSize;

  viListTBEditor_Disabled.Width := vBitmapSize;
  viListTBEditor_Disabled.Height := vBitmapSize;

  tbEditorDockPanel.ArrangeToolBars;
end;


We are currently checking the way you are implementing this.
We will give you an answer as soon as possible if and how it is feasible.



Do your buttons in the toolbars have different heights and is AutoSize set to true?
From
my experience, to get the DPI scale correctly you need to get the
PixelsPerInch from your monitor and not from the screen. The screen will
only retrieve the PixelsPerInch from your primary monitor.

A possible suggestion is for force a new autosize of the toolbar after scaling, i.e.


var
  I: Integer;
begin
  for I := 0 to AdvDockpanel1.ControlCount - 1 do
  begin
    if (AdvDockPanel1.Controls is TAdvToolBar) then
    begin
      (AdvDockPanel1.Controls as TAdvToolBar).AutoSize := false;
      (AdvDockPanel1.Controls as TAdvToolBar).AutoSize := true;
    end;
  end;
  AdvDockPanel1.ArrangeToolBars;
end;