Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PointToScreen() doesn't respect the spacing set in parent DynamicLayout. An eto bug. #2651

Open
WileyNg opened this issue May 12, 2024 · 0 comments

Comments

@WileyNg
Copy link

WileyNg commented May 12, 2024

Expected Behavior

PointToScreen should produce accurate result.

Actual Behavior

PointToScreen() doesn't take into account of the spacing/padding and it is always shifted whenever parent DynamicLayout has padding or spacing.

Code that Demonstrates the Problem

[Paste your code here]
```C#
            var form = new Eto.Forms.Form();
            var targetButton = new Button { Text = "target button" }
            var layout = new DynamicLayout();
             layout.BeginVertical(new Padding(12, 12, 0, 0));
            layout.AddRow(new Button {Text="Testing" });
            layout.AddRow(new Button {Text="Testing2" });
            layout.EndBeginVertical(new Padding(34, 14, 16, 2), spacing: new Size(12, 6));
            layout.AddRow(targetButton);
            layout.AddRow(new Button { Text = "Testing" });

            Rhino.RhinoApp.WriteLine($"{parentControl.PointFromScreen(targetButton.PointToScreen(new PointF(0, 0)))}"); 
            // the point printed is wrong. it doesn't take into account of the spacing 

        /// <summary>
        /// PointToScreen doesn't respect the spacing set in parent DynamicLayout. An eto bug.
        /// </summary>
        /// <param name="parentControl"></param>
        /// <returns></returns>
        private PointF FindTrueTopLeftPointInControl(Control parentControl)
        {
            var yOffset = 0f;
            var xOffset = 0f;
            if (Parent is DynamicLayout dl)
            {
                foreach (var rows in dl.Rows)
                    foreach (DynamicTable row in rows)
                        for (int i = 1; i < row.Rows.Count; i++)
                            if (row.Rows[i][0] is DynamicControl dc)
                                if (dc.Control is CustomButton cb)
                                    if (cb == this)
                                    {
                                        yOffset = row.Spacing.Value.Height / 2f;
                                        break;

                                    }
                if (parentControl is Popup popup && popup.HasShadow)
                {
                    yOffset += Settings.Instance.General.ShadowPadding;
                    xOffset = Settings.Instance.General.ShadowPadding;
                }
            }
            return parentControl.PointFromScreen(PointToScreen(new PointF(-xOffset, -yOffset)));

        }
<!-- Please specify the version of Eto and all platforms this can be reproduced in -->
## Specifications

  - Version:
  - Platform(s): Rhino 7 in Windows 11
  - Operating System(s):  E.g. Windows 11 
  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant