Languages

Menu
Sites
Language
Layout as a popup

Hi,

I dont want to use a popup object because I want to put a lot of elements inside that popup dont allow (input text, sliders...), can I declare a layout for this? as a secudary view, and then show and hide this secundary layout aver the main view... I would like to see any example.

Thanks.

Responses

3 Replies
Yasin Ali

Hi,
As Tizen technicalities currently not supporting features you're trying to
add in popup window then you may try with different approach.

* Like using form to get input etc.
* Getting floating behavior using webview integrating form input functionality.

Floating popup window with webview: Idea on code implementation:

/*
 * HEADER of popup function
 * popupso.h
 */

#ifndef _POPUPSO_H_
#define _POPUPSO_H_

#include <stdbool.h>
#include <tizen.h>

typedef void (*Popup_Close_Cb)(bool checked, void *data);
EXPORT_API bool webview_popup(const char* url, Popup_Close_Cb cb, void *data);

#endif // _POPUPSO_H_



/*
 * implementation of popup function
 * popupso.c
 */
#include "popupso.h"
#include <Elementary.h>
#include <EWebKit.h>
#include <dlog.h>
#include <efl_extension.h>

#ifdef  LOG_TAG
#undef  LOG_TAG
#endif
#define LOG_TAG "popupso"

#define PADDINGH 0.1
#define PADDINGV 0.2

static void win_back_cb(void *data, Evas_Object *obj, void *event_info)
{
    evas_object_del(obj);
}

static void close_cb(void *data, Evas_Object *obj, void *event_info)
{
 Evas_Object *popup_win = data;
 Evas_Object *check = evas_object_data_get(popup_win, "_checkbox");
 Popup_Close_Cb cb = evas_object_data_get(popup_win, "_cb");
 void *user_data = evas_object_data_get(popup_win, "_data");
 Eina_Bool checked = elm_check_state_get(check);

 evas_object_del(popup_win);
 cb(checked, user_data);
}

bool webview_popup(const char *url, Popup_Close_Cb cb, void *data)
{
 Evas_Object *popup_win = elm_win_add(NULL, "TestWindow", ELM_WIN_DIALOG_BASIC);
 // very important! if you don't make it close on back, user can't close it until push check or another button.
 eext_object_event_callback_add(popup_win, EEXT_CALLBACK_BACK, win_back_cb, NULL);

 int w,h;
 elm_win_screen_size_get(popup_win, NULL, NULL, &w, &h);
 evas_object_move(popup_win, 0, 0);
 int pw = w - w*PADDINGH, ph = h - h*PADDINGV;
 evas_object_resize(popup_win, pw, ph);

 Evas_Object *bg = elm_bg_add(popup_win);
 elm_bg_color_set(bg, 255, 255, 255);
 evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
 elm_win_resize_object_add(popup_win, bg);
 evas_object_show(bg);

 Evas_Object *vbox = elm_box_add(popup_win);
 evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
 evas_object_size_hint_min_set(vbox, pw, ph);
 elm_win_resize_object_add(popup_win, vbox);
 evas_object_show(vbox);

 Evas_Object *webview = ewk_view_add(evas_object_evas_get(popup_win));
 evas_object_size_hint_align_set(webview, EVAS_HINT_FILL, EVAS_HINT_FILL);
 ewk_view_url_set(webview, url);
 elm_box_pack_end(vbox, webview);
 evas_object_show(webview);

 Evas_Object *hbox = elm_box_add(vbox);
 elm_box_horizontal_set(hbox, EINA_TRUE);
 evas_object_size_hint_align_set(webview, EVAS_HINT_FILL, 1.0);
 elm_box_pack_end(vbox, hbox);
 evas_object_show(hbox);

 Evas_Object *label = elm_label_add(hbox);
 elm_object_text_set(label, "don't open in today ");
 evas_object_size_hint_align_set(label, 1.0, 0.5);
 elm_box_pack_end(hbox, label);
 evas_object_show(label);

 Evas_Object *check = elm_check_add(hbox);
 evas_object_size_hint_align_set(check, 1.0, 0.5);
 elm_box_pack_end(hbox, check);
 evas_object_smart_callback_add(check, "changed", close_cb, popup_win);
 evas_object_show(check);

 evas_object_data_set(popup_win, "_checkbox", check);
 evas_object_data_set(popup_win, "_cb", cb);
 evas_object_data_set(popup_win, "_data", data);

 int bottom_h, label_h, check_h;
 evas_object_geometry_get(label, NULL, NULL, NULL, &label_h);
 evas_object_geometry_get(check, NULL, NULL, NULL, &check_h);
 bottom_h = label_h > check_h ? label_h : check_h;

 /* webview don't have default minimum size
  * so if you don't set webview's minimum size,
  * webview will be not show.
  */
 evas_object_size_hint_min_set(webview, pw, ph - bottom_h);
 evas_object_show(popup_win);

 return true;
}

See some ref for hints:
https://developer.tizen.org/dev-guide/2.4/org.tizen.ui.practices/html/native/efl/form_tutorial_n.htm

Hope it will help you.
If you find my post is helpful for you, please mark it as the Best Answer to promote this post to others.

Yasin Ali

I have succeded with code like below to have popup functionality without Tizen Native popup Api, have a look :

#include "simplegame.h"

#include <Elementary.h>
#include <notification.h>
#include <Elementary.h>
#include <EWebKit.h>
#include <dlog.h>
#include <efl_extension.h>
#include <tizen.h>

#ifdef  LOG_TAG
#undef  LOG_TAG
#endif
#define LOG_TAG "popupso"

#define PADDINGH 0.1
#define PADDINGV 0.2

typedef void (*Popup_Close_Cb)(bool checked, void *data);
EXPORT_API bool webview_popup(const char* url, Popup_Close_Cb cb, void *data);

Evas_Object *table;
int gameStarted = 0;
int experiment_no = 0;
int color[4][4] = { { 0, 128, 0, 255 }, { 255, 0, 0, 255 }, { 0, 0, 255, 255 },
     { 0, 0, 0, 255 } };
typedef struct appdata {
 Evas_Object *win;
 Evas_Object *conform;
 Evas_Object *entry;
 Evas_Object *bubble, *entry_game_summary;
 Evas_Object *entry_gameState;
 Evas_Object *btn[200];

 char *EntryText;
 double SliderValue;

} appdata_s;

static void win_back_cb(void *data, Evas_Object *obj, void *event_info) {
 appdata_s *ad = data;
 evas_object_del(obj);
 /* Let window go to hide state. */
 //elm_win_lower(ad->win);
}
static void close_cb(void *data, Evas_Object *obj, void *event_info) {
 Evas_Object *popup_win = data;

 Evas_Object *entext = evas_object_data_get(popup_win, "_entry");

 dlog_print(DLOG_VERBOSE, LOG_TAG, "Entry Text: %s",
   elm_entry_entry_get(entext));
 Evas_Object *check = evas_object_data_get(popup_win, "_checkbox");
 Popup_Close_Cb cb = evas_object_data_get(popup_win, "_cb");
 void *user_data = evas_object_data_get(popup_win, "_data");
 appdata_s *ad = (appdata_s*) user_data;
 Eina_Bool checked = elm_check_state_get(check);

 Evas_Object *sliderval = evas_object_data_get(popup_win, "_slider");
 double sliderValue = elm_slider_value_get(sliderval);
 dlog_print(DLOG_VERBOSE, LOG_TAG, "Slider = %f", sliderValue);
 Evas_Object *mainLabell = evas_object_data_get(popup_win, "_mainLabel");
 char buf[200] = { '\0', };
 snprintf(buf, 150, "Slider Value %f", sliderValue);
 elm_object_text_set(mainLabell, buf);

 Evas_Object *entry = evas_object_data_get(popup_win, "_entry");
 dlog_print(DLOG_VERBOSE, LOG_TAG, "Entry = %s", elm_entry_entry_get(entry));


 Evas_Object *mainlabel2 = evas_object_data_get(popup_win, "_mainEntry");
 elm_object_text_set(mainlabel2, elm_entry_entry_get(entry));

 evas_object_del(popup_win);
 //cb(checked, user_data);
}

static void my_table_pack(Evas_Object *table, Evas_Object *child, int x, int y,
  int w, int h) {
 evas_object_size_hint_align_set(child, EVAS_HINT_FILL, EVAS_HINT_FILL);
 evas_object_size_hint_weight_set(child, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 elm_table_pack(table, child, x, y, w, h);
 evas_object_show(child);
}
static void app_terminate(void *data) {
 /* Release all resources. */
 dlog_print(DLOG_VERBOSE, LOG_TAG, "App Terminate");
}

static void btn_startPlay_cb(void *data, Evas_Object *obj, void *event_info) {
 appdata_s *ad = data;
 Evas_Object *mainLabel = evas_object_data_get(obj, "_label");
 Evas_Object *mainEntryValue = evas_object_data_get(obj, "_label2");

 Evas_Object *popup_win = elm_win_add(NULL, "TestWindow",
   ELM_WIN_DIALOG_BASIC);
 //Evas_Object *popup_win = elm_win_add(NULL, "TestWindow", ELM_WIN_POPUP_MENU);
 // very important! if you don't make it close on back, user can't close it until push check or another button.
 eext_object_event_callback_add(popup_win, EEXT_CALLBACK_BACK, win_back_cb,
 NULL);

 int w, h;
 elm_win_screen_size_get(popup_win, NULL, NULL, &w, &h);
 evas_object_move(popup_win, 0, 0);
 int pw = w - w * PADDINGH, ph = h - h * PADDINGV;
 evas_object_resize(popup_win, pw, ph);
 dlog_print(DLOG_VERBOSE, LOG_TAG, "%d %d", pw, ph);

 Evas_Object *bg = elm_bg_add(popup_win);
 elm_bg_color_set(bg, 255, 155, 256);
 evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
 elm_win_resize_object_add(popup_win, bg);
 evas_object_show(bg);

 Evas_Object *vbox = elm_box_add(popup_win);
 evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
 evas_object_size_hint_min_set(vbox, pw, ph);
 elm_win_resize_object_add(popup_win, vbox);
 evas_object_show(vbox);

 Evas_Object* entry = elm_entry_add(vbox);
 elm_entry_single_line_set(entry, EINA_TRUE);
 //elm_entry_entry_set(entry, "text");
 elm_entry_entry_insert(entry, "Sample Text");
 evas_object_size_hint_align_set(entry, 0.4, 0.7);
 elm_entry_editable_set(entry, EINA_TRUE);
 //const char* msg = elm_entry_entry_get(entry);
 //dlog_print(DLOG_VERBOSE, LOG_TAG, "Pre - %s",msg);
 elm_box_pack_end(vbox, entry);
 evas_object_show(entry);

 Evas_Object *slider = elm_slider_add(vbox);
 evas_object_resize(slider, 300, 50);
 elm_slider_min_max_set(slider, 0, 100);
 evas_object_move(slider, 50, 50);
 evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, EVAS_HINT_FILL);
 elm_box_pack_end(vbox, slider);
 evas_object_show(slider);

 Evas_Object *check = elm_check_add(vbox);
 evas_object_size_hint_align_set(check, 1.0, 0.5);
 elm_box_pack_end(vbox, check);
 evas_object_smart_callback_add(check, "changed", close_cb, popup_win);
 evas_object_show(check);

 evas_object_data_set(popup_win, "_checkbox", check);
 evas_object_data_set(popup_win, "_slider", slider);
 evas_object_data_set(popup_win, "_entry", entry);
 evas_object_data_set(popup_win, "_mainLabel", mainLabel);
 evas_object_data_set(popup_win, "_mainEntry", mainEntryValue);
 evas_object_data_set(popup_win, "_data", data);

 evas_object_show(popup_win);

}

static void win_delete_request_cb(void *data, Evas_Object *obj,
  void *event_info) {
 dlog_print(DLOG_VERBOSE, LOG_TAG, "win_delete_request_cb ");
 ui_app_exit();
}

static void my_table_pack_not_show(Evas_Object *table, Evas_Object *child,
  int x, int y, int w, int h) {
 evas_object_size_hint_align_set(child, EVAS_HINT_FILL, EVAS_HINT_FILL);
 evas_object_size_hint_weight_set(child, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 elm_table_pack(table, child, x, y, w, h);
 //evas_object_show(child);
}

static void create_base_gui(appdata_s *ad) {
 /* Window */
 dlog_print(DLOG_VERBOSE, LOG_TAG, "IN GUI");
 ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

 ad->win = elm_win_util_standard_add("bubble", "Bubble");
 elm_win_autodel_set(ad->win, EINA_TRUE);

 if (elm_win_wm_rotation_supported_get(ad->win)) {
  int rots[4] = { 0, 0, 0, 0 };
  elm_win_wm_rotation_available_rotations_set(ad->win,
    (const int *) (&rots), 4);
 }
 evas_object_smart_callback_add(ad->win, "delete,request",
   win_delete_request_cb,
   NULL);
 eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb,
   ad);

 /* Conformant */
 ad->conform = elm_conformant_add(ad->win);
 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_HIDE);
 elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
 evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND,
 EVAS_HINT_EXPAND);
 elm_win_resize_object_add(ad->win, ad->conform);
 evas_object_show(ad->conform);

 /* Box to put the table */
 Evas_Object *box = elm_box_add(ad->win);
 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 elm_win_resize_object_add(ad->win, box);
 evas_object_show(box);

 /* Table */
 table = elm_table_add(ad->win); // table for entry,go button and webview

 /* Make table homogenous - every cell will be the same size */
 elm_table_homogeneous_set(table, EINA_TRUE);

 /* Set padding*/
 elm_table_padding_set(table, elm_config_scale_get(),
   elm_config_scale_get());

 /* Let the table child allocation area expand within in the box */
 evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

 /* Set table to fill width but align to bottom of box */
 evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
 elm_box_pack_end(box, table);
 evas_object_show(table);

 {

  /*  Background   */
  Evas_Object *bg;
  bg = elm_bg_add(ad->win);
  elm_bg_color_set(bg, 0x7F, 0xFF, 0xD4);
  //evas_object_color_set(bg, 0, 0, 255, 255);
  my_table_pack(table, bg, 0, 0, 3, 10);

  /* 'Add Tab' Button*/
  ad->btn[5] = elm_button_add(ad->win);
  //evas_object_color_set(ad->btn[4], 255, 0, 0, 255);
  elm_object_text_set(ad->btn[5], "Start Play");
  evas_object_smart_callback_add(ad->btn[5], "clicked", btn_startPlay_cb,
    ad);
  my_table_pack(table, ad->btn[5], 0, 5, 1, 1);

  Evas_Object *label;
  label = elm_label_add(box);
  elm_object_text_set(label, "Slider Value to Show Here");
  evas_object_show(label);
  elm_box_pack_end(box, label);

  Evas_Object *label2;
  label2 = elm_label_add(box);
  elm_object_text_set(label2, "Entry Value to Show Here");
  evas_object_show(label2);
  elm_box_pack_end(box, label2);

  evas_object_data_set(ad->btn[5], "_label", label);
  evas_object_data_set(ad->btn[5], "_label2", label2);
 }

 /* Show window after base gui is set up */
 evas_object_show(ad->win);
}

static bool app_create(void *data) {
 /* Hook to take necessary actions before main event loop starts
  Initialize UI resources and application's data
  If this function returns true, the main loop of application starts
  If this function returns false, the application is terminated */
 appdata_s *ad = data;
 create_base_gui(ad);
 dlog_print(DLOG_VERBOSE, LOG_TAG, "App Create");
 return true;
}

static void app_control(app_control_h app_control, void *data) {
 /* Handle the launch request. */
 dlog_print(DLOG_VERBOSE, LOG_TAG, "App Control");
}

static void app_pause(void *data) {
 /* Take necessary actions when application becomes invisible. */
 dlog_print(DLOG_VERBOSE, LOG_TAG, "App Pused");
}

static void app_resume(void *data) {
 /* Take necessary actions when application becomes visible. */
 appdata_s *ad = data;
 dlog_print(DLOG_VERBOSE, LOG_TAG, "App Resumed");
}

static void ui_app_lang_changed(app_event_info_h event_info, void *user_data) {
 /*APP_EVENT_LANGUAGE_CHANGED*/
 char *locale = NULL;
 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE,
   &locale);
 elm_language_set(locale);
 free(locale);
 return;
}

static void ui_app_orient_changed(app_event_info_h event_info, void *user_data) {
 /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
 return;
}

static void ui_app_region_changed(app_event_info_h event_info, void *user_data) {
 /*APP_EVENT_REGION_FORMAT_CHANGED*/
}

static void ui_app_low_battery(app_event_info_h event_info, void *user_data) {
 /*APP_EVENT_LOW_BATTERY*/
}

static void ui_app_low_memory(app_event_info_h event_info, void *user_data) {
 /*APP_EVENT_LOW_MEMORY*/
}

int main(int argc, char *argv[]) {
 dlog_print(DLOG_VERBOSE, LOG_TAG, "Main");
 appdata_s ad = { 0, };
 int ret = 0;

 ui_app_lifecycle_callback_s event_callback = { 0, };
 app_event_handler_h handlers[5] = { NULL, };

 event_callback.create = app_create;
 event_callback.terminate = app_terminate;
 event_callback.pause = app_pause;
 event_callback.resume = app_resume;
 event_callback.app_control = app_control;

 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY],
   APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY],
   APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED],
   APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED],
   APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED],
   APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
 ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);

 ret = ui_app_main(argc, argv, &event_callback, &ad);
 if (ret != APP_ERROR_NONE) {
  dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);
 }

 return ret;
}

Hope it will help

Carlos Dominguez

Hello Ali,

Thanks, is so helpfull! but at las I did using a secundary windows with hs conformant and so on... and the show and hide, and effect is like a popup but with all windows functionality, somethin like:

static void
create_base_gui(appdata_s *ad)
{
    /* Window */
    ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
    elm_win_autodel_set(ad->win, EINA_TRUE);

    /* Conformant */
    ad->conform = elm_conformant_add(ad->win);
    elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
    elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
    evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    elm_win_resize_object_add(ad->win, ad->conform);
    evas_object_show(ad->conform);

    ad->table = elm_table_add(ad->win);

...

/*Open file windows drawing*/
    ad->open_win = elm_win_util_standard_add(PACKAGE, PACKAGE);
    elm_win_autodel_set(ad->open_win, EINA_TRUE);
    Evas_Object *open_conform;
    Evas_Object *open_table;
    open_conform = elm_conformant_add(ad->open_win);

...

and then show and hide ad->open_win.

I just wanted to share... maybe usefull...

Thanks man