tvplanit: Improved button positioning

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4954 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2016-07-14 12:20:59 +00:00
parent de164297ab
commit 91137d576a
4 changed files with 49 additions and 20 deletions

View File

@ -105,14 +105,14 @@ type
EMailLbl: TLabel;
EMailEdit: TEdit;
CategoryLbl: TLabel;
procedure OKBtnClick(Sender: TObject);
procedure cboxCountryChange(Sender: TObject);
procedure CancelBtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ItemChanged(Sender: TObject);
procedure cboxCountryChange(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure tsContactsChange(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure OKBtnClick(Sender: TObject);
procedure ItemChanged(Sender: TObject);
procedure tsContactsChange(Sender: TObject);
private
procedure SetCaptions;
procedure DisplayCurrentCountry;
@ -426,7 +426,7 @@ begin
{ Determine width of label based upon whether large or small fonts are
in effect. }
for i := Low(Labels) to High(Labels) do begin
Labels[i].FocusControl.Left := HBORDER + LargestLabelWidth + DIST;
Labels[i].FocusControl.Left := HBorder + LargestLabelWidth + Dist;
Labels[i].Left := Labels[i].FocusControl.Left - DIST - GetLabelWidth(Labels[i]);
Labels[i].Top := Labels[i].FocusControl.Top + (Labels[i].FocusControl.Height - Labels[i].Height) div 2;
end;
@ -459,7 +459,7 @@ begin
{ Set form width according to widest field }
corr := ClientWidth - tabMain.ClientWidth;
ClientWidth := LastNameEdit.Left + widestfield + HBORDER + corr;
ClientWidth := LastNameEdit.Left + widestfield + HBorder + corr;
{ Set edit and combo widths }
for i:= Low(Labels) to High(Labels) do
@ -477,7 +477,7 @@ begin
if Labels[i].Visible then begin
Labels[i].FocusControl.Top := FieldTop;
Labels[i].Top := FieldTop + delta;
inc(FieldTop, editHeight + VDIST);
inc(FieldTop, editHeight + VDist);
end;
{ Set form height such that first tab is filled completely by controls }
@ -513,22 +513,22 @@ begin
FieldTop := TopField;
for i:=Low(Comboboxes) to High(Comboboxes) do begin
Comboboxes[i].Left := HBORDER;
Comboboxes[i].Left := HBorder;
Comboboxes[i].Width := largestLabelWidth;
Comboboxes[i].Top := FieldTop;
inc(FieldTop, editHeight + VDIST);
inc(FieldTop, editHeight + VDist);
end;
for i:= Low(Edits) to High(Edits) do begin
Edits[i].Left := cboxPhoneLbl1.Left + cboxPhoneLbl1.Width + DIST;
Edits[i].Width := ClientWidth - Edits[i].Left - HBORDER - corr;
Edits[i].Width := ClientWidth - Edits[i].Left - HBorder - corr;
Edits[i].Top := Comboboxes[i].Top;
end;
EMailEdit.Left := Phone1Edit.Left;
EMailEdit.Width := Phone1Edit.Width;
EMailEdit.Top := Phone5Edit.Top + editHeight + VDIST;
EMailLbl.Left := EMailEdit.Left - GetLabelWidth(EMailLbl) - DIST;
EMailEdit.Top := Phone5Edit.Top + editHeight + VDist;
EMailLbl.Left := EMailEdit.Left - GetLabelWidth(EMailLbl) - Dist;
EMailLbl.Top := EMailEdit.Top + delta;
{ Page "User-defined" }
@ -544,14 +544,20 @@ begin
FieldTop := TopField;
for i := Low(Labels) to High(Labels) do begin
Labels[i].FocusControl.Left := HBORDER + LargestLabelWidth + DIST;
Labels[i].FocusControl.Left := HBorder + LargestLabelWidth + Dist;
Labels[i].FocusControl.Top := FieldTop;
Labels[i].FocusControl.Width := ClientWidth - Labels[i].FocusControl.Left - HBORDER - corr;
Labels[i].FocusControl.Width := ClientWidth - Labels[i].FocusControl.Left - HBorder - corr;
Labels[i].Width := LargestLabelWidth;
Labels[i].Left := Labels[i].FocusControl.Left - GetLabelWidth(Labels[i]) - DIST;
Labels[i].Left := Labels[i].FocusControl.Left - GetLabelWidth(Labels[i]) - Dist;
Labels[i].Top := FieldTop + delta;
inc(FieldTop, editHeight + VDIST);
inc(FieldTop, editHeight + VDist);
end;
OKBtn.Width := Max(GetButtonWidth(OKBtn), GetButtonWidth(CancelBtn));
CancelBtn.Width := OKBtn.Width;
CancelBtn.Left := pnlBottom.ClientWidth - HBorder - CancelBtn.Width;
OKBtn.Left := CancelBtn.Left - Dist - OKBtn.Width;
end;
procedure TContactEditForm.DisplayCurrentCountry;

View File

@ -132,6 +132,7 @@ function GetEndLine(EndTime: TDateTime; Granularity: TVpGranularity): Integer;
function LineToStartTime(Line: Integer; Granularity: TVpGranularity): TDateTime;
function GetLineDuration(Granularity: TVpGranularity): Double;
function GetButtonWidth(AButton: TButton): Integer;
function GetLabelWidth(ALabel: TLabel): Integer;
function GetRealFontHeight(AFont: TFont): Integer;
@ -599,6 +600,18 @@ begin
canvas.Free;
end;
function GetButtonWidth(AButton: TButton): Integer;
const
MARGIN = 16;
var
canvas: TControlCanvas;
begin
canvas := TControlCanvas.Create;
canvas.Control := AButton;
canvas.Font.Assign(AButton.Font);
Result := canvas.TextWidth(AButton.Caption) + 24 * Screen.PixelsPerInch div DesignTimeDPI;
end;
function GetRealFontHeight(AFont: TFont): Integer;
begin
if AFont.Size = 0 then

View File

@ -14,7 +14,7 @@ object TaskEditForm: TTaskEditForm
OnShow = FormShow
Position = poScreenCenter
LCLVersion = '1.7'
object Panel2: TPanel
object ButtonPanel: TPanel
Left = 0
Height = 37
Top = 303

View File

@ -51,7 +51,7 @@ type
{ TTaskEditForm }
TTaskEditForm = class(TForm)
Panel2: TPanel;
ButtonPanel: TPanel;
OKBtn: TButton;
CancelBtn: TButton;
PageControl1: TPageControl;
@ -106,7 +106,7 @@ type
implementation
uses
VpMisc;
Math, VpMisc;
{$IFDEF LCL}
{$R *.lfm}
@ -159,11 +159,17 @@ procedure TTaskEditForm.PositionControls;
var
VBevelDist: Integer; // Distance bevel-to-control
VDist: Integer; // Vertical distance between controls
HDist: Integer; // Horizontal distance between controls:
begin
VBevelDist := round(8 * Screen.PixelsPerInch / DesignTimeDPI);
VDist := round(8 * Screen.PixelsPerInch / DesignTimeDPI);
HDist := round(8 * Screen.PixelsPerInch / DesignTimeDPI);
DueDateEdit.Left := DueDateLbl.Left + GetLabelWidth(DueDateLbl) + 8;
DueDateEdit.Left := DueDateLbl.Left + GetLabelWidth(DueDateLbl) + HDist;
OKBtn.Width := Max(GetButtonWidth(OKBtn), GetButtonWidth(CancelBtn));
CancelBtn.Width := OKBtn.Width;
CancelBtn.Left := ButtonPanel.ClientWidth - ResourcenameLbl.Left - CancelBtn.Width;
OKBtn.Left := CancelBtn.Left - HDist - OKBtn.Width;
Bevel1.Top := BottomOf(DescriptionEdit) + VBevelDist;
@ -178,6 +184,10 @@ begin
DetailsMemo.Top := BottomOf(CreatedOnLbl) + VBevelDist;
DetailsMemo.Height := tabTask.ClientHeight - DetailsMemo.Top - DescriptionEdit.Top;
OKBtn.Top := (ButtonPanel.Height - OKBtn.Height) div 2;
CancelBtn.Top := OKBtn.Top;
ResourceNameLbl.Top := (ButtonPanel.Height - ResourceNameLbl.Height) div 2;
end;
{=====}