Skip to content

Commit

Permalink
WinUI: Add Button/Splitter and fill out properties of Label
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Jul 3, 2024
1 parent 3a3b029 commit 8bb1c5e
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 22 deletions.
25 changes: 25 additions & 0 deletions src/Eto.WinUI/Forms/Controls/ButtonHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Eto.WinUI.Forms.Controls;

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

public string Text
{
get => Control.Content as string;
set => Control.Content = value;
}

public Color TextColor
{
get => Control.Foreground.ToEtoColor();
set => Control.Foreground = value.ToWinUIBrush();
}

public Font Font { get; set; }

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

}
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; }
}
}
56 changes: 56 additions & 0 deletions src/Eto.WinUI/Forms/Controls/SplitterHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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; set; }
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
{
get
{
yield return _panel1;
yield return _panel2;
}
}

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

protected override void Initialize()
{
base.Initialize();
Control.DisplayMode = muc.SplitViewDisplayMode.Inline;
}
}
17 changes: 17 additions & 0 deletions src/Eto.WinUI/Forms/WinUIControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

using Microsoft.UI.Xaml;

namespace Eto.WinUI.Forms;

public abstract class WinUIControl<TControl, TWidget, TCallback> : WinUIFrameworkElement<TControl, TWidget, TCallback>, Control.IHandler
where TControl : muc.Control
where TWidget : Control
where TCallback : Control.ICallback
{
public override FrameworkElement ContainerControl => Control;
public override Color BackgroundColor
{
get => Control.Background.ToEtoColor();
set => Control.Background = value.ToWinUIBrush();
}
}
1 change: 1 addition & 0 deletions src/Eto.WinUI/Forms/WinUIFrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public abstract partial class WinUIFrameworkElement<TControl, TWidget, TCallback


public virtual Color BackgroundColor { get; set; }

public Size Size
{
get => new Size(Width, Height);
Expand Down
4 changes: 2 additions & 2 deletions src/Eto.WinUI/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void AddTo(Eto.Platform p)
//p.Add<CustomCell.IHandler>(() => new CustomCellHandler());

// Forms.Controls
//p.Add<Button.IHandler>(() => new ButtonHandler());
p.Add<Button.IHandler>(() => new ButtonHandler());
//p.Add<Calendar.IHandler>(() => new CalendarHandler());
//p.Add<CheckBox.IHandler>(() => new CheckBoxHandler());
//p.Add<DropDown.IHandler>(() => new DropDownHandler());
Expand All @@ -90,7 +90,7 @@ public static void AddTo(Eto.Platform p)
//p.Add<Scrollable.IHandler>(() => new ScrollableHandler());
//p.Add<Slider.IHandler>(() => new SliderHandler());
p.Add<Spinner.IHandler>(() => new ThemedSpinnerHandler());
//p.Add<Splitter.IHandler>(() => new SplitterHandler());
p.Add<Splitter.IHandler>(() => new SplitterHandler());
//p.Add<TabControl.IHandler>(() => new TabControlHandler());
//p.Add<TabPage.IHandler>(() => new TabPageHandler());
//p.Add<TextArea.IHandler>(() => new TextAreaHandler());
Expand Down
51 changes: 51 additions & 0 deletions src/Eto.WinUI/WinUIConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,57 @@ public static sw.Point ToWinUI(this PointF value)
return new sw.Point(value.X, value.Y);
}

public static mux.VerticalAlignment ToWinUI(this VerticalAlignment value) => value switch
{
VerticalAlignment.Top => mux.VerticalAlignment.Top,
VerticalAlignment.Bottom => mux.VerticalAlignment.Bottom,
VerticalAlignment.Center => mux.VerticalAlignment.Center,
VerticalAlignment.Stretch => mux.VerticalAlignment.Stretch,
_ => throw new NotImplementedException()
};

public static VerticalAlignment ToEto(this mux.VerticalAlignment value) => value switch
{
mux.VerticalAlignment.Top => VerticalAlignment.Top,
mux.VerticalAlignment.Bottom => VerticalAlignment.Bottom,
mux.VerticalAlignment.Center => VerticalAlignment.Center,
mux.VerticalAlignment.Stretch => VerticalAlignment.Stretch,
_ => throw new NotImplementedException()
};

public static mux.TextWrapping ToWinUI(this WrapMode value) => value switch
{
WrapMode.Character => mux.TextWrapping.Wrap,
WrapMode.None => mux.TextWrapping.NoWrap,
WrapMode.Word => mux.TextWrapping.WrapWholeWords,
_ => throw new NotImplementedException()
};

public static WrapMode ToEto(this mux.TextWrapping value) => value switch
{
mux.TextWrapping.Wrap => WrapMode.Character,
mux.TextWrapping.NoWrap => WrapMode.None,
mux.TextWrapping.WrapWholeWords => WrapMode.Word,
_ => throw new NotImplementedException()
};
public static mux.TextAlignment ToWinUI(this TextAlignment value) => value switch
{
TextAlignment.Left => mux.TextAlignment.Left,
TextAlignment.Center => mux.TextAlignment.Center,
TextAlignment.Right => mux.TextAlignment.Right,
//TextAlignment.Justify => mux.TextAlignment.Justify,
_ => throw new NotImplementedException()
};

public static TextAlignment ToEto(this mux.TextAlignment value) => value switch
{
mux.TextAlignment.Left => TextAlignment.Left,
mux.TextAlignment.Center => TextAlignment.Center,
mux.TextAlignment.Right => TextAlignment.Right,
//TextAlignment.Justify => mux.TextAlignment.Justify,
_ => throw new NotImplementedException()
};

/*
public static KeyEventArgs ToEto(this swi.KeyEventArgs e, KeyEventType keyType)
{
Expand Down
14 changes: 9 additions & 5 deletions test/Eto.Test.WinUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ public class MainWindow : Eto.Forms.Form
{
public MainWindow()
{
Content = new TableLayout
Content = new Splitter
{
Rows = {
new TableRow(new Label { Text = "This is an Eto.Forms Label" }, new Label { Text = "Second Column" }),
new Label { Text = "Second Row" }
Panel1 = new Label { Text = "Hi" },
Panel2 = new TableLayout
{
Rows = {
new TableRow(new Label { Text = "This is an Eto.Forms Label" }, new Label { Text = "Second Column", TextAlignment = TextAlignment.Center }),
new Button {Text = "Some Button"},
new Label { Text = "Second Row", VerticalAlignment = VerticalAlignment.Center }
}
}
};

}
}
}
6 changes: 3 additions & 3 deletions test/Eto.Test/MainForm.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public MainForm(IEnumerable<Section> topNodes = null)
topNodes = topNodes ?? TestSections.Get(TestApplication.DefaultTestAssemblies());

var nodes = topNodes.ToList();
if (Platform.IsAndroid)
SectionList = new SectionListGridView(nodes);
else
if (Platform.Supports<TreeGridView>())
SectionList = new SectionListTreeGridView(nodes);
else if (Platform.Supports<GridView>())
SectionList = new SectionListGridView(nodes);

SectionList.SelectedItemChanged += SectionList_SelectedItemChanged;

Expand Down

0 comments on commit 8bb1c5e

Please sign in to comment.