using InABox.Configuration; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; namespace InABox.Wpf; public class FilterButton : Button { public event DynamicGridFilterComponent.FilterSelectedHandler? OnFiltersSelected { add { Component.OnFiltersSelected += value; } remove { Component.OnFiltersSelected -= value; } } public event DynamicGridFilterComponent.FilterRefreshHandler? OnFilterRefresh { add { Component.OnFilterRefresh += value; } remove { Component.OnFilterRefresh -= value; } } private class ButtonComponent : DynamicGridFilterComponent { private FilterButton Button; public ButtonComponent( FilterButton button, IConfiguration globalConfiguration, IConfiguration userConfiguration) : base(globalConfiguration, userConfiguration) { Button = button; } protected override void UpdateButtonText(System.Drawing.Bitmap image, string text) { Button.Update(image, text); } public void Click() { DoFilter(); } } private ButtonComponent Component; public FilterButton( IConfiguration globalConfiguration, IConfiguration userConfiguration) { Component = new(this, globalConfiguration, userConfiguration); SetValue(BorderBrushProperty, new SolidColorBrush(Colors.Gray)); SetValue(BorderThicknessProperty, new Thickness(0.75)); Height = 30; Update(Wpf.Resources.filter, ""); } public void SetSettings(DynamicGridSelectedFilterSettings settings, bool refresh) { Component.SetSettings(settings, refresh); } private void Update(System.Drawing.Bitmap image, string text) { var stackPnl = new StackPanel(); stackPnl.Orientation = Orientation.Horizontal; //stackPnl.Margin = new Thickness(2); if (image != null) { var img = new Image { Source = image.AsBitmapImage(), Margin = new Thickness(2) }; stackPnl.Children.Add(img); } if (!string.IsNullOrEmpty(text)) { stackPnl.MaxWidth = double.MaxValue; var lbl = new Label(); lbl.Content = text; lbl.VerticalAlignment = VerticalAlignment.Stretch; lbl.VerticalContentAlignment = VerticalAlignment.Center; lbl.Margin = new Thickness(2, 0, 5, 0); lbl.ToolTip = ToolTip; stackPnl.Children.Add(lbl); } else { stackPnl.MaxWidth = 30; } Content = stackPnl; } protected override void OnClick() { base.OnClick(); Component.Click(); } public Filter? GetFilter() { return Component.GetFilter(); } }