Skip to content

feat: add TreeViewItemIndentConverter for dynamic margin calculation #18718

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 1 commit into from
Jun 18, 2025

Conversation

zdpcdt
Copy link
Contributor

@zdpcdt zdpcdt commented Apr 24, 2025

What does the pull request do?

This pull request refactors how indentation is applied to TreeViewItem elements in both the Fluent and Simple themes of Avalonia.

What is the current behavior?

What is the updated/expected behavior with this PR?

It introduces a new converter, TreeViewItemIndentConverter, to handle indentation dynamically, replacing the previous static converters and hardcoded implementations.

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

Introduction of a new converter:

Updates to the Fluent theme:

Updates to the Simple theme:

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

#18311

@avaloniaui-bot
Copy link

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

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Apr 24, 2025

  • All contributors have signed the CLA.

@zdpcdt
Copy link
Contributor Author

zdpcdt commented Apr 24, 2025

@cla-avalonia agree

@MrJul MrJul added the feature label Apr 24, 2025
@maxkatz6 maxkatz6 added the needs-api-review The PR adds new public APIs that should be reviewed. label May 16, 2025
@MrJul
Copy link
Member

MrJul commented Jun 10, 2025

API diff for review:

+namespace Avalonia.Controls.Converters
+{
+    public class TreeViewItemIndentConverter : IMultiValueConverter
+    {
+        public static readonly TreeViewItemIndentConverter Instance;
+        public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture);
+    }
+}

@rabbitism
Copy link
Contributor

API diff for review:

+namespace Avalonia.Controls.Converters
+{
+    public class TreeViewItemIndentConverter : IMultiValueConverter
+    {
+        public static readonly TreeViewItemIndentConverter Instance;
+        public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture);
+    }
+}

This can be internal.

@MrJul
Copy link
Member

MrJul commented Jun 18, 2025

Notes from the API review:

We spent quite a bit of time debating whether this should be added to Avalonia.Controls.Converters, be internal, or be public but theme-specific.

First, we rejected internal to allow users to easily copy and paste an existing ControlTheme to their own project, without having to copy a bunch of related internal types.

Regarding whether the converter should be part of Avalonia.Controls or Avalonia.Themes.<...>, we believe consistency is the most important thing here. There are already several theme-specific converters such as MenuScrollingVisibilityConverter or MarginMultiplierConverter in the Avalonia.Controls.Converters namespace (Avalonia.Controls assembly).

We might consider moving those converters to theme-specific assemblies in the future. If we do so, it will be for all converters.

As such, this API is accepted as-is.

@MrJul MrJul added api-approved The new public APIs have been approved. and removed needs-api-review The PR adds new public APIs that should be reviewed. labels Jun 18, 2025
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 Jun 18, 2025
Merged via the queue into AvaloniaUI:master with commit 33c58a9 Jun 18, 2025
11 checks passed
@zdpcdt zdpcdt deleted the treeview branch June 24, 2025 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved The new public APIs have been approved. feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants