TizenRefApp-7989 Implement Selector component 44/115844/3
authorSergei Kobec <s.kobec@samsung.com>
Tue, 21 Feb 2017 12:28:31 +0000 (14:28 +0200)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Wed, 22 Feb 2017 12:30:24 +0000 (04:30 -0800)
Change-Id: I6e26aae16e5ac89991fa4c6696fa0c9dd0add682
Signed-off-by: Sergei Kobec <s.kobec@samsung.com>
lib-apps-common/inc/Ux/MultiSelector.h [new file with mode: 0644]
lib-apps-common/src/Ux/MultiSelector.cpp [new file with mode: 0644]

diff --git a/lib-apps-common/inc/Ux/MultiSelector.h b/lib-apps-common/inc/Ux/MultiSelector.h
new file mode 100644 (file)
index 0000000..efb9db2
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * 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 UX_MULTI_SELECTOR_H
+#define UX_MULTI_SELECTOR_H
+
+#include "Ui/Control.h"
+
+namespace Ux
+{
+       class EXPORT_API MultiSelector : public Ui::Control
+       {
+       public:
+               struct Strings
+               {
+                       const char *selectAll;      /**< "Select all" item text. */
+                       const char *deselectAll;    /**< "Deselect all" item text. */
+               };
+
+               MultiSelector();
+
+               /**
+                * @brief Set count of selected items.
+                */
+               void setCount(size_t count);
+
+               /**
+                * @brief Set translatable strings for menu.
+                * @param[in]   strings     Translatable strings table.
+                */
+               void setStrings(const Strings &strings);
+
+       private:
+               virtual Evas_Object *onCreate(Evas_Object *parent) override;
+               void onButtonClicked(Evas_Object *button, void *eventInfo);
+
+               Strings m_Strings;
+       };
+}
+
+#endif /* UX_MULTI_SELECTOR_H */
diff --git a/lib-apps-common/src/Ux/MultiSelector.cpp b/lib-apps-common/src/Ux/MultiSelector.cpp
new file mode 100644 (file)
index 0000000..ed5a7c7
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * 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 "Ux/MultiSelector.h"
+#include "Ui/CircleMenu.h"
+#include "Utils/Callback.h"
+
+#define BUF_SIZE 8
+
+using namespace Ux;
+
+MultiSelector::MultiSelector()
+       : m_Strings { }
+{
+}
+
+void MultiSelector::setCount(size_t count)
+{
+       char buf[BUF_SIZE];
+       snprintf(buf, sizeof(buf), "%zu", count);
+       elm_object_text_set(getEvasObject(), buf);
+}
+
+void MultiSelector::setStrings(const Strings &strings)
+{
+       m_Strings = strings;
+}
+
+Evas_Object *MultiSelector::onCreate(Evas_Object *parent)
+{
+       auto button = elm_button_add(parent);
+       elm_object_style_set(button, "select_mode");
+       elm_object_text_set(button, "0");
+       evas_object_smart_callback_add(button, "clicked",
+                       makeCallback(&MultiSelector::onButtonClicked), this);
+
+       elm_layout_content_set(parent, "elm.swallow.icon", button);
+
+       return button;
+}
+
+void MultiSelector::onButtonClicked(Evas_Object *button, void *eventInfo)
+{
+       auto menu = new Ui::CircleMenu();
+       menu->create(button);
+
+       menu->addItem(m_Strings.selectAll, [] {
+               //TODO React on select all event
+       });
+       menu->addItem(m_Strings.deselectAll, [] {
+               //TODO React on deselect all event
+       });
+       menu->show();
+}