Recent

Author Topic: Custom AutoSize and remove controls from inherited AlignControls  (Read 807 times)

ps

  • Full Member
  • ***
  • Posts: 136
    • CSS
I have TCustomPanel with  own AlignControls to align some (99%) controls by my way. I would like to have both align system: my own + original LCL for other controls.

It's possible remove "my" controls from LCL alignment (because of performance)?

Code: Pascal  [Select][+][-]
  1. procedure THtmlPanel.AlignControls(AControl: TControl;
  2.   var RemainingClientRect: TRect);
  3. begin
  4.   ResizeControlsByHtml; // here is my logic to align 2001 controls
  5.   inherited AlignControls(AControl, RemainingClientRect); // please align only ONE control, not 2002 :)
  6. end;      

Code: Pascal  [Select][+][-]
  1.   btn := TButton.Create(Self);
  2.   btn.Caption := 'This button will be alligned by LCL';
  3.   btn.Parent :=  HtmlPanel;
  4.   btn.Align := alTop;
  5.   btn.BorderSpacing.Top := 50;  
  6.  
  7.   for I := 0 to 2000 do begin
  8.     shape := THtmlGraphicControl.Create(Self);
  9.     shape.Align := alCustom;
  10.     shape.HTML.Name := 'OBJ:' + I.ToString;
  11.     shape.HTML.InlineStyle := 'width:' + (5+Random(10)).ToString + 'px;border:1px solid red;background-color: #ffff' + Random(255).ToHexString(2) + ';display:inline;height:' + (2+ random(30)).ToString+ 'px;';
  12.     if I mod 100 = 0 then
  13.       shape.HTML.InlineStyle := shape.HTML.InlineStyle + 'display:block;background-color:red;';
  14.     shape.Parent := HtmlPanel;
  15.   end;
  16.  


Where is correct way to calculate Height of control for autosize. (now  my calculation is in ResizeControlsByHtml). It's correct?
Code: Pascal  [Select][+][-]
  1. procedure THtmlPanel.CalculatePreferredSize(var PreferredWidth,
  2.   PreferredHeight: integer; WithThemeSpace: Boolean);
  3. begin
  4.   inherited CalculatePreferredSize(PreferredWidth, PreferredHeight,
  5.     WithThemeSpace);
  6.   if (AutoSize) and (FAutoHeight>PreferredHeight) then
  7.     PreferredHeight := FAutoHeight; // height calculated in ResizeControlsByHtml
  8. end;
« Last Edit: October 30, 2019, 01:26:23 pm by ps »
Small simple CSS/box model implementation: https://github.com/pst2d/csscontrols/tree/dev

 

TinyPortal © 2005-2018