program fpgui_mig_Demo;
{$mode objfpc}{$H+}
{-$define dbg}
/// for public domain \\\
uses /// made for your amusement by Benny Christensen a.k.a. cdbc \\\
classes, sysutils, fpg_cmdlineparams,
fpg_main, fpg_form, fpg_base, fpg_label, fpg_edit, fpg_button, fpg_panel,
fpg_mig_cc, fpg_miglayout, fpg_stylemanager, fpg_style_plastic;
{ using the new MIG-layout-manager }
type
{ TMainForm }
TMainForm = class(TfpgForm)
private
lblNavn: TfpgLabel;
edtNavn: TfpgEdit;
btnGem: TfpgButton;
stbInfo: TfpgPanel;
procedure HandleFormKeyPress(Sender: TObject; var KeyCode: word;
var ShiftState: TShiftState; var Consumed: boolean);
procedure SetupLayout;
public
procedure AfterCreate; override;
end;
var cmd: ICmdLineParams = nil; lstyle: string = 'plastic-dark';
procedure TMainForm.AfterCreate;
begin
inherited AfterCreate;
Left:= 100; Top:= 100; Width:= 365; Height:= 140;
WindowTitle := 'MigLayout Demo <'+lstyle+'>';
{ setup components - note we don't have to set X, Y, Width, Height here! }
lblNavn := TfpgLabel.Create(self);
lblNavn.Text := 'Your Name:';
edtNavn := TfpgEdit.Create(self);
edtNavn.Text := '';
btnGem := TfpgButton.Create(self);
btnGem.Text := 'Save Data';
stbInfo:= TfpgPanel.Create(Self); { <--- i'm missing a statusbar, }
stbInfo.Alignment:= taLeftJustify; { so this'll have to do %) }
stbInfo.Style:= bsLowered; { baby steps \o/\ö/\o/ }
stbInfo.Height := 25; { defining a preferred height for StatusBar /gg }
stbInfo.Text:= '[Ctrl + Q] = Quit';
SetupLayout; { employs the MIG-Layout-manager :o) }
OnKeyPress:= @HandleFormKeyPress; { convenience with 'Ctrl+Q' to close/quit }
end;
procedure TMainForm.HandleFormKeyPress(Sender: TObject; var KeyCode: word;
var ShiftState: TShiftState; var Consumed: boolean);
var ct: boolean;
begin
ct:= ssCtrl in ShiftState;
case KeyCode of
$51: if ct then begin
Consumed:= true; { <- important }
Close; { Ctrl + Q ~ fpg_key_q }
end;
end;
end;
(* Note from Graeme @ https://forum.lazarus.freepascal.org/index.php/topic,73452.msg576274/topicseen.html#msg576274
The .Fill on the LC (layout constraint) will allow all cells to grow and take up
all available space. Meaning it will push your StatusBar (panel) all the way down.
The .Debug is simply so you can visually see how mig calculated the cell sizes
and component sizes. *)
procedure TMainForm.SetupLayout;
var layout: TfpgMigLayoutManager;
begin
{ initialize MigLayout }
layout := TfpgMigLayoutManager.Create;
{ Graeme: LC.Fill is key, note: '.Debug' facilitates grid-lines when designing }
layout.LC.Fill{$ifdef dbg}.Debug{$endif};
layout.AddLayoutComponent(lblNavn, TfpgMigCC.Create); { simplified by /gg }
{ growx = stretch horz }
layout.AddLayoutComponent(edtNavn, TfpgMigCC.Create.GrowX); { simplified by /gg }
layout.AddLayoutComponent(btnGem, TfpgMigCC.Create); { simplified by /gg }
layout.AddLayoutComponent(stbInfo, TfpgMigCC.Create.DockSouth); { simplified by /gg }
{ activate our layout }
LayoutManager:= layout;
end;
begin
fpgApplication.Initialize;
if fpgApplication.GetInterface(ICmdLineParams,cmd) then begin { nifty little com-obj }
{ i don't like spaces in cmdline params, so i alias it ;) }
fpgStyleManager.RegisterClass(lstyle,TfpgPlasticDarkStyle);
{ if the user provided a style-choice, we'll roll with that }
if cmd.HasOption('style') then lstyle:= cmd.GetOptionValue('style');
fpgStyleManager.SetStyle(lstyle); { or we'll just use some plastic :o) }
end;
with TMainForm.Create(nil) do try
Show;
fpgApplication.Run;
finally Free; end;
end.