Skip to content

[Grid] Fix size calculation for ranges #18621

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

Merged
merged 7 commits into from
Apr 11, 2025

Conversation

kebox7
Copy link
Contributor

@kebox7 kebox7 commented Apr 10, 2025

What does the pull request do?

This PR fixes the calculation of the size of merged cells when setting the RowSpan and ColumnSpan properties.
Sample code for sandbox:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
        x:Class="Sandbox.MainWindow"
        Width="550"
        Height="240">

  <Grid RowDefinitions="*,Auto" RowSpacing="10"
        Grid.IsSharedSizeScope="True"
        Margin="10">

    <Grid RowDefinitions="Auto,*,Auto,Auto" RowSpacing="10"
          ColumnSpacing="10"
          ShowGridLines="True"
          Background="Moccasin">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="Auto" SharedSizeGroup="C3" />
      </Grid.ColumnDefinitions>

      <ScrollViewer Grid.Row="0" Grid.RowSpan="3"
                    Grid.Column="0" Grid.ColumnSpan="3"
                    HorizontalScrollBarVisibility="Auto"
                    VerticalScrollBarVisibility="Auto">
        <TextBlock>
          0: 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890<LineBreak />
          1: 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890<LineBreak />
          2: 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890<LineBreak />
          3: 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890<LineBreak />
          4: 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890<LineBreak />
          5: 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890<LineBreak />
          6: 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890<LineBreak />
          7: 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890<LineBreak />
          8: 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890<LineBreak />
          9: 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
        </TextBlock>
      </ScrollViewer>

      <Button Grid.Row="0" Grid.Column="3"
              Width="100" Height="40"
              HorizontalContentAlignment="Center"
              VerticalContentAlignment="Center"
              Content="Button R0" />
      <Button Grid.Row="2" Grid.Column="3"
              Width="100" Height="40"
              HorizontalContentAlignment="Center"
              VerticalContentAlignment="Center"
              Content="Button R2" />

      <Button Grid.Row="3" Grid.Column="0"
              Width="100" Height="40"
              HorizontalContentAlignment="Center"
              VerticalContentAlignment="Center"
              Content="Button C0" />
      <Button Grid.Row="3" Grid.Column="2"
              Width="100" Height="40"
              HorizontalContentAlignment="Center"
              VerticalContentAlignment="Center"
              Content="Button C2" />
    </Grid>

    <Grid Grid.Row="1" Background="Moccasin">
      <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition Width="Auto" SharedSizeGroup="C3" />
      </Grid.ColumnDefinitions>

      <TextBlock Grid.Column="1"
                 Height="20"
                 Text="1234567890"/>
    </Grid>
  </Grid>
</Window>

What is the current behavior?

2025-04-09 173703

What is the updated/expected behavior with this PR?

2025-04-09 173825

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0055977-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added bug backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Apr 10, 2025
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0055985-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0055989-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

double requestedSize,
double percentReferenceSize)
double spacing,
double desiredSize)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was really confused at the removal of percentReferenceSize here (we ideally don't want to touch code that isn't related to spacing). But apparently this parameter was never used! It's the same thing in the original WPF source code.

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@MrJul MrJul added this pull request to the merge queue Apr 11, 2025
Merged via the queue into AvaloniaUI:master with commit f42af48 Apr 11, 2025
10 checks passed
@kebox7 kebox7 deleted the fix/grid-measuresizeforrange branch April 11, 2025 14:31
MrJul pushed a commit that referenced this pull request Apr 12, 2025
* Fix size calculation for range

* Add unit tests

* Clean code

* More correct fix

* Clean code (remove unused params)

* Delete accidentally added file
@MrJul MrJul added backported-11.3.x and removed backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants