mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-16 23:49:28 +02:00
LCL/Dialogs: Auto-sized layout for InputCombo(Ex). Fixes issue #39410.
This commit is contained in:
parent
d33a33921c
commit
608ffc5ee9
@ -110,50 +110,76 @@ var
|
|||||||
CBSelect : TComboBox;
|
CBSelect : TComboBox;
|
||||||
LPrompt: TLabel;
|
LPrompt: TLabel;
|
||||||
BP: TButtonPanel;
|
BP: TButtonPanel;
|
||||||
|
P: TPanel;
|
||||||
begin
|
begin
|
||||||
Margin:=24;
|
|
||||||
Sep:=8;
|
|
||||||
Result:='';
|
Result:='';
|
||||||
ASelected:=-1;
|
ASelected:=-1;
|
||||||
Frm:=TForm.Create(Application);
|
frm := TForm.Create(Application);
|
||||||
try
|
try
|
||||||
|
Margin:= frm.Scale96ToForm(16);
|
||||||
|
Sep := frm.Scale96ToForm(8);
|
||||||
|
|
||||||
|
frm.BorderStyle:=bsDialog;
|
||||||
|
frm.Caption:=ACaption;
|
||||||
|
frm.Position:=poScreenCenter;
|
||||||
|
|
||||||
// Determine needed width
|
// Determine needed width
|
||||||
W:=frm.Canvas.TextWidth(APrompt);
|
W:=frm.Canvas.TextWidth(APrompt);
|
||||||
W:=Max(W,frm.Canvas.TextWidth(ACaption));
|
W:=Max(W,frm.Canvas.TextWidth(ACaption));
|
||||||
for I:=0 to AList.Count-1 do
|
for I:=0 to AList.Count-1 do
|
||||||
W:=Max(W,frm.Canvas.TextWidth(AList[i]+'WWW')); // WWW is just some extra.
|
W:=Max(W,frm.Canvas.TextWidth(AList[i]+'WWW')); // WWW is just some extra.
|
||||||
frm.BorderStyle:=bsDialog;
|
|
||||||
frm.Caption:=ACaption;
|
// Panel for controls
|
||||||
frm.ClientWidth:=W+2*Margin;
|
P := TPanel.Create(frm);
|
||||||
frm.Position:=poScreenCenter;
|
P.Parent := frm;
|
||||||
|
P.Align := alClient;
|
||||||
|
P.Borderspacing.Around := Margin;
|
||||||
|
P.Caption := '';
|
||||||
|
P.BevelOuter := bvNone;
|
||||||
|
P.AutoSize := true;
|
||||||
|
|
||||||
// Prompt
|
// Prompt
|
||||||
LPrompt:=TLabel.Create(frm);
|
LPrompt:=TLabel.Create(frm);
|
||||||
LPrompt.Parent:=frm;
|
LPrompt.Parent:=P; //frm;
|
||||||
LPrompt.Caption:=APrompt;
|
LPrompt.Caption:=APrompt;
|
||||||
LPrompt.SetBounds(Margin,Margin,Frm.ClientWidth-2*Margin,frm.Canvas.TextHeight(APrompt));
|
LPrompt.AnchorSideTop.Control := P;
|
||||||
|
LPrompt.AnchorSideLeft.Control := P;
|
||||||
|
LPrompt.AnchorSideRight.Control := P;
|
||||||
|
LPrompt.AnchorSideRight.Side := asrBottom;
|
||||||
|
LPrompt.BorderSpacing.Bottom := Sep;
|
||||||
|
LPrompt.Anchors := [akLeft, akRight, akTop];
|
||||||
LPrompt.WordWrap:=True;
|
LPrompt.WordWrap:=True;
|
||||||
LPrompt.AutoSize:=False;
|
LPrompt.AutoSize:=true;
|
||||||
|
|
||||||
// Selection combobox
|
// Selection combobox
|
||||||
CBSelect:=TComboBox.Create(Frm);
|
CBSelect:=TComboBox.Create(Frm);
|
||||||
CBSelect.Parent:=Frm;
|
CBSelect.Parent:=P;
|
||||||
CBSelect.Style:=CBStyles[AllowInput];
|
CBSelect.Style:=CBStyles[AllowInput];
|
||||||
CBSelect.Items.Assign(AList);
|
CBSelect.Items.Assign(AList);
|
||||||
CBSelect.ItemIndex:=-1;
|
CBSelect.ItemIndex:=-1;
|
||||||
CBSelect.Left:=Margin;
|
CBSelect.AnchorSideTop.Control := LPrompt;
|
||||||
CBSelect.Top:=LPrompt.Top + LPrompt.Height + Sep;
|
CBSelect.AnchorSideTop.Side := asrBottom;
|
||||||
CBSelect.Width:=Frm.ClientWidth-2*Margin;
|
CBSelect.AnchorSideLeft.Control := P;
|
||||||
|
CBSelect.AnchorSideRight.Control := P;
|
||||||
|
CBSelect.AnchorSideRight.Side := asrBottom;
|
||||||
|
CBSelect.Anchors := [akLeft, akRight, akTop];
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
BP:=TButtonPanel.Create(Frm);
|
BP:=TButtonPanel.Create(Frm);
|
||||||
BP.Parent:=Frm;
|
BP.Parent:=Frm;
|
||||||
BP.ShowButtons:=[pbOK,pbCancel];
|
BP.ShowButtons:=[pbOK,pbCancel];
|
||||||
Frm.ClientHeight:=LPrompt.Height+CBSelect.Height+BP.Height+2*Sep+Margin;
|
|
||||||
if (Frm.ShowModal=mrOk) then
|
// Autosize the form
|
||||||
|
frm.AutoSize := true;
|
||||||
|
frm.Constraints.MinWidth := W + 2*Margin;
|
||||||
|
|
||||||
|
if (frm.ShowModal=mrOk) then
|
||||||
begin
|
begin
|
||||||
Result:=CBSelect.Text;
|
Result:=CBSelect.Text;
|
||||||
ASelected:=CBSelect.ItemIndex;
|
ASelected:=CBSelect.ItemIndex;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
FreeAndNil(Frm);
|
FreeAndNil(frm);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user