/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
namespace ElmSharp.Wearable
{
///
/// The MoreOption is a widget composed of the toggle (cue button) and more option view that can change a visibility through the toggle.
/// Inherits Layout
///
/// preview
public class MoreOption : Layout
{
///
/// Sets or gets the list of the more option item.
///
/// preview
public IList Items { get; private set; }
///
/// Selected will be triggered when the user selects an item.
///
/// preview
public event EventHandler Selected;
///
/// Clicked will be triggered when the user selects the already selected item again or selects a selector.
///
/// preview
public event EventHandler Clicked;
///
/// Opened will be triggered when the more option view is shown.
///
/// preview
public event EventHandler Opened;
///
/// Closed will be triggered when the more option view is hidden.
///
/// preview
public event EventHandler Closed;
SmartEvent _selectedEvent;
SmartEvent _clickedEvent;
SmartEvent _openedEvent;
SmartEvent _closedEvent;
///
/// Creates and initializes a new instance of the MoreOption class.
///
/// The parent is a given container, which will be attached by the MoreOption as a child. It's type.
/// preview
public MoreOption(EvasObject parent) : base(parent)
{
Items = new MoreOptionList(this);
_selectedEvent = new SmartEvent(this, "item,selected", (d, o, info) => new PointerEventArgs { Pointer = info });
_clickedEvent = new SmartEvent(this, "item,clicked", (d, o, info) => new PointerEventArgs { Pointer = info });
_openedEvent = new SmartEvent(this, "more,option,opened");
_closedEvent = new SmartEvent(this, "more,option,closed");
_selectedEvent.On += (s, e) =>
{
MoreOptionItem selected = Items.FirstOrDefault(i => i.Handle == e.Pointer);
Selected?.Invoke(this, new MoreOptionItemEventArgs() { Item = selected });
};
_clickedEvent.On += (s, e) =>
{
MoreOptionItem selected = Items.FirstOrDefault(i => i.Handle == e.Pointer);
Clicked?.Invoke(this, new MoreOptionItemEventArgs() { Item = selected });
};
_openedEvent.On += (s, e) => Opened?.Invoke(this, EventArgs.Empty);
_closedEvent.On += (s, e) => Closed?.Invoke(this, EventArgs.Empty);
}
///
/// Creates a widget handle.
///
/// Parent EvasObject.
/// Handle IntPtr.
/// preview
protected override IntPtr CreateHandle(EvasObject parent)
{
return Interop.Eext.eext_more_option_add(parent);
}
///
/// Sets or gets the direction of more option.
///
/// preview
public MoreOptionDirection Direction
{
get
{
int dir = Interop.Eext.eext_more_option_direction_get(this);
return (MoreOptionDirection)dir;
}
set
{
Interop.Eext.eext_more_option_direction_set(this, (int)value);
}
}
///
/// Sets or gets the visibility of the more option view.
///
/// preview
public bool IsOpened
{
get
{
return Interop.Eext.eext_more_option_opened_get(this);
}
set
{
Interop.Eext.eext_more_option_opened_set(this, value);
}
}
}
///
/// Enumeration for the more option direction types.
///
/// preview
public enum MoreOptionDirection
{
///
/// Top direction.
///
Top,
///
/// Bottom direction.
///
Bottom,
///
/// Left direction.
///
Left,
///
/// Right direction.
///
Right
}
}