lcl: label: change left when making label visible for right-aligned autosized label. issue #21898

This commit is contained in:
Ondrej Pokorny 2022-11-27 19:17:31 +01:00
parent 316d8c1de0
commit 369b6b255e
2 changed files with 24 additions and 0 deletions

View File

@ -262,6 +262,29 @@ begin
Invalidate; Invalidate;
end; end;
procedure TCustomLabel.SetVisible(Value: Boolean);
var
OldWidth, OldLeft: Integer;
begin
// when changing to Visible, the width gets updated, check for right aligment and change left just like it is done in UpdateSize
// see issue #21898
if Value and not Visible then
begin
OldWidth := Width;
OldLeft := Left;
end else
begin
OldWidth := -1;
OldLeft := -1;
end;
inherited SetVisible(Value);
if (OldWidth>=0) and (AutoSize or OptimalFill) and (Alignment=taRightJustify)
and (OldWidth<>Width) and (OldLeft=Left) then
Left := Left-Width+OldWidth;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCustomLabel.SetWordWrap Method: TCustomLabel.SetWordWrap
Params: None Params: None

View File

@ -1598,6 +1598,7 @@ type
procedure SetWordWrap(Value: Boolean); procedure SetWordWrap(Value: Boolean);
procedure Loaded; override; procedure Loaded; override;
procedure UpdateSize; procedure UpdateSize;
procedure SetVisible(Value: Boolean); override;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify; property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
property FocusControl: TWinControl read FFocusControl write SetFocusControl; property FocusControl: TWinControl read FFocusControl write SetFocusControl;