forked from enlightenment/efl
cxx: Showcase function pointer in calendar example
This is just a work-in-progress example.
This commit is contained in:
parent
5425baa906
commit
425d8db90f
|
@ -1,40 +1,60 @@
|
||||||
|
#define EFL_CXX_WREF_EASY
|
||||||
|
|
||||||
#include <Elementary.hh>
|
#include <Elementary.hh>
|
||||||
|
|
||||||
using efl::eo::instantiate;
|
using efl::eo::instantiate;
|
||||||
|
using namespace std::placeholders;
|
||||||
|
|
||||||
// FIXME: Function callbacks need a lot of love in C++
|
struct appData
|
||||||
static void
|
|
||||||
_format_cb(void *data EINA_UNUSED, Eina_Strbuf *str, const Eina_Value value)
|
|
||||||
{
|
{
|
||||||
if (::eina_value_type_get(&value) != ::EINA_VALUE_TYPE_TM)
|
appData() : m_win(nullptr) {}
|
||||||
{
|
|
||||||
// FIXME: val.to_string()
|
~appData() {
|
||||||
char *convert = ::eina_value_to_string(&value);
|
std::cout << "Good bye!" << std::endl;
|
||||||
eina_strbuf_append(str, convert);
|
}
|
||||||
free(convert);
|
|
||||||
}
|
void create() {
|
||||||
else
|
std::cout << "Hello!" << std::endl;
|
||||||
{
|
|
||||||
struct tm time;
|
instantiate(m_win);
|
||||||
eina_value_get(&value, &time);
|
m_win.text_set("Calendar Layout Formatting Example");
|
||||||
eina_strbuf_append_strftime(str, "%b. %y", &time);
|
m_win.delete_request_event_cb_add([&](){ destroy(); });
|
||||||
}
|
|
||||||
}
|
efl::ui::Calendar cal(instantiate, m_win);
|
||||||
|
m_win.content_set(cal);
|
||||||
|
|
||||||
|
auto wcal(cal._get_wref());
|
||||||
|
|
||||||
|
// FIXME: How does one figure out the argument types for the function?
|
||||||
|
auto cb_a = std::bind([=](
|
||||||
|
efl::eina::strbuf_wrapper& sb,
|
||||||
|
efl::eina::value_view const& value) {
|
||||||
|
try {
|
||||||
|
sb.append_strftime("%b. %y", efl::eina::get<tm>(value));
|
||||||
|
} catch (std::system_error const&) {
|
||||||
|
sb.append(value.to_string());
|
||||||
|
}
|
||||||
|
std::cout << "Month: " << std::string(sb) << std::endl;
|
||||||
|
}, _1, _2);
|
||||||
|
cal.format_cb_set(cb_a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroy() {
|
||||||
|
// FIXME: need del() function and no error on unref().
|
||||||
|
::efl_allow_parent_unref_set(m_win._eo_ptr(), true);
|
||||||
|
m_win = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
efl::ui::Win m_win;
|
||||||
|
};
|
||||||
|
|
||||||
|
static appData app;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
||||||
{
|
{
|
||||||
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN);
|
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
|
||||||
|
app.create();
|
||||||
efl::ui::Win win(instantiate);
|
|
||||||
win.text_set("Calendar Layout Formatting Example");
|
|
||||||
win.autohide_set(true);
|
|
||||||
|
|
||||||
efl::ui::Calendar cal(instantiate, win);
|
|
||||||
win.content_set(cal);
|
|
||||||
|
|
||||||
// FIXME: Function cb doesn't work (C++ variant)
|
|
||||||
cal.format_cb_set(_format_cb);
|
|
||||||
::efl_ui_format_cb_set(cal._eo_ptr(), NULL, _format_cb, NULL);
|
|
||||||
}
|
}
|
||||||
EFL_MAIN()
|
EFL_MAIN()
|
||||||
|
|
Loading…
Reference in New Issue