835d00677d2c5968283869b6cdfa390e5e448073
[apps/native/gear-racing-controller.git] / src / view_manager / view_manager.c
1 /*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3 *
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://floralicense.org/license/
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <assert.h>
18 #include "view_manager/view_manager.h"
19
20 typedef struct _s_ui {
21         Evas_Object *win;
22         Evas_Object *conform;
23         Evas_Object *naviframe;
24         s_view_base *current_view;
25 } s_ui;
26
27 static s_ui s_info = { 0,};
28
29 static void _win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
30 {
31         ui_app_exit();
32 }
33
34 static void _create_window(void)
35 {
36         s_info.win = elm_win_util_standard_add(PACKAGE, PACKAGE);
37         if (!s_info.win) {
38                 assert(!"Failed to create the main window");
39         }
40
41         elm_win_conformant_set(s_info.win, EINA_TRUE);
42         elm_win_autodel_set(s_info.win, EINA_TRUE);
43
44         evas_object_smart_callback_add(s_info.win, "delete,request", _win_delete_request_cb, NULL);
45 }
46
47 static void _create_conformant(void)
48 {
49         s_info.conform = elm_conformant_add(s_info.win);
50         elm_win_indicator_mode_set(s_info.win, ELM_WIN_INDICATOR_SHOW);
51         elm_win_indicator_opacity_set(s_info.win, ELM_WIN_INDICATOR_OPAQUE);
52         evas_object_size_hint_weight_set(s_info.conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
53         elm_win_resize_object_add(s_info.win, s_info.conform);
54         evas_object_show(s_info.conform);
55 }
56
57 static void _create_naviframe(void)
58 {
59         s_info.naviframe = elm_naviframe_add(s_info.win);
60         evas_object_size_hint_weight_set(s_info.naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
61         elm_object_content_set(s_info.conform, s_info.naviframe);
62         evas_object_show(s_info.conform);
63 }
64
65 void view_manager_set_view(view_id id)
66 {
67         view_base_hide(s_info.current_view);
68
69         s_view_base *view = view_factory_create_view(s_info.naviframe, id);
70
71         s_info.current_view = view;
72         elm_naviframe_item_simple_push(s_info.naviframe, s_info.current_view->layout);
73
74         view_base_show(s_info.current_view);
75 }
76
77 void view_manager_initialize_ui(void)
78 {
79         _create_window();
80         _create_conformant();
81         _create_naviframe();
82
83         view_manager_set_view(VIEW_CONNECT_TO_CAR);
84         evas_object_show(s_info.win);
85 }
86
87 Evas_Object *view_manager_get_win(void)
88 {
89         return s_info.win;
90 }
91
92 Evas_Object *view_manager_get_conform(void)
93 {
94         return s_info.conform;
95 }