Search code examples
androidiosdelphifiremonkeydelphi-xe8

Increase size of FireMonkey TSpeedButton image


Using a FireMonkey TspeedButton on a form for a cross platform app, when setting the property StyleLookup to use cameratoolbutton is there any way of changing the size of this image, I can't seem to find anything.


Solution

  • There are at least two ways to do this, but all based on using stylebook.

    First, simplest way - edit cameratoolbutton style in stylebook:

    1. Load style into stylebook and open it
    2. Scroll to cameratoolbutton item in Structure panel

    enter image description here

    1. Find icon subitem and change it's properties in Object Inspector. For example, you can change Align (Client by default) and WrapMode (Center by default)

    Second way - do it in runtime. Add OnApplyStyleLookup event handler to button and write code to work with style items:

    procedure THeaderFooterForm.btn2ApplyStyleLookup(Sender: TObject);
    var
      obj: TFmxObject;
    begin
      obj:=TFmxObject(Sender).FindStyleResource('icon'); // use StyleName of inner object (see prev. picture)
      if Assigned(obj) and (obj is TStyleObject) then // TStyleObject is class of "icon"  (see prev. picture)
        TStyleObject(obj).WrapMode:=TImageWrapMode.Stretch;
    end;
    

    Note 1: by default, you can't change size of cameratoolbutton, because when you run program, it's size returns to hardcoded values. If you need this, you must do next workaround:

    1. Save your style from stylebook in .style file
    2. Open this file in any text editor (Notepad++, for example)
    3. Find next strings
    object TLayout
      StyleName = 'cameratoolbutton'
      Visible = False
      TabOrder = 160
      FixedWidth = 44
      FixedHeight = 44
    
    1. Remove FixedXXX strings and save file
    2. Load changed file to stylebook

    Note 2: style uses bitmaps, so if you need large/small picture, perhaps, you should use your own images