Implemented Tabbar control. Implemented Selector interface in Hoversel.
Change-Id: I636d265d10a160e4ffd50c3d69e494ff2f85d9c3
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
#ifndef UI_HOVERSEL_H
#define UI_HOVERSEL_H
-#include "Ui/Control.h"
-#include <functional>
+#include "Ui/Selector.h"
namespace Ui
{
- class EXPORT_API Hoversel : public Control
+ class EXPORT_API Hoversel : public Selector
{
public:
/**
- * @brief Item selection callback.
- * @param[in] Item value
- * @return Whether to display selected item in hoversel button automatically
+ * @brief Add item with text.
+ * @param[in] text Item text
+ * @param[in] value Item data
+ * @return Added item on success, otherwise nullptr.
+ * @see Selector::addItem()
*/
- typedef std::function<bool(int)> SelectedCallback;
+ Elm_Object_Item *addItem(const char *text, void *data);
/**
- * @brief Add item.
- * @param[in] text Item text
- * @param[in] value Item value which will be passed to SelectedCallback
- * @return Added item on success, otherwise nullptr.
+ * @see Selector::addItem()
*/
- Elm_Object_Item *addItem(const char *text, int value);
+ virtual Elm_Object_Item *addItem(void *data) override;
/**
* @brief Set text of currently selected item.
void setText(const char *text);
/**
- * @brief Set item selection callback.
- * @param[in] callback Callback to be called after item was selected
+ * @see Selector::setSelectedItem()
*/
- void setSelectedCallback(SelectedCallback callback);
+ virtual void setSelectedItem(Elm_Object_Item *item) override;
protected:
virtual Evas_Object *onCreate(Evas_Object *parent) override;
static void onExpanded(void *data, Evas_Object *hoversel, void *eventInfo);
static void onDismissed(void *data, Evas_Object *hoversel, void *eventInfo);
static void onBackPressed(void *data, Evas_Object *hoversel, void *eventInfo);
-
- SelectedCallback m_OnSelected;
};
}
--- /dev/null
+/*
+ * Copyright (c) 2015-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.
+ *
+ */
+
+#ifndef UI_SELECTOR_H
+#define UI_SELECTOR_H
+
+#include "Ui/Control.h"
+#include <functional>
+
+namespace Ui
+{
+ /**
+ * @brief Interface for controls that provide item selection functionality.
+ */
+ class EXPORT_API Selector : public Control
+ {
+ public:
+ /**
+ * @brief Item selection callback.
+ * @param[in] Item data
+ * @return Whether to perform the default action if any.
+ */
+ typedef std::function<bool(void *)> SelectCallback;
+
+ /**
+ * @brief Add item.
+ * @param[in] value Item data which will be passed to SelectedCallback
+ * @return Added item on success, otherwise nullptr.
+ */
+ virtual Elm_Object_Item *addItem(void *data) = 0;
+
+ /**
+ * @brief Set whether selection is enabled.
+ * @param[in] isEnabled Whether selection is enabled
+ */
+ virtual void setSelectEnabled(bool isEnabled);
+
+ /**
+ * @brief Set which item is currently selected.
+ * @param[in] item Item to be selected
+ */
+ virtual void setSelectedItem(Elm_Object_Item *item) = 0;
+
+ /**
+ * @brief Set item selection callback.
+ * @param[in] callback Callback to be called after item was selected
+ */
+ void setSelectCallback(SelectCallback callback);
+
+ protected:
+ /**
+ * @brief Item selection callback.
+ * @param[in] item Selected item
+ */
+ bool onSelected(Elm_Object_Item *item);
+
+ SelectCallback m_OnSelected;
+ };
+}
+
+#endif /* UI_SELECTOR_H */
--- /dev/null
+/*
+ * Copyright (c) 2015-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.
+ *
+ */
+
+#ifndef UI_TABBAR_H
+#define UI_TABBAR_H
+
+#include "Ui/Selector.h"
+
+namespace Ui
+{
+ /**
+ * @brief Selector control for switching between tabs.
+ */
+ class EXPORT_API Tabbar : public Selector
+ {
+ public:
+ /**
+ * @see Selector::addItem()
+ */
+ virtual Elm_Object_Item *addItem(void *data) override;
+
+ /**
+ * @see Selector::setSelectEnabled()
+ */
+ virtual void setSelectEnabled(bool isEnabled) override;
+
+ /**
+ * @see Selector::setSelectedItem()
+ */
+ virtual void setSelectedItem(Elm_Object_Item *item) override;
+
+ protected:
+ /**
+ * @see Control::onCreate()
+ */
+ virtual Evas_Object *onCreate(Evas_Object *parent) override;
+
+ private:
+ void onSelected(Evas_Object *tabbar, Elm_Object_Item *item);
+ };
+}
+
+#endif /* UI_TABBAR_H */
using namespace Ui;
-Elm_Object_Item *Hoversel::addItem(const char *text, int value)
+Elm_Object_Item *Hoversel::addItem(const char *text, void *data)
{
Elm_Object_Item *item = elm_hoversel_item_add(getEvasObject(), text,
- nullptr, ELM_ICON_NONE, nullptr, (void *) (long) value);
+ nullptr, ELM_ICON_NONE, nullptr, data);
elm_object_item_text_translatable_set(item, EINA_TRUE);
return item;
}
+Elm_Object_Item *Hoversel::addItem(void *data)
+{
+ return addItem(nullptr, data);
+}
+
void Hoversel::setText(const char *text)
{
elm_object_translatable_text_set(getEvasObject(), text);
}
-void Hoversel::setSelectedCallback(SelectedCallback callback)
+void Hoversel::setSelectedItem(Elm_Object_Item *item)
{
- m_OnSelected = std::move(callback);
+ setText(elm_object_item_translatable_text_get(item));
}
Evas_Object *Hoversel::onCreate(Evas_Object *parent)
void Hoversel::onSelected(Evas_Object *hoversel, Elm_Object_Item *item)
{
- int value = (long) elm_object_item_data_get(item);
- if (!m_OnSelected || m_OnSelected(value)) {
- setText(elm_object_item_translatable_text_get(item));
+ if (Selector::onSelected(item)) {
+ setSelectedItem(item);
}
}
--- /dev/null
+/*
+ * Copyright (c) 2015-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.
+ *
+ */
+
+#include "Ui/Selector.h"
+
+using namespace Ui;
+
+void Selector::setSelectEnabled(bool isEnabled)
+{
+ elm_object_disabled_set(getEvasObject(), !isEnabled);
+}
+
+void Selector::setSelectCallback(SelectCallback callback)
+{
+ m_OnSelected = std::move(callback);
+}
+
+bool Selector::onSelected(Elm_Object_Item *item)
+{
+ void *data = elm_object_item_data_get(item);
+ return !m_OnSelected || m_OnSelected(data);
+}
--- /dev/null
+/*
+ * Copyright (c) 2015-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.
+ *
+ */
+
+#include "Ui/Tabbar.h"
+#include "Utils/Callback.h"
+
+using namespace Ui;
+
+Elm_Object_Item *Tabbar::addItem(void *data)
+{
+ return elm_toolbar_item_append(getEvasObject(), nullptr, nullptr, nullptr, data);
+}
+
+void Tabbar::setSelectEnabled(bool isEnabled)
+{
+ elm_toolbar_select_mode_set(getEvasObject(),
+ isEnabled ? ELM_OBJECT_SELECT_MODE_ALWAYS : ELM_OBJECT_SELECT_MODE_NONE);
+}
+
+void Tabbar::setSelectedItem(Elm_Object_Item *item)
+{
+ elm_toolbar_item_selected_set(item, EINA_TRUE);
+}
+
+Evas_Object *Tabbar::onCreate(Evas_Object *parent)
+{
+ Evas_Object *tabbar = elm_toolbar_add(parent);
+ elm_toolbar_shrink_mode_set(tabbar, ELM_TOOLBAR_SHRINK_EXPAND);
+ elm_toolbar_select_mode_set(tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
+ elm_toolbar_transverse_expanded_set(tabbar, EINA_TRUE);
+ evas_object_smart_callback_add(tabbar, "selected",
+ (Evas_Smart_Cb) makeCallback(&Tabbar::onSelected), this);
+ return tabbar;
+}
+
+void Tabbar::onSelected(Evas_Object *tabbar, Elm_Object_Item *item)
+{
+ Selector::onSelected(item);
+}
private:
virtual void onCreated() override;
- bool onSelected(int value);
+ bool onSelected(void *data);
Model::ContactEnumField &m_TypeField;
Model::ContactTextField &m_LabelField;
auto pairs = getEnumValueNames(EnumType(m_TypeField.getSubType()));
for (auto &&pair : pairs) {
- addItem(pair.name, pair.value);
+ addItem(pair.name, (void *) (long) pair.value);
if (pair.value == currentValue) {
setText(pair.name);
setText(m_LabelField.getValue());
}
- setSelectedCallback(std::bind(&ContactTypedFieldControl::onSelected, this,
+ setSelectCallback(std::bind(&ContactTypedFieldControl::onSelected, this,
std::placeholders::_1));
}
-bool ContactTypedFieldControl::onSelected(int value)
+bool ContactTypedFieldControl::onSelected(void *data)
{
+ int value = (long) data;
if (value == m_TypeField.getCustomValue()) {
auto popup = new Ux::EditfieldPopup();
popup->setStrings({