efl/legacy/elementary/src/examples/box_cxx_example_02.cc

219 lines
6.6 KiB
C++
Raw Normal View History

2014-07-16 13:34:22 -07:00
//Compile with:
//gcc -g box_example_02.c -o box_example_02 `pkg-config --cflags --libs elementary`
extern "C"
{
2014-07-16 13:34:22 -07:00
#ifdef HAVE_CONFIG_H
# include <elementary_config.h>
#endif
#define ELM_INTERNAL_API_ARGESFSDFEFC
#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
#define ELM_INTERFACE_ATSPI_COMPONENT_PROTECTED
#define ELM_INTERFACE_ATSPI_ACTION_PROTECTED
#define ELM_INTERFACE_ATSPI_VALUE_PROTECTED
#define ELM_INTERFACE_ATSPI_EDITABLE_TEXT_PROTECTED
#define ELM_INTERFACE_ATSPI_TEXT_PROTECTED
#define ELM_INTERFACE_ATSPI_SELECTION_PROTECTED
#define ELM_INTERFACE_ATSPI_IMAGE_PROTECTED
#define ELM_INTERFACE_ATSPI_WIDGET_ACTION_PROTECTED
#include <Elementary.h>
#include <Eo.h>
#include <Evas.h>
#include <Elementary.h>
#include <elm_widget.h>
#include "elm_interface_atspi_accessible.h"
#include "elm_interface_atspi_accessible.eo.h"
#include "elm_interface_atspi_widget_action.h"
#include "elm_interface_atspi_widget_action.eo.h"
}
#include <iostream>
2014-07-16 13:34:22 -07:00
#include <elm_win.eo.hh>
#include <elm_box.eo.hh>
#include <elm_button.eo.hh>
#include <Eina.hh>
2014-07-16 13:34:22 -07:00
#include <deque>
2014-07-16 13:34:22 -07:00
2014-07-21 09:35:11 -07:00
struct Transitions_Data
{
efl::eo::wref<elm_box> box;
std::deque<Evas_Object_Box_Layout> transitions;
Evas_Object_Box_Layout last_layout;
};
static void
_test_box_transition_change(void *data)
{
Transitions_Data *tdata = static_cast<Transitions_Data*>(data);
Elm_Box_Transition *layout_data;
Evas_Object_Box_Layout next_layout;
assert (!!data);
assert (!tdata->transitions.empty());
if(efl::eina::optional<elm_box> box = tdata->box.lock())
{
next_layout = tdata->transitions.front();
layout_data = elm_box_transition_new(2.0, tdata->transitions.back(),
nullptr, nullptr, next_layout, nullptr, nullptr,
_test_box_transition_change, tdata);
box->layout_set(elm_box_layout_transition, layout_data,
elm_box_transition_free);
tdata->last_layout = next_layout;
2014-07-17 07:30:39 -07:00
2014-07-21 09:35:11 -07:00
tdata->transitions.push_back(tdata->transitions[0]);
tdata->transitions.pop_front();
}
}
2014-07-16 13:34:22 -07:00
struct clean_ref
{
clean_ref(efl::eo::base base)
: _ref(base._eo_ptr())
{}
template <typename T>
void operator()(T const&, Eo_Event_Description const&, void*) const
{
if(_ref)
eo_unref(_ref);
}
Eo* _ref;
};
2014-07-16 13:34:22 -07:00
EAPI_MAIN int
elm_main(int argc, char *argv[])
{
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
2014-07-21 09:35:11 -07:00
Transitions_Data tdata;
Eo* test;
2014-07-16 13:34:22 -07:00
{
2014-07-17 07:30:39 -07:00
::elm_win win (elm_win_util_standard_add("box-transition", "Box Transition"));
win.autodel_set(true);
elm_box bigbox ( efl::eo::parent = win );
bigbox.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2014-07-21 09:35:11 -07:00
win.resize_object_add(bigbox);
2014-07-17 07:30:39 -07:00
bigbox.visibility_set(true);
win.callback_del_add(clean_ref(bigbox));
2014-07-17 07:30:39 -07:00
elm_box buttons ( efl::eo::parent = win );
buttons.horizontal_set(EINA_TRUE);
2014-07-21 09:35:11 -07:00
bigbox.pack_end(buttons);
2014-07-17 07:30:39 -07:00
buttons.visibility_set(true);
win.callback_del_add(clean_ref(buttons));
2014-07-17 07:30:39 -07:00
elm_button add ( efl::eo::parent = win );
add.text_set("elm.text", "Add");
2014-07-21 09:35:11 -07:00
buttons.pack_end(add);
2014-07-17 07:30:39 -07:00
add.visibility_set(true);
add.callback_clicked_add
2014-07-21 09:35:11 -07:00
(std::bind([&tdata]
{
2014-07-21 09:35:11 -07:00
if(efl::eina::optional<elm_box> box = tdata.box.lock())
{
elm_button btn ( efl::eo::parent = *box );
btn.text_set("elm.text", "I do nothing");
efl::eina::list<evas::object> childrens(box->children_get());
if (!childrens.empty())
{
2014-07-21 09:35:11 -07:00
box->pack_after(btn, childrens.front());
}
else
2014-07-21 09:35:11 -07:00
box->pack_end(btn);
btn.visibility_set(true);
}
}));
win.callback_del_add(clean_ref(add));
2014-07-17 07:30:39 -07:00
elm_button clear ( efl::eo::parent = win );
clear.text_set("elm.text", "Clear");
2014-07-21 09:35:11 -07:00
buttons.pack_end(clear);
2014-07-17 07:30:39 -07:00
clear.visibility_set(true);
clear.callback_clicked_add(std::bind([&tdata] { tdata.box.lock()->clear(); }));
win.callback_del_add(clean_ref(clear));
2014-07-17 07:30:39 -07:00
elm_box dynamic ( efl::eo::parent = win );
dynamic.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
dynamic.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL);
2014-07-21 09:35:11 -07:00
bigbox.pack_end(dynamic);
2014-07-17 07:30:39 -07:00
dynamic.visibility_set(true);
win.callback_del_add(clean_ref(dynamic));
2014-07-17 07:30:39 -07:00
2014-07-21 09:35:11 -07:00
auto unpack = std::bind([&tdata] (evas::clickable_interface obj)
{
elm_button btn = efl::eo::downcast<elm_button>(obj);
2014-07-21 09:35:11 -07:00
tdata.box.lock()->unpack(btn);
btn.position_set(0, 50);
btn.color_set(128, 64, 0, 128);
}, std::placeholders::_1)
;
2014-07-17 07:30:39 -07:00
elm_button bt1 ( efl::eo::parent = win );
bt1.text_set("elm.text", "Button 1");
bt1.callback_clicked_add(unpack);
2014-07-17 07:30:39 -07:00
bt1.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
bt1.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL);
2014-07-21 09:35:11 -07:00
dynamic.pack_end(bt1);
2014-07-17 07:30:39 -07:00
bt1.visibility_set(true);
win.callback_del_add(clean_ref(bt1));
2014-07-17 07:30:39 -07:00
elm_button bt2 ( efl::eo::parent = win );
bt2.text_set("elm.text", "Button 2");
2014-07-17 07:30:39 -07:00
bt2.size_hint_weight_set(EVAS_HINT_EXPAND, 0.0);
bt2.size_hint_align_set(1.0, 0.5);
bt2.callback_clicked_add(unpack);
2014-07-21 09:35:11 -07:00
dynamic.pack_end(bt2);
2014-07-17 07:30:39 -07:00
bt2.visibility_set(true);
win.callback_del_add(clean_ref(bt2));
2014-07-17 07:30:39 -07:00
elm_button bt3 ( efl::eo::parent = win );
bt3.text_set("elm.text", "Button 3");
bt3.callback_clicked_add(unpack);
2014-07-21 09:35:11 -07:00
dynamic.pack_end(bt3);
2014-07-17 07:30:39 -07:00
bt3.visibility_set(true);
win.callback_del_add(clean_ref(bt3));
2014-07-17 07:30:39 -07:00
2014-07-21 09:35:11 -07:00
tdata.box = dynamic;
tdata.last_layout = evas_object_box_layout_horizontal;
tdata.transitions.push_back(evas_object_box_layout_vertical);
tdata.transitions.push_back(evas_object_box_layout_horizontal);
tdata.transitions.push_back(evas_object_box_layout_stack);
tdata.transitions.push_back(evas_object_box_layout_homogeneous_vertical);
tdata.transitions.push_back(evas_object_box_layout_homogeneous_horizontal);
tdata.transitions.push_back(evas_object_box_layout_flow_vertical);
tdata.transitions.push_back(evas_object_box_layout_flow_horizontal);
tdata.transitions.push_back(evas_object_box_layout_stack);
2014-07-17 07:30:39 -07:00
dynamic.layout_set(evas_object_box_layout_horizontal, nullptr, nullptr);
2014-07-21 09:35:11 -07:00
_test_box_transition_change(&tdata);
2014-07-16 13:34:22 -07:00
2014-07-17 07:30:39 -07:00
win.size_set(300, 320);
win.visibility_set(true);
2014-07-21 09:35:11 -07:00
std::cout << "references to win " << win.ref_get() << std::endl;
test = win._eo_ptr();
win._release();
2014-07-16 13:34:22 -07:00
}
2014-07-21 09:35:11 -07:00
std::cout << "references to win " << ::eo_ref_get(test) << std::endl;
2014-07-16 13:34:22 -07:00
elm_run();
elm_shutdown();
return 0;
}
ELM_MAIN()