203 lines
7.0 KiB
C#
203 lines
7.0 KiB
C#
/*
|
|
* Copyright (c) 2022 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.View;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.Specialized;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace AuroraUIComponent.UserControls
|
|
{
|
|
public class StatusItem : NotifyPropertyChangedBase
|
|
{
|
|
public string GroupName { get; set; }
|
|
public string Name { get; set; }
|
|
public string Extra { get; set; }
|
|
|
|
private int _Status = 0; // 0: Deactivated, 1: Activated, 2: Moving
|
|
public int Status { get => _Status; set => SetProperty(ref _Status, value); }
|
|
|
|
public StatusItem(string name, string groupName = "", string extra = "")
|
|
{
|
|
GroupName = groupName;
|
|
Name = name;
|
|
Status = 0;
|
|
Extra = extra;
|
|
}
|
|
}
|
|
|
|
public class GroupTitle : NotifyPropertyChangedBase
|
|
{
|
|
public string Title { get; set; }
|
|
|
|
private int _Columns = 0;
|
|
public int Columns { get => _Columns; set => SetProperty(ref _Columns, value); }
|
|
|
|
public GroupTitle(string title, int columns = 1)
|
|
{
|
|
Title = title;
|
|
Columns = 1;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Interaction logic for UCGroupStatus.xaml
|
|
/// </summary>
|
|
public partial class UCGroupStatus : UserControl
|
|
{
|
|
public UCGroupStatus()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public static readonly DependencyProperty StatusListProperty =
|
|
DependencyProperty.Register("StatusList", typeof(ObservableCollection<StatusItem>), typeof(UCGroupStatus), new PropertyMetadata(null, OnStatusChanged));
|
|
|
|
private static void OnStatusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
var ucGroupStatus = d as UCGroupStatus;
|
|
ucGroupStatus.UpdateTitles();
|
|
}
|
|
|
|
public ObservableCollection<StatusItem> StatusList {
|
|
get {
|
|
if (GetValue(StatusListProperty) == null) {
|
|
SetValue(StatusListProperty, new ObservableCollection<StatusItem>());
|
|
}
|
|
return (ObservableCollection<StatusItem>)GetValue(StatusListProperty);
|
|
}
|
|
set {
|
|
SetValue(StatusListProperty, value);
|
|
UpdateTitles();
|
|
StatusList.CollectionChanged += StatusList_CollectionChanged;
|
|
}
|
|
}
|
|
|
|
private void StatusList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
var ucGroupStatus = sender as UCGroupStatus;
|
|
|
|
ucGroupStatus.UpdateTitles();
|
|
}
|
|
|
|
public static readonly DependencyProperty ButtonEventHandlerProperty
|
|
= DependencyProperty.Register(
|
|
nameof(ButtonEventHandler),
|
|
typeof(ICommand),
|
|
typeof(UCGroupStatus),
|
|
new PropertyMetadata(null, OnButtonEventHandlerChanged));
|
|
|
|
private static void OnButtonEventHandlerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
var uc = d as UCGroupStatus;
|
|
|
|
if (uc != null) {
|
|
uc.TitleButtonList.ForEach(x => { x.Command = uc.ButtonEventHandler; x.IsEnabled = uc.ButtonEventHandler != null; });
|
|
}
|
|
}
|
|
|
|
public ICommand ButtonEventHandler {
|
|
get { return (ICommand)GetValue(ButtonEventHandlerProperty); }
|
|
set { SetValue(ButtonEventHandlerProperty, value); }
|
|
}
|
|
|
|
private ObservableCollection<GroupTitle> Titles = new ObservableCollection<GroupTitle>();
|
|
public List<Button> TitleButtonList = new List<Button>();
|
|
|
|
public void UpdateTitles()
|
|
{
|
|
Titles.Clear();
|
|
TitleButtonList.Clear();
|
|
|
|
string lastTitle = null;
|
|
int count = 0;
|
|
|
|
if (StatusList == null || StatusList.Count == 0 || !StatusList.Any(x => !string.IsNullOrEmpty(x.GroupName))) {
|
|
gridTitle.Visibility = Visibility.Collapsed;
|
|
return;
|
|
} else {
|
|
gridTitle.Visibility = Visibility.Visible;
|
|
}
|
|
|
|
for (int i = 0; i < StatusList?.Count; i++) {
|
|
if (lastTitle == null || StatusList[i].GroupName != lastTitle) { // 새로 추가
|
|
lastTitle = StatusList[i].GroupName;
|
|
count = 1;
|
|
Titles.Add(new GroupTitle(StatusList[i].GroupName, count));
|
|
} else { // 이전 item에 columns만 1 증가
|
|
count++;
|
|
Titles.LastOrDefault().Columns = count;
|
|
}
|
|
}
|
|
|
|
gridTitle.ColumnDefinitions.Clear();
|
|
|
|
for (int i = 0; i < Titles.Count; i++) {
|
|
gridTitle.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(Titles[i].Columns, GridUnitType.Star) });
|
|
|
|
var button = new Button() {
|
|
Content = Titles[i].Title,
|
|
Command = ButtonEventHandler,
|
|
CommandParameter = Titles[i].Title,
|
|
Style = (Style)FindResource("StButtonAccentGray"),
|
|
IsEnabled = ButtonEventHandler != null
|
|
};
|
|
TitleButtonList.Add(button);
|
|
|
|
var border = new Border() { Child = button };
|
|
Grid.SetColumn(border, i);
|
|
gridTitle.Children.Add(border);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public class ThreeColorConverter : IValueConverter
|
|
{
|
|
public string Color0 { get; set; }
|
|
public string Color1 { get; set; }
|
|
public string Color2 { get; set; }
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
var baseColorList = new SolidColorBrush[3];
|
|
baseColorList[0] = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Color0));
|
|
baseColorList[1] = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Color1));
|
|
baseColorList[2] = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Color2));
|
|
|
|
Color blackColor = (Color)ColorConverter.ConvertFromString("#000000");
|
|
SolidColorBrush BlackColor = new SolidColorBrush(blackColor);
|
|
|
|
int LedStatusVal = (int)value;
|
|
if (LedStatusVal >= 0 && LedStatusVal < 3) {
|
|
return baseColorList[LedStatusVal];
|
|
}
|
|
|
|
// 여기서 적절한 조건에 따라 색상을 선택하거나 계산하세요.
|
|
return blackColor;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
}
|
|
}
|