forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tizen] Add ImageButton handler (dotnet#261)
* [Tizen] Add ImageButton handler * Add comment
- Loading branch information
1 parent
e2f6a24
commit b70befc
Showing
3 changed files
with
110 additions
and
10 deletions.
There are no files selected for viewing
52 changes: 43 additions & 9 deletions
52
src/Core/src/Handlers/ImageButton/ImageButtonHandler.Tizen.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using ElmSharp; | ||
using TImage = Tizen.UIExtensions.ElmSharp.Image; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
//TODO: Need to impl | ||
public partial class ImageButtonHandler : ViewHandler<IImageButton, TImage> | ||
public partial class ImageButtonHandler : ViewHandler<IImageButton, MauiImageButton> | ||
{ | ||
protected override TImage CreateNativeView() => throw new NotImplementedException(); | ||
|
||
void OnSetImageSource(TImage? obj) | ||
protected override MauiImageButton CreateNativeView() | ||
{ | ||
throw new NotImplementedException(); | ||
_ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} must be set to create a ImageButton"); | ||
_ = NativeParent ?? throw new InvalidOperationException($"{nameof(NativeParent)} cannot be null"); | ||
|
||
var view = new MauiImageButton(NativeParent); | ||
return view; | ||
} | ||
|
||
protected override void ConnectHandler(MauiImageButton nativeView) | ||
{ | ||
nativeView.Clicked += OnClicked; | ||
nativeView.Pressed += OnPressed; | ||
nativeView.Released += OnReleased; | ||
base.ConnectHandler(nativeView); | ||
} | ||
|
||
protected override void DisconnectHandler(MauiImageButton nativeView) | ||
{ | ||
nativeView.Clicked -= OnClicked; | ||
nativeView.Pressed -= OnPressed; | ||
nativeView.Released -= OnReleased; | ||
base.DisconnectHandler(nativeView); | ||
} | ||
|
||
private void OnReleased(object? sender, EventArgs e) | ||
{ | ||
VirtualView?.Released(); | ||
} | ||
|
||
private void OnPressed(object? sender, EventArgs e) | ||
{ | ||
VirtualView?.Pressed(); | ||
} | ||
|
||
private void OnClicked(object? sender, EventArgs e) | ||
{ | ||
VirtualView?.Clicked(); | ||
} | ||
|
||
void OnSetImageSource(TImage? img) | ||
{ | ||
//Empty on purpose | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using ElmSharp; | ||
using Tizen.UIExtensions.Common; | ||
using Tizen.UIExtensions.ElmSharp; | ||
using TButton = Tizen.UIExtensions.ElmSharp.Button; | ||
using TImage = Tizen.UIExtensions.ElmSharp.Image; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
public class MauiImageButton : Canvas | ||
{ | ||
TImage _image; | ||
TButton _button; | ||
|
||
public MauiImageButton(EvasObject parent) : base(parent) | ||
{ | ||
_image = new TImage(parent); | ||
_button = new TButton(parent); | ||
|
||
_button.Clicked += OnClicked; | ||
_button.Pressed += OnPressed; | ||
_button.Released += OnReleased; | ||
_button.SetTransparentStyle(); | ||
|
||
Children.Add(_image); | ||
_image.RaiseTop(); | ||
|
||
Children.Add(_button); | ||
_button.SetTransparentStyle(); | ||
_button.RaiseTop(); | ||
|
||
LayoutUpdated += OnLayout; | ||
} | ||
|
||
public TImage ImageView | ||
{ | ||
get => _image; | ||
} | ||
|
||
public event EventHandler? Clicked; | ||
public event EventHandler? Pressed; | ||
public event EventHandler? Released; | ||
|
||
void OnReleased(object? sender, EventArgs e) | ||
{ | ||
Released?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
void OnPressed(object? sender, EventArgs e) | ||
{ | ||
Pressed?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
void OnClicked(object? sender, EventArgs e) | ||
{ | ||
Clicked?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
void OnLayout(object? sender, LayoutEventArgs e) | ||
{ | ||
_button.Geometry = Geometry; | ||
_image.Geometry = Geometry; | ||
} | ||
} | ||
} |