The article “Chameleon” discussed in detail the mechanism for managing the styles of applications created on the My Visual Database platform, and it is proposed to use the main menu item as a style selection element.

The solution is simple, but the list of items for choosing a style turned out to be impressive, it draws all the user’s attention to itself. This was fine for a demo application, but in a production project, the style selection process should be more modest.

I want to draw your attention to the existing main menu item: Tools – Settings, which, when selected, opens the application settings window.

It seems to me that this is where the style selector element should be. To implement the plan, you need to add another tab, calling it “Appearance”. On this tab, place a drop-down list to select a style.

procedure Style_CreateOptions;
// adding a style setting to the standard settings window
var
  tmpSheet: TTabSheet;
  tmpCombo: TdbComboBox;
  tmpLabel: TdbLabel;
begin
  // добавить вкладку
  tmpSheet := TTabSheet.Create( frmOptionsDBCore );
  tmpSheet.Name := 'tshViewMode';
  tmpSheet.PageControl := frmOptionsDBCore.PageControl1;
  tmpSheet.Caption := 'Appearance';
  // add list with styles
  tmpCombo := Style_CreateComboBox( frmOptionsDBCore );
  tmpCombo.Parent := tmpSheet;
  tmpCombo.Top := 30;
  tmpCombo.Left := 10;
  // add label
  tmpLabel := TdbLabel.Create( frmOptionsDBCore );
  tmpLabel.Parent := tmpSheet;
  tmpLabel.Top := 14;
  tmpLabel.Left := 10;
  tmpLabel.Caption := 'Style';
end;Code language: Delphi (delphi)

If the application has its own window with settings, then it is quite logical to move the functionality for creating a drop-down list with styles into separate procedures:

function Style_CreateComboBox( AForm: TForm ):TdbComboBox;
// creating a dropdown list with styles
var
  i: integer;
begin
  Result := TdbComboBox.Create(AForm);
  Result.Parent := AForm;
  Result.onChange := @Style_ComboBox_OnChange;
  // add entries to change the style
  for i := 0 to Length(arStyles) - 1 do
  begin
    Result.dbAddRecord( i, arStyles[i] );
    // select current style
    if arStyles[i] = currentStyleName then
      Result.dbItemID := i;
  end;
end;

procedure Style_ComboBox_OnChange (Sender: TObject);
// select a style from the list
begin
  Style_SetStyle( TdbComboBox(Sender).Text );
end;
Code language: PHP (php)

After calling the Style_CreateOptions() procedure, the appearance of the settings form has changed:

Write in the comments what else would you like to know about styles? What features to add? For example, do you need a style browser: a list of styles with a textual description and illustration of the look and feel that an application acquires after applying it?

Leave a Reply

Your email address will not be published. Required fields are marked *