From: Woochan Lee Date: Thu, 24 Mar 2016 11:33:37 +0000 (+0900) Subject: Add View rotation sample. X-Git-Tag: submit/tizen/20160617.075742~97 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6856e4cb6ecead9d28d5d693f617d237241451b1;p=platform%2Fcore%2Fuifw%2Fui-viewmgr.git Add View rotation sample. page10 : using on_portrait, on_landscape page11 : using on_rotate Change-Id: I46734cd6bd2fc9181cfa056df96272ae665e3678 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 561834a..23e79ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ SET(EXEC_DIR ${PREFIX}) SET(BINDIR ${PREFIX}/bin) SET(LIBDIR ${PREFIX}/lib) SET(INCDIR ${PREFIX}/include) +SET(IMGDIR ${PREFIX}/share/${PROJECT_NAME}/images) SET(VERSION_MAJOR 0) SET(VERSION ${VERSION_MAJOR}.1.0) SET(VENDOR "samsung") @@ -48,3 +49,4 @@ ADD_CUSTOM_TARGET(${PROJECT_NAME}.edj ) ADD_DEPENDENCIES(${PROJECT_NAME} ${PROJECT_NAME}.edj) INSTALL(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.edj DESTINATION /usr/share/edje/${PROJECT_NAME}) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/images/ DESTINATION ${IMGDIR} FILES_MATCHING PATTERN "*.png") diff --git a/data/images/tizen.png b/data/images/tizen.png new file mode 100644 index 0000000..408188a Binary files /dev/null and b/data/images/tizen.png differ diff --git a/packaging/ui-viewmgr.spec b/packaging/ui-viewmgr.spec index afd5d09..36980bb 100644 --- a/packaging/ui-viewmgr.spec +++ b/packaging/ui-viewmgr.spec @@ -59,6 +59,7 @@ cp %{_builddir}/%{buildsubdir}/LICENSE %{buildroot}/usr/share/license/%{name} %defattr(-,root,root,-) %{_libdir}/libui-viewmgr.so.* %manifest %{name}.manifest +%{_datadir}/ui-viewmgr/images/* /usr/share/license/%{name} /usr/share/edje/ui-viewmgr/ui-viewmgr.edj diff --git a/src/examples/efl/main.cpp b/src/examples/efl/main.cpp index 95db0a4..9e53ce8 100644 --- a/src/examples/efl/main.cpp +++ b/src/examples/efl/main.cpp @@ -15,6 +15,8 @@ * */ #include "main.h" +#include "page11.h" +#include "page10.h" #include "page9.h" #include "page8.h" #include "page7.h" @@ -47,6 +49,74 @@ create_toolbar(Evas_Object *parent, const char *style) return toolbar; } +Evas_Object* +create_landscape_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad) +{ + char buf[128]; + Elm_Grid *grid; + Elm_Box *box; + Elm_Layout *layout; + Elm_Scroller *scroller; + Elm_Button *btn; + Elm_Image *image; + + /* Scroller */ + scroller = elm_scroller_add(parent); + elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE); + elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO); + + /* Grid */ + grid = elm_grid_add(scroller); + evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(grid); + + /* NoContent Layout */ + layout = elm_layout_add(grid); + elm_layout_theme_set(layout, "layout", "nocontents", "default"); + elm_object_part_text_set(layout, "elm.text", text); + evas_object_show(layout); + elm_grid_pack(grid, layout, 0, 0, 50, 100); + + /* Image */ + image = elm_image_add(grid); + snprintf(buf, sizeof(buf), "/usr/share/ui-viewmgr/images/tizen.png"); + elm_image_file_set(image, buf, NULL); + evas_object_show(image); + elm_grid_pack(grid, image, 50, 0, 50, 85); + + /* Box */ + box = elm_box_add(grid); + elm_box_horizontal_set(box, EINA_TRUE); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_padding_set(box, ELM_SCALE_SIZE(50), 0); + evas_object_show(box); + elm_grid_pack(grid, box, 0, 0, 100, 100); + + /* Previous Page Button */ + btn = elm_button_add(grid); + evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 1.0); + elm_object_text_set(btn, "Prev"); + evas_object_smart_callback_add(btn, "clicked", prev_btn_clicked_cb, ad); + evas_object_show(btn); + elm_box_pack_end(box, btn); + + /* Next Page Button */ + btn = elm_button_add(grid); + evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 1.0); + elm_object_text_set(btn, "Next"); + evas_object_smart_callback_add(btn, "clicked", next_btn_clicked_cb, ad); + evas_object_show(btn); + elm_box_pack_end(box, btn); + + elm_object_content_set(scroller, grid); + + return scroller; +} + Evas_Object* create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad) { diff --git a/src/examples/efl/main.h b/src/examples/efl/main.h index 5846a11..abc7ac7 100644 --- a/src/examples/efl/main.h +++ b/src/examples/efl/main.h @@ -39,5 +39,6 @@ typedef struct appdata { ui_viewmgr *viewmgr; } appdata_s; +Evas_Object *create_landscape_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad); Evas_Object *create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad); Elm_Toolbar *create_toolbar(Evas_Object *parent, const char *style); diff --git a/src/examples/efl/page10.h b/src/examples/efl/page10.h new file mode 100644 index 0000000..844a9e9 --- /dev/null +++ b/src/examples/efl/page10.h @@ -0,0 +1,120 @@ +/* + * 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. + * + */ +class page10: public ui_controller +{ +private: + appdata_s *ad; + +public: + page10(appdata_s *ad) + : ad(ad) + { + /* ui_view(controller, identity name). + Later, you could get the identity name using view->get_name(); */ + ad->viewmgr->push_view(new ui_view(this, "page10")); + } + + ~page10() + { + } + + Evas_Object *create_page10_content(ui_view *view, bool is_portrait) + { + Evas_Object *content; + + if (is_portrait) + { + //Create portrait content. + content = create_content(view->get_base(), + "ViewMgr Demo
Page 10 With
on_portrait(), on_landscape()", + //Prev Button Callback + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + ad->viewmgr->pop_view(); + }, + //Next Button Callback + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + create_page11(ad); + }, + this->ad); + } + else + { + //Create landscape content. + content = create_landscape_content(view->get_base(), + "ViewMgr Demo
Page 10 With
on_portrait(), on_landscape()", + //Prev Button Callback + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + ad->viewmgr->pop_view(); + }, + //Next Button Callback + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + create_page11(ad); + }, + this->ad); + } + + return content; + } + + void on_load() + { + Evas_Object *content; + + //Initialize contents. + ui_view *view = dynamic_cast(this->get_view()); + + //FIXME: Change below code to more convenient and clear way. + if (view->get_degree() == 90 || view->get_degree() == 270) + this->on_landscape(); + else + this->on_portrait(); + } + + void on_portrait() + { + Evas_Object *content; + + ui_view *view = dynamic_cast(this->get_view()); + + content = this->create_page10_content(view, true); + view->set_content(content, "Title Portrait"); + } + + void on_landscape() + { + Evas_Object *content; + + ui_view *view = dynamic_cast(this->get_view()); + + content = this->create_page10_content(view, false); + view->set_content(content, "Title Landscape"); + } + +}; + +void create_page10(appdata_s *ad) +{ + new page10(ad); +} diff --git a/src/examples/efl/page11.h b/src/examples/efl/page11.h new file mode 100644 index 0000000..115cf68 --- /dev/null +++ b/src/examples/efl/page11.h @@ -0,0 +1,105 @@ +/* + * 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. + * + */ + +class page11: public ui_view +{ +private: + appdata_s *ad; + +protected: + Evas_Object *create_page11_content(bool is_portrait) + { + Evas_Object *content; + + if (is_portrait) + { + //Create portrait content. + content = create_content(this->get_base(), "ViewMgr Demo
Page 11 (View inheritance)
With on_rotate()", + //Prev Button Callback + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + ad->viewmgr->pop_view(); + }, + //Next Button Callback + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + ad->viewmgr->deactivate(); + }, + this->ad); + } + else + { + //Create landscape content. + content = create_landscape_content(this->get_base(), "ViewMgr Demo
Page 11 (View inheritance)
With on_rotate()", + //Prev Button Callback + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + ad->viewmgr->pop_view(); + }, + //Next Button Callback + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + ad->viewmgr->deactivate(); + }, + this->ad); + } + + return content; + } + + virtual void on_load() + { + this->on_rotate(this->get_degree()); + } + + virtual void on_rotate(int degree) + { + Evas_Object *content; + + if (this->get_degree() == 0 || this->get_degree() == 180) + { + content = this->create_page11_content(true); + this->set_content(content, "Title Portrait"); + } + else + { + content = this->create_page11_content(false); + this->set_content(content, "Title Landscape"); + } + } + +public: + page11(const char *name, appdata_s *ad) + : ui_view(name), ad(ad) + { + ad->viewmgr->push_view(this); + } + + ~page11() + { + } +}; + +void create_page11(appdata_s *ad) +{ + /* A example for view class extension instead of using controller class. */ + new page11("page11", ad); +} diff --git a/src/examples/efl/page9.h b/src/examples/efl/page9.h index 464c1ad..f07b62c 100644 --- a/src/examples/efl/page9.h +++ b/src/examples/efl/page9.h @@ -39,7 +39,7 @@ public: [](void *data, Evas_Object *obj, void *event_info) -> void { appdata_s *ad = static_cast(data); - ad->viewmgr->deactivate(); + create_page10(ad); }, this->ad);