1
0
mirror of https://github.com/chylex/Brotli-Builder.git synced 2024-12-21 13:42:48 +01:00
Brotli-Builder/BrotliBuilder/Blocks/Structure/BuildWindowSize.cs

47 lines
1.6 KiB
C#

using System;
using System.Linq;
using System.Windows.Forms;
using BrotliLib.Brotli.Components;
namespace BrotliBuilder.Blocks.Structure{
partial class BuildWindowSize : UserControl{
private readonly IBuildingBlockContext context;
public BuildWindowSize(IBuildingBlockContext context, WindowSize windowSize){
InitializeComponent();
this.context = context;
var items = WindowSize.BitsRange.Values.Select(bits => new WindowSizeItem(new WindowSize(bits))).ToArray();
this.listElements.Items.AddRange(items);
this.listElements.SelectedItem = items.FirstOrDefault(item => windowSize.Equals(item.Value));
this.listElements.SelectedValueChanged += listElements_SelectedValueChanged;
}
private void listElements_SelectedValueChanged(object? sender, EventArgs e){
WindowSize newWindowSize = ((WindowSizeItem)listElements.SelectedItem).Value;
context.NotifyParent(new WindowSizeNotifyArgs(newWindowSize));
}
private class WindowSizeItem{
public WindowSize Value { get; }
public WindowSizeItem(WindowSize value){
this.Value = value;
}
public override string ToString(){
return $"{Value.Bits} bits / {Value.Bytes} bytes";
}
}
public class WindowSizeNotifyArgs : EventArgs{
public WindowSize NewWindowSize { get; }
public WindowSizeNotifyArgs(WindowSize newWindowSize){
this.NewWindowSize = newWindowSize;
}
}
}
}