using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Presenters; using Avalonia.Controls.Primitives; using Avalonia.Input; namespace SukiUI.Controls; public class SukiSideMenuItem : ListBoxItem { public static readonly StyledProperty IconProperty = AvaloniaProperty.Register(nameof(Icon)); private Border? _border; public object? Icon { get => GetValue(IconProperty); set => SetValue(IconProperty, value); } public static readonly StyledProperty HeaderProperty = AvaloniaProperty.Register(nameof(Header)); public string? Header { get => GetValue(HeaderProperty); set => SetValue(HeaderProperty, value); } public static readonly StyledProperty PageContentProperty = AvaloniaProperty.Register(nameof(PageContent)); public object PageContent { get => GetValue(PageContentProperty); set => SetValue(PageContentProperty, value); } public void Show() { if (_border == null) { return; } _border.MaxHeight = 200.0; } public void Hide() { if (_border == null) { return; } _border.MaxHeight = 0.0; } protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); _border = e.NameScope.Get("PART_Border"); if (e.NameScope.Get("PART_AltDisplay") is { } contentControl) { if (Header is not null || Icon is not null) { contentControl.IsVisible = false; } } } protected override void OnPointerPressed(PointerPressedEventArgs e) { base.OnPointerPressed(e); if (e.Handled) return; if (!e.Handled && ItemsControl.ItemsControlFromItemContainer(this) is SukiSideMenu owner) { var p = e.GetCurrentPoint(this); if (p.Properties.PointerUpdateKind is PointerUpdateKind.LeftButtonPressed or PointerUpdateKind.RightButtonPressed) { if (p.Pointer.Type == PointerType.Mouse) { // If the pressed point comes from a mouse, perform the selection immediately. e.Handled = owner.UpdateSelectionFromPointerEvent(this); } } } } public static readonly StyledProperty IsContentMovableProperty = AvaloniaProperty.Register(nameof(IsContentMovable), defaultValue: true); public bool IsContentMovable { get => GetValue(IsContentMovableProperty); set => SetValue(IsContentMovableProperty, value); } public static readonly StyledProperty IsTopMenuExpandedProperty = AvaloniaProperty.Register(nameof(IsTopMenuExpanded), defaultValue: true); public bool IsTopMenuExpanded { get => GetValue(IsTopMenuExpandedProperty); set => SetValue(IsTopMenuExpandedProperty, value); } }