From 0ba6c83cfc848dd7b76fc16830b8ce6718238c2c Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Tue, 5 Mar 2019 08:32:58 +0100 Subject: [PATCH] Add new type of GenlistItem - Icon This change introduce new type of GenlistItem and use it in SwitchesPage Change-Id: I76a7d4303da2aad76d75492a0466005e6563e909 --- src/GenlistItem.cpp | 20 ++++++++++++++++++++ src/GenlistItem.hpp | 3 +++ src/Icon.cpp | 5 +++++ src/Icon.hpp | 2 ++ src/SwitchesPage.cpp | 33 +++++++-------------------------- src/SwitchesPage.hpp | 2 -- src/Widget.cpp | 5 +++++ src/Widget.hpp | 1 + 8 files changed, 43 insertions(+), 28 deletions(-) diff --git a/src/GenlistItem.cpp b/src/GenlistItem.cpp index df1e612..6db26a3 100644 --- a/src/GenlistItem.cpp +++ b/src/GenlistItem.cpp @@ -3,6 +3,7 @@ #include "setting-debug.h" #include "Check.hpp" #include "Genlist.hpp" +#include "Icon.hpp" GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedString desc, Type type) : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), type_(type) @@ -16,6 +17,10 @@ GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedStr : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), onSelection_(std::move(onSelection)), widgetType_(type) {} +GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onSelection, std::string iconPath, WidgetType type) + : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), onSelection_(std::move(onSelection)), iconPath_(std::move(iconPath)), widgetType_(type) +{} + void GenlistItem::setText(const TranslatedString &text) { text_ = text; @@ -128,6 +133,9 @@ Evas_Object *GenlistItem::contentRealizator(void *data, Evas_Object *obj, const case WidgetType::check: return self->realizeCheck(part); + case WidgetType::icon: + return self->realizeIcon(part); + default: break; } @@ -176,6 +184,18 @@ Evas_Object *GenlistItem::realizeCheck(const std::string &part) return check->getObject(); } +Evas_Object *GenlistItem::realizeIcon(const std::string &part) +{ + if (part != "elm.swallow.icon") return nullptr; + + auto icon = Widget::make(genlist_); + icon->setColor(15, 41, 73, 255); + icon->setImageFile(iconPath_); + icon->setAspectHint(EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); + + return icon->getObject(); +} + void GenlistItem::onItemSelection(void *data, Evas_Object *obj, void *event_info) { SETTING_TRACE_ERROR("."); diff --git a/src/GenlistItem.hpp b/src/GenlistItem.hpp index 5190c25..2738c7d 100644 --- a/src/GenlistItem.hpp +++ b/src/GenlistItem.hpp @@ -21,6 +21,7 @@ public: GenlistItem(std::string style, TranslatedString text, TranslatedString desc = {}, Type type = Type::group); GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onSelection, Type type = Type::regular); GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onSelection, WidgetType type); + GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onSelection, std::string iconPath, WidgetType type = WidgetType::icon); void setText(const TranslatedString &text); void setDescription(const TranslatedString &desc); @@ -40,6 +41,7 @@ private: Elm_Genlist_Item_Type getItemType(); Evas_Object *realizeToggle(const std::string &part); Evas_Object *realizeCheck(const std::string &part); + Evas_Object *realizeIcon(const std::string &part); static char *textRealizator(void *data, Evas_Object *obj, const char *part); static Evas_Object *contentRealizator(void *data, Evas_Object *obj, const char *part); @@ -51,6 +53,7 @@ private: std::function onSelection_; Genlist *genlist_ = nullptr; Eina_Bool state_ = EINA_FALSE; + std::string iconPath_; Elm_Object_Item *objItem_ = nullptr; Type type_ = Type::regular; diff --git a/src/Icon.cpp b/src/Icon.cpp index 9f02098..494f421 100644 --- a/src/Icon.cpp +++ b/src/Icon.cpp @@ -6,3 +6,8 @@ Icon::Icon(Widget *parent) uniqueObj_.reset(elm_icon_add(parent->getObject())); show(); } + +void Icon::setImageFile(std::string path) +{ + elm_image_file_set(uniqueObj_.get(), path.c_str(), nullptr); +} \ No newline at end of file diff --git a/src/Icon.hpp b/src/Icon.hpp index 4988e8e..334b559 100644 --- a/src/Icon.hpp +++ b/src/Icon.hpp @@ -8,6 +8,8 @@ class Icon : public Widget public: Icon(Widget *parent); + void setImageFile(std::string path); + }; #endif diff --git a/src/SwitchesPage.cpp b/src/SwitchesPage.cpp index 724dfd7..e419f25 100644 --- a/src/SwitchesPage.cpp +++ b/src/SwitchesPage.cpp @@ -58,25 +58,16 @@ void SwitchesPage::updateSwitchesList() { switches_->clear(); createSwitchesGroup(); - createAddButton(); + switches_->appendItem({"type1", "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES_ADD_SWITCH", {}, + [this](auto item) + { + addSwitchPage_ = std::make_unique(context_); + addSwitchPage_->attachCallbackOnSwitchAttach(addSwitchCb, this); + }, ACCESSIBILITY_UNIVERSAL_SWITCH_PLUS_ICON + }); removeSwitchesPageBtn_->disable(context_->config.configuration_items.size() == 0); } -void SwitchesPage::createAddButton() -{ - GenGroupItemData *item = createGendialGroupItem(switches_->getObject(), &itc_1text_1icon_3, - addSwitchClickedCb, this, - SwallowType::ICON_IMAGE, 0, - "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES_ADD_SWITCH", - {}, - NULL); - - if (item) { - item->l_swallow_path = ACCESSIBILITY_UNIVERSAL_SWITCH_PLUS_ICON; - item->userdata = context_; - } -} - void SwitchesPage::createSwitchesGroup() { for (auto &it : context_->config.configuration_items) { @@ -85,16 +76,6 @@ void SwitchesPage::createSwitchesGroup() } } -void SwitchesPage::addSwitchClickedCb(void *data, Evas_Object *obj, void *event_info) -{ - elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE); - retm_if(data == NULL, "Data argument is NULL"); - auto self = static_cast(data); - - self->addSwitchPage_ = std::make_unique(self->context_); - self->addSwitchPage_->attachCallbackOnSwitchAttach(addSwitchCb, self); -} - void SwitchesPage::switchClickCb(void *data, Evas_Object *obj, void *event_info) { Elm_Object_Item *item = (Elm_Object_Item *)event_info; diff --git a/src/SwitchesPage.hpp b/src/SwitchesPage.hpp index 2f1394a..87ce7dd 100644 --- a/src/SwitchesPage.hpp +++ b/src/SwitchesPage.hpp @@ -48,9 +48,7 @@ public: private: void updateSwitchesList(); - void createAddButton(); void createSwitchesGroup(); - static void addSwitchClickedCb(void *data, Evas_Object *obj, void *event_info); static void switchClickCb(void *data, Evas_Object *obj, void *event_info); static void switchUpdatedCb(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name); static void switchRemovedCb(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name); diff --git a/src/Widget.cpp b/src/Widget.cpp index 5cc000b..c45f432 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -36,6 +36,11 @@ void Widget::setMaxSizeHint(Evas_Coord v, Evas_Coord h) evas_object_size_hint_max_set(uniqueObj_.get(), v, h); } +void Widget::setAspectHint(Evas_Aspect_Control aspect, Evas_Coord w, Evas_Coord h) +{ + evas_object_size_hint_aspect_set(uniqueObj_.get(), aspect, w, h); +} + Rectangle Widget::getGeometry() { int x, y, w, h; diff --git a/src/Widget.hpp b/src/Widget.hpp index a1f1854..682ad84 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -41,6 +41,7 @@ public: void setAlignHint(double x, double y); void setMinSizeHint(Evas_Coord v, Evas_Coord h); void setMaxSizeHint(Evas_Coord v, Evas_Coord h); + void setAspectHint(Evas_Aspect_Control aspect, Evas_Coord w, Evas_Coord h); Rectangle getGeometry(); void setPosition(Point anchor); void setEvasSmartCallback(const std::string &eventName, std::function callback); -- 2.7.4