Skip to content

Commit

Permalink
WinUI: More control implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Jul 3, 2024
1 parent 3a3b029 commit 601279a
Show file tree
Hide file tree
Showing 26 changed files with 732 additions and 64 deletions.
1 change: 1 addition & 0 deletions src/Eto.WinUI/Forms/ApplicationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void AsyncInvoke(Action action)
public void Attach(object context)
{
Control = context as mux.Application;
Callback.OnInitialized(Widget, EventArgs.Empty);
}

protected override void Initialize()
Expand Down
40 changes: 40 additions & 0 deletions src/Eto.WinUI/Forms/Controls/ButtonHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace Eto.WinUI.Forms.Controls;

public class ButtonHandler : WinUIControl<muc.Button, Button, Button.ICallback>, Button.IHandler
{
muc.TextBlock _textBlock;
public Image Image { get; set; }
public ButtonImagePosition ImagePosition { get; set; }
public Size MinimumSize { get; set; }

public string Text
{
get => _textBlock.Text;
set => _textBlock.Text = value;
}

protected override muc.Button CreateControl() => new muc.Button();

protected override void Initialize()
{
base.Initialize();
_textBlock = new muc.TextBlock();
Control.Content = _textBlock;
Control.Click += Control_Click;
}

private void Control_Click(object sender, mux.RoutedEventArgs e)
{
Callback.OnClick(Widget, EventArgs.Empty);
}

public override void AttachEvent(string id)
{
switch (id)
{
default:
base.AttachEvent(id);
break;
}
}
}
34 changes: 34 additions & 0 deletions src/Eto.WinUI/Forms/Controls/CheckBoxHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Eto.WinUI.Forms.Controls;

public class CheckBoxHandler : WinUIControl<muc.CheckBox, CheckBox, CheckBox.ICallback>, CheckBox.IHandler
{
public string Text
{
get => Control.Content as string;
set => Control.Content = value;
}
public bool? Checked
{
get => Control.IsChecked;
set => Control.IsChecked = value;
}
public bool ThreeState
{
get => Control.IsThreeState;
set => Control.IsThreeState = value;
}

protected override muc.CheckBox CreateControl() => new();

protected override void Initialize()
{
base.Initialize();
Control.Checked += Control_Checked;
}

private void Control_Checked(object sender, mux.RoutedEventArgs e)
{
Callback.OnCheckedChanged(Widget, EventArgs.Empty);
}

}
39 changes: 39 additions & 0 deletions src/Eto.WinUI/Forms/Controls/DropDownHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Eto.WinUI.Forms.Controls;

public class DropDownHandler : WinUIControl<muc.ComboBox, DropDown, DropDown.ICallback>, DropDown.IHandler
{
public bool ShowBorder { get; set; }
IEnumerable<object> _store;
public IEnumerable<object> DataStore
{
get => _store;
set
{
_store = value;
var source = _store;
if (_store is not INotifyCollectionChanged)
source = new ObservableCollection<object>(_store);
Control.ItemsSource = source;
}
}
public int SelectedIndex
{
get => Control.SelectedIndex;
set => Control.SelectedIndex = value;
}
public IIndirectBinding<string> ItemTextBinding { get; set; }
public IIndirectBinding<string> ItemKeyBinding { get; set; }

protected override muc.ComboBox CreateControl() => new();
protected override void Initialize()
{
base.Initialize();
Control.SelectionChanged += Control_SelectionChanged;
}

private void Control_SelectionChanged(object sender, muc.SelectionChangedEventArgs e)
{
Callback.OnSelectedIndexChanged(Widget, EventArgs.Empty);
}

}
55 changes: 43 additions & 12 deletions src/Eto.WinUI/Forms/Controls/LabelHandler.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
namespace Eto.WinUI.Forms.Controls;

namespace Eto.WinUI.Forms.Controls
public class LabelHandler : WinUIFrameworkElement<muc.TextBlock, Label, Label.ICallback>, Label.IHandler
{
public class LabelHandler : WinUIFrameworkElement<muc.TextBlock, Label, Label.ICallback>, Label.IHandler
public override mux.FrameworkElement ContainerControl => Control;
protected override muc.TextBlock CreateControl() => new muc.TextBlock();

public TextAlignment TextAlignment
{
get => Control.TextAlignment.ToEto();
set => Control.TextAlignment = value.ToWinUI();
}

public VerticalAlignment VerticalAlignment
{
public override mux.FrameworkElement ContainerControl => Control;
protected override muc.TextBlock CreateControl() => new muc.TextBlock();
get => Control.VerticalAlignment.ToEto();
set => Control.VerticalAlignment = value.ToWinUI();
}

public TextAlignment TextAlignment { get; set; }
public VerticalAlignment VerticalAlignment { get; set; }
public WrapMode Wrap { get; set; }
public string Text
public WrapMode Wrap
{
get => Control.TextWrapping.ToEto();
set => Control.TextWrapping = value.ToWinUI();
}
public string Text
{
get => Control.Text;
set => Control.Text = value;
}
public Color TextColor
{
get => Control.Foreground.ToEtoColor();
set => Control.Foreground = value.ToWinUIBrush();
}

public Font Font { get; set; }

public override void AttachEvent(string id)
{
switch (id)
{
get => Control.Text;
set => Control.Text = value;
case TextControl.TextChangedEvent:
// do nothing, label doesn't get updated by the user
break;

default:
base.AttachEvent(id);
break;
}
public Color TextColor { get; set; }
public Font Font { get; set; }
}
}
40 changes: 40 additions & 0 deletions src/Eto.WinUI/Forms/Controls/ListBoxHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

namespace Eto.WinUI.Forms.Controls;

public class ListBoxHandler : WinUIControl<muc.ListView, ListBox, ListBox.ICallback>, ListBox.IHandler
{
IEnumerable<object> _store;
public IEnumerable<object> DataStore
{
get => _store;
set
{
_store = value;
var source = _store;
if (_store is not INotifyCollectionChanged)
source = new ObservableCollection<object>(_store);
Control.ItemsSource = source;
}
}
public int SelectedIndex
{
get => Control.SelectedIndex;
set => Control.SelectedIndex = value;
}
public IIndirectBinding<string> ItemTextBinding { get; set; }
public IIndirectBinding<string> ItemKeyBinding { get; set; }
public ContextMenu ContextMenu { get; set; }

protected override muc.ListView CreateControl() => new();

protected override void Initialize()
{
base.Initialize();
Control.SelectionChanged += Control_SelectionChanged;
}

private void Control_SelectionChanged(object sender, muc.SelectionChangedEventArgs e)
{
Callback.OnSelectedIndexChanged(Widget, EventArgs.Empty);
}
}
26 changes: 26 additions & 0 deletions src/Eto.WinUI/Forms/Controls/PanelHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

namespace Eto.WinUI.Forms.Controls;

public class PanelHandler : WinUIContainer<muc.Border, Panel, Panel.ICallback>, Panel.IHandler
{
Control _content;
public Control Content
{
get => _content;
set
{
if (_content != value)
{
_content = value;
Control.Child = value.ToNative();
}
}
}

public Padding Padding { get; set; }
public Size MinimumSize { get; set; }
public ContextMenu ContextMenu { get; set; }
public override mux.FrameworkElement ContainerControl => Control;

protected override muc.Border CreateControl() => new();
}
43 changes: 43 additions & 0 deletions src/Eto.WinUI/Forms/Controls/ScrollableHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@


namespace Eto.WinUI.Forms.Controls;

public class ScrollableHandler : WinUIContainer<muc.ScrollView, Scrollable, Scrollable.ICallback>, Scrollable.IHandler
{
Control _content;
public Control Content
{
get => _content;
set
{
if (_content != value)
{
_content = value;
Control.Content = value.ToNative();
}
}
}

public Padding Padding { get; set; }
public Size MinimumSize { get; set; }
public ContextMenu ContextMenu { get; set; }

protected override muc.ScrollView CreateControl() => new();

public void UpdateScrollSizes()
{
throw new NotImplementedException();
}

public override mux.FrameworkElement ContainerControl => Control;

public Point ScrollPosition { get; set; }
public Size ScrollSize { get; set; }
public BorderType Border { get; set; }
public Rectangle VisibleRect { get; }
public bool ExpandContentWidth { get; set; }
public bool ExpandContentHeight { get; set; }
public float MinimumZoom { get; set; }
public float MaximumZoom { get; set; }
public float Zoom { get; set; }
}
52 changes: 52 additions & 0 deletions src/Eto.WinUI/Forms/Controls/SplitterHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Eto.WinUI.Forms.Controls;

public class SplitterHandler : WinUIControl<muc.SplitView, Splitter, Splitter.ICallback>, Splitter.IHandler
{
Control _panel1;
Control _panel2;
public Orientation Orientation { get; set; }
public SplitterFixedPanel FixedPanel { get; set; }
public int Position
{
get => (int)Control.OpenPaneLength;
set => Control.OpenPaneLength = value;
}

public double RelativePosition { get; set; }
public int SplitterWidth { get; set; }
public Control Panel1
{
get => _panel1;
set
{
if (_panel1 == value)
return;
_panel1 = value;
Control.Pane = value.ToNative();
}
}
public Control Panel2
{
get => _panel2;
set
{
if (_panel2 == value)
return;

_panel2 = value;
Control.Content = value.ToNative();
}
}
public int Panel1MinimumSize { get; set; }
public int Panel2MinimumSize { get; set; }
public Size ClientSize { get; set; }
public bool RecurseToChildren => true;

public override IEnumerable<Control> VisualControls => Widget.Controls;

protected override muc.SplitView CreateControl() => new muc.SplitView
{
DisplayMode = muc.SplitViewDisplayMode.Inline,
IsPaneOpen = true
};
}
Loading

0 comments on commit 601279a

Please sign in to comment.