Modern.Forms icon indicating copy to clipboard operation
Modern.Forms copied to clipboard

fix checkbox width / Height - if autosize True;

Open blackholeearth opened this issue 10 months ago • 7 comments

blackholeearth avatar Mar 09 '25 00:03 blackholeearth

Unfortunately this is not the way to implement AutoSize correctly. You will need for CheckBox to override Control.GetPreferredSizeCore and calculate a new size that takes every possible size modifier into account, eg:

  • Font
  • Text
  • Check glyph
  • Image
  • ImageTextRelation
  • Border width
  • Padding

jpobst avatar Mar 09 '25 08:03 jpobst

var result = TextImageLayoutEngine.Layout (this); already taking care of everything. BUT its not sending result information to control's height/Width.

so i override the checkbox.GetPreferredSize() . add layout mesuremnts there.

edit: i realized you have written GetPreferredSizeCore . if its wrong, i can move the code there. but it work inside ""GetPreferredSize"" ??

current state

https://github.com/user-attachments/assets/69d1b1bd-8e75-465f-826c-48fed0cee802

blackholeearth avatar Mar 09 '25 14:03 blackholeearth

  • also textalign , imagealign , glypalign ,, after these changed.. need to call trigger autosize . othwerwise . the control are may get bigger on each change of these enums.
    • [edit: done]

i realized radiobutton also has the same problem

blackholeearth avatar Mar 09 '25 14:03 blackholeearth

i realized you have written GetPreferredSizeCore . if its wrong, i can move the code there. but it work inside ""GetPreferredSize"" ??

Overriding Control.GetPreferredSize breaks all the AutoSize logic in there. If you override Control.GetPreferredSizeCore then you shouldn't need to call anything in the property setters like TextAlign (as long as they already have the LayoutTransaction.DoLayoutIf (AutoSize, Parent, this, PropertyNames.TextAlign) call).

i realized radiobutton also has the same problem

Yes, the Size calculate_AutosizeArea () code probably needs to go into TextImageLayoutEngine.GetPreferredSize (Control control, Size proposedSize). Then it can be called by all the Controls that use TextImageLayoutEngine like Button, Label, RadioButton, and CheckBox.

jpobst avatar Mar 09 '25 22:03 jpobst

since i am a noob in this repo - baby steps for me .

i moved calculate_AutosizeArea into GetPrefferredSizeCore. it Works same as GetPrefferredSize ..

no problem here..


then

i removed Trigger_Resizing() from the chekbox's enums (TextRealation etc)

but if i do that; on every Enum change (TextRealation etc) , Checkbox Size gets bigger bigger…

see here:

https://github.com/user-attachments/assets/77d48c31-cd8c-469e-903d-19f906856b8f


so, until real Fix is found, i ll keep triggerResizing() as Hack..


a question:

currently in calculate_AutosizeArea ; i am using TextImageLayoutData.layout() //just like you do in the ChekboxRenderer..

but the TextImageLayoutData.layout

i do calculation believing that info result of TextImageLayoutData.layout() is correct ??

blackholeearth avatar Mar 10 '25 15:03 blackholeearth

I don't think TextImageLayoutData.Layout () is going to work for this purpose. It is designed to fit the content the best it can within a predetermined size.

You need the opposite: what is the ideal size to fit the content?

jpobst avatar Mar 11 '25 00:03 jpobst

instead of x.y posititons ..

latest code uses engine.layout() . widths Heights.

now enums dont need trigger resizing.

blackholeearth avatar Mar 11 '25 23:03 blackholeearth