Compare commits

..

2 Commits

Author SHA1 Message Date
Lauro Moura 3d15e3f2bc Fix life example 2018-07-10 10:07:48 -03:00
Xavi Artigas 1a36d77c88 tutorials: Fix C# Life tutorial
Fix API changes, plus several logic and syntax errors... again, this had
never been built.
2018-07-06 12:44:02 +02:00
821 changed files with 1287 additions and 133294 deletions

View File

@ -1,7 +0,0 @@
{
"project_id" : "examples",
"projects" : "examples",
"conduit_uri" : "https://phab.enlightenment.org/",
"phabricator.uri" : "https://phab.enlightenment.org/",
"repository.callsign" : "examples"
}

4
.gitignore vendored
View File

@ -1,5 +1,3 @@
build
*.pot
.*.swp
subprojects
/meson.build

17
README
View File

@ -19,20 +19,3 @@ the appropriate steps automatically.
Directory naming is <type>/<language>/<name> please be careful to
namespace example binaries in case they are installed by the user.
Building the whole set of Examples
==================================
You can build all examples at once, all you have to do is:
./setup.py
This will create a folder called subprojects, all examples are
then sym-linked into this directory, a corresponding meson.build
file is generated, which uses every example as a subproject.
After that you can build the meson project with:
* mkdir build
* meson build/
* cd build
* ninja all

View File

@ -1,13 +0,0 @@
project(
'efl-example-calculator', 'c',
version : '0.0.1',
default_options: [ 'c_std=gnu99', 'warning_level=2' ],
meson_version : '>= 0.38.0')
eina = dependency('eina', version : '>=1.20.99')
efl = dependency('efl-ui', version : '>=1.20.99')
elm = dependency('elementary', version : '>=1.20.99')
inc = include_directories('.')
subdir('src')

View File

@ -1,212 +0,0 @@
#define EFL_BETA_API_SUPPORT 1
#include <Elementary.h>
#include <Efl_Ui.h>
static Efl_Ui_Textbox *_screen = NULL; // Text widget showing current value
static int _prev_value = 0; // Value introduced before an operation (first operand
static int _curr_value = 0; // Value currently being introduced (second operand)
static char _operation = '='; // Last operation button pressed
static Eina_Bool _must_overwrite = EINA_FALSE; // Whether next number must be appended to current input
// or overwrite it
// Quits the application
static void
_gui_quit_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
{
efl_exit(0);
}
// Performs "operation" on "currValue" and "prevValue" and leaves result in "currValue"
static void
_operate()
{
switch (_operation)
{
case '+':
_curr_value += _prev_value;
break;
case '-':
_curr_value = _prev_value - _curr_value;
break;
case '*':
_curr_value *= _prev_value;
break;
case '/':
_curr_value = _prev_value / _curr_value;
break;
default:
break;
}
}
// Called every time a button is pressed
static void
_button_pressed_cb(void *data, const Efl_Event *event EINA_UNUSED)
{
char button = ((const char *)data)[0];
// If it is a number, append it to current input (or replace it)
if (button >= '0' && button <= '9')
{
char str[2] = { button, '\0' };
if (_must_overwrite)
{
efl_text_set(_screen, "");
_must_overwrite = EINA_FALSE;
}
Efl_Text_Cursor_Object *cursor = efl_text_interactive_main_cursor_get(_screen);
efl_text_cursor_object_text_insert(cursor, str);
}
else
{
char str[32] = "";
// No need to sanitize these values, so do not emit "text changed" events
efl_event_freeze(_screen);
switch (button)
{
case 'C':
// Clear current input
efl_text_set(_screen, "0");
break;
case '+':
case '-':
case '*':
case '/':
case '=':
// If there was a pending operation, perform it
if (_operation != '=')
{
_operate();
snprintf(str, sizeof(str), "%d", _curr_value);
efl_text_set(_screen, str);
}
// Store this operation
_operation = button;
_must_overwrite = EINA_TRUE;
_prev_value = _curr_value;
break;
default:
break;
}
efl_event_thaw(_screen);
}
}
// Called every time the content of the screen changes
// We use it to sanitize input (remove leading zeros, for example)
// This makes more sense when the Text widget is editable, since the user
// is free to type anything.
static void
_screen_changed_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
{
char _text[32] = "";
const char *str = efl_text_get(_screen);
int d;
if ((strcmp(str, "") == 0) || (strcmp(str, "-") == 0))
{
snprintf(_text, sizeof(_text), "0");
}
else if (sscanf(str, "%d", &d) == 1)
{
snprintf(_text, sizeof(_text), "%d", d);
_curr_value = d;
}
if (strncmp(_text, str, sizeof(_text)))
{
// Avoid infinite recursion when setting the text from the
// "text changed" callback
efl_event_freeze(_screen);
efl_text_set(_screen, _text);
efl_event_thaw(_screen);
}
}
// Creates an Efl.Ui.Button and positions it in the given position inside the table
// The button text is colored with "r, g, b"
// "text" is what is drawn on the button, which might be a multi-byte unicode string.
// "command" is a single-char id for the button.
static void
_button_add(Efl_Ui_Table *table, const char *text, const char *command, int posx, int posy, int r, int g, int b)
{
Efl_Ui_Button *button =
efl_add(EFL_UI_BUTTON_CLASS, table,
efl_pack_table(table, efl_added, posx, posy, 1, 1),
efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED, _button_pressed_cb, command));
// Buttons can only have simple text (no font, styles or markup) but can swallow
// any other object we want.
// Therefore we create a more complex Efl_Ui_Text object and use it as content for the button.
Efl_Ui_Textbox *label =
efl_add(EFL_UI_TEXTBOX_CLASS, button,
efl_text_interactive_editable_set(efl_added, EINA_FALSE),
efl_text_horizontal_align_set(efl_added, 0.5),
efl_text_vertical_align_set(efl_added, 0.5),
efl_gfx_color_set(efl_added, r, g, b, 255),
efl_text_set(efl_added, text));
efl_text_font_family_set(label, "Sans");
efl_text_font_size_set(label, 36);
efl_content_set(button, label);
}
// Creates the UI
static void
_gui_setup()
{
Eo *win, *table;
// The window
win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
efl_text_set(efl_added, "EFL Calculator"),
efl_ui_win_autodel_set(efl_added, EINA_TRUE));
// when the user clicks "close" on a window there is a request to delete
efl_event_callback_add(win, EFL_UI_WIN_EVENT_DELETE_REQUEST, _gui_quit_cb, NULL);
// The table is the main layout
table = efl_add(EFL_UI_TABLE_CLASS, win,
efl_content_set(win, efl_added),
efl_pack_table_size_set(efl_added, 4, 5),
efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(300, 400)));
// Create all buttons using the _button_add helper
_button_add(table, "1", "1", 0, 3, 255, 255, 255);
_button_add(table, "2", "2", 1, 3, 255, 255, 255);
_button_add(table, "3", "3", 2, 3, 255, 255, 255);
_button_add(table, "4", "4", 0, 2, 255, 255, 255);
_button_add(table, "5", "5", 1, 2, 255, 255, 255);
_button_add(table, "6", "6", 2, 2, 255, 255, 255);
_button_add(table, "7", "7", 0, 1, 255, 255, 255);
_button_add(table, "8", "8", 1, 1, 255, 255, 255);
_button_add(table, "9", "9", 2, 1, 255, 255, 255);
_button_add(table, "0", "0", 1, 4, 255, 255, 255);
_button_add(table, "+", "+", 3, 1, 128, 128, 128);
_button_add(table, "", "-", 3, 2, 128, 128, 128);
_button_add(table, "×", "*", 3, 3, 128, 128, 128);
_button_add(table, "÷", "/", 3, 4, 128, 128, 128);
_button_add(table, "=", "=", 2, 4, 128, 128, 128);
_button_add(table, "C", "C", 0, 4, 0, 0, 0);
// Create a big Efl.Ui.Textbox screen to display the current input
_screen = efl_add(EFL_UI_TEXTBOX_CLASS, table,
efl_text_set(efl_added, "0"),
efl_text_multiline_set(efl_added, EINA_FALSE),
efl_text_interactive_editable_set(efl_added, EINA_FALSE),
efl_text_interactive_selection_allowed_set(efl_added, EINA_FALSE),
efl_pack_table(table, efl_added, 0, 0, 4, 1),
efl_text_horizontal_align_set(efl_added, 0.9),
efl_text_vertical_align_set(efl_added, 0.5),
efl_text_effect_type_set(efl_added, EFL_TEXT_STYLE_EFFECT_TYPE_GLOW),
efl_text_glow_color_set(efl_added, 128, 128, 128, 128),
efl_event_callback_add(efl_added, EFL_UI_TEXTBOX_EVENT_CHANGED,
_screen_changed_cb, NULL));
efl_text_font_family_set(_screen, "Sans");
efl_text_font_size_set(_screen, 48);
}
EAPI_MAIN void
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
_gui_setup();
}
EFL_MAIN()

Binary file not shown.

View File

@ -1,311 +0,0 @@
#define EFL_BETA_API_SUPPORT
#include <Efl_Ui.h>
#include <Eio.h>
#define TABLE_COLUMNS 4
#define TABLE_ROWS 5
typedef struct _Build_Data
{
Eo *over_container;
Efl_Io_Manager *io_manager;
Eo *table;
int x, y;
} Build_Data;
static const char *launcher_apps[][3] =
{ { "Call", "", "call-start" },
{ "Contacts", "", "contact-new" },
{ "Home", "xdg-open $HOME", "user-home" },
{ "Mail", "xdg-email 'info@enlightenment.org'", "mail-send-receive" },
{ "Documents", "xdg-open $(xdg-user-dir DOCUMENTS)", "folder-documents" } };
static void
_icon_clicked_cb(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
const char *command = data;
printf("%s\n", command);
efl_add(EFL_EXE_CLASS, efl_main_loop_get(),
efl_core_command_line_command_string_set(efl_added, command),
efl_task_run(efl_added));
}
static void
_icon_deleted_cb(void *data, const Efl_Event *ev EINA_UNUSED)
{
free(data);
}
// If "string" begins with the "key" prefix, sets "value" to whatever comes after "key"
// up until the next \n, replacing it with a \0, in a newly allocated string
// (which must be freed).
// Returns 1 if key was found.
static int
_parse_token(const char *string, const char *key, char **value)
{
if (eina_str_has_prefix(string, key))
{
int key_len = strlen(key);
const char *end = strchr(string + key_len, '\n');
if (!end)
end = string + strlen(string); // Point to EOF '\0'
int len = end - string - key_len;
if (*value) free(*value);
*value = eina_strndup(string + key_len, len + 1);
*((*value) + len) = '\0';
return 1;
}
return 0;
}
// Reads a .desktop file and returns the app name, the command to launch and the icon name.
// Returns 0 if it didn't work.
// Free the strings after usage.
static int
_parse_desktop_file(const char *desktop_file_path, char **app_name, char **app_command, char **app_icon_name)
{
EINA_RW_SLICE_DECLARE(slice, 1024);
Efl_Io_File *desktop_file;
int ret = 0;
desktop_file = efl_new(EFL_IO_FILE_CLASS,
efl_file_set(efl_added, desktop_file_path),
efl_io_closer_close_on_invalidate_set(efl_added, EINA_TRUE));
if (!desktop_file)
return 0;
char *name = NULL, *command = NULL, *icon = NULL, *onlyshow = NULL, *nodisplay = NULL;
while (!efl_io_reader_eos_get(desktop_file) &&
efl_io_reader_read(desktop_file, &slice) == EINA_ERROR_NO_ERROR)
{
char *content = eina_rw_slice_strdup(slice);
char *ptr = content;
while ((ptr = strchr(ptr, '\n')))
{
ptr++;
_parse_token(ptr, "Name=", &name);
_parse_token(ptr, "Exec=", &command);
_parse_token(ptr, "Icon=", &icon);
_parse_token(ptr, "OnlyShowIn=", &onlyshow);
_parse_token(ptr, "NoDisplay=", &nodisplay);
}
free(content);
}
if (name && command && icon && !onlyshow && (!nodisplay || eina_streq(nodisplay, "false")))
{
*app_name = name;
*app_command = command;
*app_icon_name = icon;
ret = 1;
}
else
{
if (name)
free(name);
if (command)
free(command);
if (icon)
free(icon);
}
if (onlyshow)
free(onlyshow);
if (nodisplay)
free(nodisplay);
efl_unref(desktop_file);
return ret;
}
// Creates a widget "button" with the specified name, icon and command
// to execute on click.
// These buttons are actually just an image with a label below.
static Efl_Ui_Widget *
_create_icon(Eo *parent, const char *name, const char *command, const char *icon)
{
Eo *box = efl_add(EFL_UI_BOX_CLASS, parent);
// Icon
efl_add(EFL_UI_IMAGE_CLASS, box,
efl_ui_image_icon_set(efl_added, icon),
efl_gfx_hint_weight_set(efl_added, 1.0, 1.0),
efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(64, 64)),
efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED, _icon_clicked_cb, command),
efl_event_callback_add(efl_added, EFL_EVENT_DEL, _icon_deleted_cb, command),
efl_pack(box, efl_added));
// Label
efl_add(EFL_UI_TEXTBOX_CLASS, box,
efl_text_set(efl_added, name),
efl_text_multiline_set(efl_added, EINA_TRUE),
efl_canvas_textblock_style_apply(efl_added,
"effect_type=soft_shadow shadow_color=#444 wrap=word font_size=10 align=center ellipsis=1"),
efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(0, 40)),
efl_text_interactive_editable_set(efl_added, EINA_FALSE),
efl_text_interactive_selection_allowed_set(efl_added, EINA_FALSE),
efl_pack(box, efl_added));
return box;
}
// Creates a widget "button" for the specified .desktop file.
// These buttons are actually just an image with a label below.
static Efl_Ui_Widget *
_create_app_icon(Eo *parent, const char *desktop_file_path)
{
char *name = NULL, *command = NULL, *icon = NULL;
Eo *widget = NULL;
if (!_parse_desktop_file(desktop_file_path, &name, &command, &icon))
return NULL;
widget = _create_icon(parent, name, command, icon);
free(name);
free(icon);
return widget;
}
// Adds a new empty page to the homescreen
static void
_add_page(Build_Data *bdata)
{
bdata->table = efl_add(EFL_UI_TABLE_CLASS, bdata->over_container,
efl_pack_table_size_set(efl_added, TABLE_COLUMNS, TABLE_ROWS));
efl_pack_end(bdata->over_container, bdata->table);
bdata->x = bdata->y = 0;
}
// Adds all files in the array to the homescreen, adding pages as they become full.
static void
_app_found(void *data, Eina_Array *files)
{
unsigned int i;
const char *item;
Eina_Array_Iterator iterator;
Build_Data *bdata = data;
EINA_ARRAY_ITER_NEXT(files, i, item, iterator)
{
Eo *app = _create_app_icon(bdata->over_container, item);
if (app)
{
if (!bdata->table)
_add_page(bdata);
efl_pack_table(bdata->table, app, bdata->x, bdata->y, 1, 1);
bdata->x++;
if (bdata->x == TABLE_COLUMNS)
{
bdata->x = 0;
bdata->y++;
if (bdata->y == TABLE_ROWS)
bdata->table = NULL;
}
}
}
}
// Called when directory listing has finished
static Eina_Value
_file_listing_done_cb (void *data, const Eina_Value file, const Eina_Future *dead EINA_UNUSED)
{
Build_Data *bdata = data;
// Fill any remaining empty cells with invisible rectangles so the rest of the cells
// keep the same size as other pages
while (bdata->y < TABLE_ROWS)
{
while (bdata->x < TABLE_COLUMNS)
{
efl_add(EFL_CANVAS_RECTANGLE_CLASS, bdata->table,
efl_gfx_color_set(efl_added, 0, 0, 0, 0),
efl_pack_table(bdata->table, efl_added, bdata->x, bdata->y, 1, 1));
bdata->x++;
}
bdata->x = 0;
bdata->y++;
}
return file;
}
// Create Spotlight widget and start populating it with user apps.
static void
_build_homescreen(Efl_Ui_Win *win, Build_Data *bdata)
{
Efl_Ui_Spotlight_Indicator *indicator = efl_new(EFL_UI_SPOTLIGHT_ICON_INDICATOR_CLASS);
Efl_Ui_Spotlight_Manager *scroll = efl_new(EFL_UI_SPOTLIGHT_SCROLL_MANAGER_CLASS);
bdata->over_container = efl_add(EFL_UI_SPOTLIGHT_CONTAINER_CLASS, win,
efl_ui_spotlight_manager_set(efl_added, scroll),
efl_ui_spotlight_indicator_set(efl_added, indicator)
);
bdata->table = NULL;
Eina_Future *future = efl_io_manager_ls(bdata->io_manager, "/usr/share/applications", bdata, _app_found, NULL);
eina_future_then(future, _file_listing_done_cb, bdata, NULL);
}
// The main box, with an upper space for the apps list and a lower space
// for the quick-action buttons.
static Efl_Ui_Widget*
_build_overall_structure(Efl_Ui_Win *win, Efl_Ui_Widget *homescreen)
{
Efl_Ui_Widget *box, *start_line;
box = efl_add(EFL_UI_BOX_CLASS, win);
// Set box background
// Objects retrieved with efl_part() only survive one function call, so we ref it
Eo *background = efl_ref(efl_part(box, "background"));
efl_file_key_set(background, "e/desktop/background");
efl_file_set(background, "../src/Hills.edj");
efl_file_load(background);
efl_unref(background);
efl_pack_end(box, homescreen);
// Start line
start_line = efl_add(EFL_UI_BOX_CLASS, win,
efl_gfx_color_set(efl_part(efl_added, "background"), 128, 128, 128, 128));
efl_gfx_hint_weight_set(start_line, 1.0, 0.0);
efl_ui_layout_orientation_set(start_line, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL);
efl_pack_end(box, start_line);
for (unsigned int i = 0; i < sizeof(launcher_apps)/sizeof(launcher_apps[0]); ++i)
{
efl_pack_end(start_line, _create_icon(start_line,
launcher_apps[i][0],
strdup(launcher_apps[i][1]),
launcher_apps[i][2]));
}
return box;
}
// Called when the app is closed
static void
_gui_quit_cb(void *data, const Efl_Event *event EINA_UNUSED)
{
Build_Data *bdata = data;
if (bdata->io_manager)
efl_del(bdata->io_manager);
free(bdata);
efl_exit(0);
}
EAPI_MAIN void
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
Eo *win, *desktop;
Build_Data *bdata = calloc (1, sizeof(Build_Data));
bdata->io_manager = efl_add(EFL_IO_MANAGER_CLASS, efl_main_loop_get());
win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
efl_ui_win_autodel_set(efl_added, EINA_TRUE));
// when the user clicks "close" on a window there is a request to delete
efl_event_callback_add(win, EFL_UI_WIN_EVENT_DELETE_REQUEST, _gui_quit_cb, bdata);
_build_homescreen(win, bdata);
desktop = _build_overall_structure(win, bdata->over_container);
efl_content_set(win, desktop);
}
EFL_MAIN()

View File

@ -1,11 +0,0 @@
src = files([
'homescreen.c',
])
deps = [eina, efl, elm]
executable('efl_example_homescreen', src,
dependencies : deps,
include_directories : inc,
install : true
)

View File

@ -1,5 +1,7 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Elementary.h>
#include <Efl_Ui.h>
#include "life_private.h"
@ -65,7 +67,7 @@ life_board_run(Efl_Ui_Win *win)
_life_timer = efl_add(EFL_LOOP_TIMER_CLASS, efl_main_loop_get(),
efl_loop_timer_interval_set(efl_added, 0.1));
efl_event_callback_add(_life_timer, EFL_LOOP_TIMER_EVENT_TIMER_TICK, _life_tick, win);
efl_event_callback_add(_life_timer, EFL_LOOP_TIMER_EVENT_TICK, _life_tick, win);
}
int

View File

@ -1,5 +1,7 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Elementary.h>
#include <Efl_Ui.h>
#include "life_private.h"
@ -47,19 +49,19 @@ _life_win_key_down(void *data EINA_UNUSED, const Efl_Event *event)
ev = event->info;
win = event->object;
if (!strcmp(efl_input_key_sym_get(ev), "space"))
if (!strcmp(efl_input_key_get(ev), "space"))
life_board_pause_toggle(win);
}
static Efl_Ui_Win *
static Evas_Object *
_life_win_setup(void)
{
Efl_Ui_Win *win;
int w;
int h;
Evas_Coord w;
Evas_Coord h;
win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_BASIC),
efl_text_set(efl_added, "EFL Life"),
efl_ui_win_autodel_set(efl_added, EINA_TRUE));
if (!win) return NULL;
@ -74,7 +76,7 @@ _life_win_setup(void)
life_render_init(win);
life_render_refresh(win);
efl_event_callback_add(win, EFL_GFX_ENTITY_EVENT_SIZE_CHANGED, _life_win_resize, NULL);
efl_event_callback_add(win, EFL_GFX_ENTITY_EVENT_RESIZE, _life_win_resize, NULL);
efl_event_callback_add(win, EFL_EVENT_POINTER_DOWN, _life_win_touch, NULL);
efl_event_callback_add(win, EFL_EVENT_KEY_DOWN, _life_win_key_down, NULL);

View File

@ -1,6 +1,7 @@
#ifndef LIFE_PRIVATE_H_
# define LIFE_PRIVATE_H_
#include <Elementary.h>
#include <Efl_Ui.h>
#define LIFE_BOARD_WIDTH 47

View File

@ -1,5 +1,7 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Elementary.h>
#include <Efl_Ui.h>
#include "life_private.h"
@ -46,7 +48,7 @@ life_render_layout(Efl_Ui_Win *win)
{
Eina_Size2D size;
double cw, ch;
Efl_Canvas_Rectangle *rect;
Evas_Object *rect;
int x, y;
size = efl_gfx_entity_size_get(win);
@ -67,7 +69,7 @@ life_render_layout(Efl_Ui_Win *win)
void
life_render_cell(Efl_Ui_Win *win EINA_UNUSED, int x, int y)
{
Efl_Canvas_Rectangle *rect;
Evas_Object *rect;
int i;
i = life_render_index_for_position(x, y);

View File

@ -1,9 +1,11 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Eina.h>
#include <Elementary.h>
#include <Efl_Ui.h>
Efl_Ui_Textbox *_editor;
Efl_Ui_Text *_editor;
Efl_Ui_Button *_toolbar_new;
Eina_Bool _edited = EINA_FALSE;
@ -14,7 +16,7 @@ static void
_gui_new_clicked_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
{
efl_text_set(_editor, "");
_edited = EINA_FALSE;
_edited = EINA_TRUE;
_gui_toolbar_refresh();
}
@ -40,12 +42,12 @@ _gui_toolbar_button_add(Efl_Ui_Box *toolbar, const char *name,
button = efl_add(EFL_UI_BUTTON_CLASS, toolbar,
efl_text_set(efl_added, name),
efl_pack(toolbar, efl_added),
efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED,
efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED,
func, efl_added));
efl_add(EFL_UI_IMAGE_CLASS, toolbar,
efl_ui_image_icon_set(efl_added, icon_name),
efl_content_set(button, efl_added));
efl_content_set(efl_part(button, "elm.swallow.content"), efl_added));
return button;
}
@ -57,15 +59,15 @@ _gui_toolbar_setup(Efl_Ui_Box *parent)
bar = efl_add(EFL_UI_BOX_CLASS, parent,
efl_pack(parent, efl_added),
efl_gfx_hint_weight_set(efl_added, 1, 0),
efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL));
efl_gfx_size_hint_weight_set(efl_added, 1, 0),
efl_ui_direction_set(efl_added, EFL_UI_DIR_HORIZONTAL));
_toolbar_new = _gui_toolbar_button_add(bar, "New", "document-new", _gui_new_clicked_cb);
// spacer box
efl_add(EFL_UI_BOX_CLASS, parent,
efl_pack(bar, efl_added),
efl_gfx_hint_weight_set(efl_added, 10, 0));
efl_gfx_size_hint_weight_set(efl_added, 10, 0));
_gui_toolbar_button_add(bar, "Quit", "application-exit", _gui_quit_cb);
_gui_toolbar_refresh();
@ -78,8 +80,8 @@ _gui_toolbar_refresh(void)
}
EFL_CALLBACKS_ARRAY_DEFINE(_editor_callbacks,
{ EFL_UI_TEXTBOX_EVENT_CHANGED, _editor_changed_cb },
{ EFL_TEXT_INTERACTIVE_EVENT_CHANGED_USER, _editor_changed_cb });
{ EFL_UI_TEXT_EVENT_CHANGED, _editor_changed_cb },
{ EFL_UI_TEXT_EVENT_CHANGED_USER, _editor_changed_cb });
static void
_gui_setup()
@ -87,7 +89,7 @@ _gui_setup()
Eo *win, *box;
win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_BASIC),
efl_text_set(efl_added, "Text Editor"),
efl_ui_win_autodel_set(efl_added, EINA_TRUE));
@ -96,18 +98,17 @@ _gui_setup()
box = efl_add(EFL_UI_BOX_CLASS, win,
efl_content_set(win, efl_added),
efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(360, 240)));
efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(360, 240)));
_gui_toolbar_setup(box);
_editor = efl_add(EFL_UI_TEXTBOX_CLASS, box,
_editor = efl_add(EFL_UI_TEXT_CLASS, box,
efl_text_font_set(efl_added, "Mono", 14),
efl_text_multiline_set(efl_added, EINA_TRUE),
efl_text_interactive_editable_set(efl_added, EINA_TRUE),
efl_ui_text_scrollable_set(efl_added, EINA_TRUE),
efl_event_callback_array_add(efl_added, _editor_callbacks(), NULL),
efl_pack(box, efl_added));
efl_ui_textbox_scrollable_set(_editor, EINA_TRUE);
efl_text_font_family_set(_editor, "Mono");
efl_text_font_size_set(_editor, 14);
}
EAPI_MAIN void

View File

@ -1,198 +0,0 @@
/* Simple calculator using an Efl.Ui.Table to place the buttons
*/
using System;
public class Calculator : Efl.Csharp.Application
{
private Efl.Ui.Textbox screen; // Text widget showing current value
private int prevValue = 0; // Value introduced before an operation (first operand)
private int currValue = 0; // Value currently being introduced (second operand)
private char operation = '='; // Last operation button pressed
private bool mustOverwrite = false; // Whether next number must be appended to current input
// or overwrite it
// Quits the application
private void GUIQuitCb(object sender, Efl.Gfx.EntityVisibilityChangedEventArgs ea)
{
if (ea.Arg == false)
Efl.App.AppMain.Quit(0);
}
// Performs "operation" on "currValue" and "prevValue" and leaves result in "currValue"
private void Operate()
{
switch (operation)
{
case '+':
currValue += prevValue;
break;
case '-':
currValue = prevValue - currValue;
break;
case '*':
currValue *= prevValue;
break;
case '/':
currValue = prevValue / currValue;
break;
default:
break;
}
}
// Called every time a button is pressed
private void ButtonPressedCb(char button)
{
// If it is a number, append it to current input (or replace it)
if (button >= '0' && button <= '9')
{
if (mustOverwrite)
{
screen.Text = "";
mustOverwrite = false;
}
screen.Text = screen.Text + button.ToString();
}
else
{
switch (button)
{
case 'C':
// Clear current input
screen.Text = "0";
break;
case '+':
case '-':
case '*':
case '/':
case '=':
// If there was a pending operation, perform it
if (operation != '=')
{
Operate();
screen.Text = currValue.ToString();
}
// Store this operation
operation = button;
mustOverwrite = true;
prevValue = currValue;
break;
default:
break;
}
}
}
// Called every time the content of the screen changes
// We use it to sanitize input (remove heading zeros, for example)
// This makes more sense when the Text widget is editable, since the user
// is free to type anything.
private void ScreenChangedCb(object sender, EventArgs ea)
{
string text = "";
string str = screen.Text;
int d;
if (str == "" || str == "-")
{
text = "0";
}
else
{
try
{
d = Convert.ToInt32(str);
text = d.ToString();
currValue = d;
}
catch {}
}
if (text != str) screen.Text = text;
}
// Creates an Efl.Ui.Button and positions it in the given position inside the table
// The button text is colored with "r, g, b"
// "text" is what is drawn on the button, which might be a multi-byte unicode string.
// "command" is a single-char id for the button.
private void AddButton(Efl.Ui.Table table, string text, char command, int posx, int posy, int r, int g, int b)
{
var button = new Efl.Ui.Button(table);
table.PackTable(button, posx, posy, 1, 1);
button.ClickedEvent += (object sender, Efl.Input.ClickableClickedEventArgs ea) => {
ButtonPressedCb(command);
};
// Buttons can only have simple text (no font, styles or markup) but can swallow
// any other object we want.
// Therefore we create a more complex Efl.Ui.Text object and use it as content for the button.
var label = new Efl.Ui.Textbox(table);
label.Editable = false;
label.TextHorizontalAlign = 0.5;
label.TextVerticalAlign = 0.5;
label.Color = (r, g, b, 255);
label.Text = text;
label.FontFamily = "Sans";
label.FontSize = 36;
button.Content = label;
}
// Called on start up. We use it to create the UI.
protected override void OnInitialize(string[] args)
{
// The window
var win = new Efl.Ui.Win(Efl.App.AppMain);
win.Text = "EFL Calculator";
win.Autohide = true;
win.VisibilityChangedEvent += GUIQuitCb;
// The table is the main layout
var table = new Efl.Ui.Table(win);
win.Content = table;
table.TableSize = (4, 5);
table.HintSizeMin = new Eina.Size2D(300, 400);
// Create all buttons using the AddButton helper
AddButton(table, "1", '1', 0, 3, 255, 255, 255);
AddButton(table, "2", '2', 1, 3, 255, 255, 255);
AddButton(table, "3", '3', 2, 3, 255, 255, 255);
AddButton(table, "4", '4', 0, 2, 255, 255, 255);
AddButton(table, "5", '5', 1, 2, 255, 255, 255);
AddButton(table, "6", '6', 2, 2, 255, 255, 255);
AddButton(table, "7", '7', 0, 1, 255, 255, 255);
AddButton(table, "8", '8', 1, 1, 255, 255, 255);
AddButton(table, "9", '9', 2, 1, 255, 255, 255);
AddButton(table, "0", '0', 1, 4, 255, 255, 255);
AddButton(table, "+", '+', 3, 1, 128, 128, 128);
AddButton(table, "", '-', 3, 2, 128, 128, 128);
AddButton(table, "×", '*', 3, 3, 128, 128, 128);
AddButton(table, "÷", '/', 3, 4, 128, 128, 128);
AddButton(table, "=", '=', 2, 4, 128, 128, 128);
AddButton(table, "C", 'C', 0, 4, 0, 0, 0);
// Create a big Efl.Ui.Text screen to display the current input
screen = new Efl.Ui.Textbox(table);
screen.Text = "0";
screen.Multiline = false;
screen.Editable = false;
screen.SelectionAllowed = false;
screen.TextHorizontalAlign = 0.9;
screen.TextVerticalAlign = 0.5;
screen.TextEffectType = Efl.TextStyleEffectType.Glow;
screen.TextGlowColor = (128, 128, 128, 128);
screen.FontFamily = "Sans";
screen.FontSize = 48;
screen.ChangedEvent += ScreenChangedCb;
table.PackTable(screen, 0, 0, 4, 1);
}
}
public class Example
{
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var calculator = new Calculator();
calculator.Launch();
}
}

View File

@ -1,12 +0,0 @@
src = files([
'calculator.cs',
])
deps = [efl_mono]
executable('efl_example_calculator', src,
dependencies : deps,
cs_args : efl_mono_libs,
install : true
)

View File

@ -19,7 +19,7 @@ public class LifeBoard
private bool[] board;
private bool[] board1, board2;
private Efl.LoopTimer lifeTimer = null;
private efl.ILoop_Timer lifeTimer = null;
private LifeRender lifeRender = null;
private void CellOn(int x, int y)
@ -58,11 +58,13 @@ public class LifeBoard
board = board1;
}
public void Run(Efl.Ui.Win win)
public void Run(efl.ui.IWin win)
{
lifeTimer = new Efl.LoopTimer(win, 0.1);
lifeTimer = new efl.Loop_Timer(win, (efl.ILoop_Timer etimer) => {
etimer.SetInterval(0.1);
});
lifeTimer.TimerTickEvent += (object sender, EventArgs ev) => {
lifeTimer.TickEvt += (object sender, EventArgs ev) => {
Nextgen();
if (this.lifeRender != null)
this.lifeRender.Refresh(win);
@ -139,16 +141,19 @@ public class LifeBoard
board = work;
}
public void TogglePause(Efl.Ui.Win win)
public void TogglePause(efl.ui.IWin win)
{
if (lifeTimer != null)
{
lifeTimer.Del();
lifeTimer.SetParent(null);
lifeTimer.Dispose();
lifeTimer = null;
Console.WriteLine("Paused.");
}
else
{
Run(win);
Console.WriteLine("Restarted.");
}
}

View File

@ -1,27 +1,26 @@
using System;
public class LifeWindow : Efl.Csharp.Application
public class LifeWindow
{
private LifeBoard lifeBoard;
private LifeRender lifeRender;
private Efl.Ui.Win win;
void ResizeEvent(object sender, EventArgs ev)
void ResizeEvt(object sender, EventArgs ev)
{
lifeRender.RenderLayout((Efl.Ui.Win)sender);
lifeRender.RenderLayout((efl.ui.IWin)sender);
}
void QuitEvent(object sender, Efl.Gfx.EntityVisibilityChangedEventArgs ev)
void QuitEvt(object sender, EventArgs ev)
{
// quit the mainloop
if (ev.Arg == false)
Efl.App.AppMain.Quit(0);
efl.ui.Config.Exit();
}
void TouchEvent(object sender, Efl.Input.InterfacePointerDownEventArgs ev)
void TouchEvt(object sender, efl.input.Interface.PointerDownEvt_Args ev)
{
int cellx, celly;
var position = ev.Arg.Position;
efl.ui.IWin win = (efl.ui.IWin)sender;
var position = ev.arg.GetPosition();
lifeRender.CellForCoords(win, position, out cellx, out celly);
int i = LifeBoard.IndexForPosition(cellx, celly);
@ -29,58 +28,53 @@ public class LifeWindow : Efl.Csharp.Application
lifeRender.RenderCell(win, cellx, celly);
}
void KeyDownEvent(object sender, Efl.Input.InterfaceKeyDownEventArgs ev)
void KeyDownEvt(object sender, efl.input.Interface.KeyDownEvt_Args ev)
{
if (ev.Arg.KeySym == "space")
efl.ui.IWin win = (efl.ui.IWin)sender;
if (ev.arg.GetKey() == "space")
lifeBoard.TogglePause(win);
}
protected override void OnInitialize(string[] args)
public LifeWindow()
{
win = new Efl.Ui.Win(parent: null, winName: "Life", winType: Efl.Ui.WinType.Basic);
win.Text = "EFL Life";
win.Autohide = true;
efl.ui.IWin win = new efl.ui.Win(null, (efl.ui.IWin ewin) => {
ewin.SetWinType(efl.ui.Win_Type.Basic);
ewin.SetText("EFL Life");
ewin.SetAutohide(true);
});
// when the user clicks "close" on a window there is a request to hide
((Efl.Gfx.IEntity)win).VisibilityChangedEvent += QuitEvent;
win.HideEvt += QuitEvt;
eina.Size2D sz;
sz.W = (int)(10 * LifeBoard.Width * win.GetScale());
sz.H = (int)(10 * LifeBoard.Height * win.GetScale());
lifeBoard = new LifeBoard();
lifeRender = new LifeRender(win, lifeBoard);
lifeRender.Refresh(win);
((Efl.Gfx.IEntity)win).SizeChangedEvent += ResizeEvent;
((Efl.Input.IInterface)win).PointerDownEvent += TouchEvent;
((Efl.Input.IInterface)win).KeyDownEvent += KeyDownEvent;
win.ResizeEvt += ResizeEvt;
win.PointerDownEvt += TouchEvt;
win.KeyDownEvt += KeyDownEvt;
win.Size = new Eina.Size2D((int)(10 * LifeBoard.Width * win.Scale),
(int)(10 * LifeBoard.Height * win.Scale));
win.SetSize(sz);
lifeBoard.Run(win);
}
protected override void OnPause() {
if (win != null) {
lifeBoard.TogglePause(win);
}
}
protected override void OnResume() {
if (win != null) {
lifeBoard.TogglePause(win);
}
}
protected override void OnTerminate() {
Console.WriteLine("Goodbye.");
}
}
public class Example
{
public static void Main()
{
efl.All.Init(efl.Components.Ui);
var lifeWin = new LifeWindow();
lifeWin.Launch();
// start the mainloop
efl.ui.Config.Run();
efl.All.Shutdown();
}
}

View File

@ -2,34 +2,34 @@ using System;
public class LifeRender
{
private Efl.Canvas.Rectangle[] lifeCells;
private efl.canvas.IRectangle[] lifeCells;
private LifeBoard lifeBoard;
public LifeRender(Efl.Ui.Win win, LifeBoard board)
public LifeRender(efl.ui.IWin win, LifeBoard board)
{
lifeBoard = board;
lifeBoard.SetRender(this);
lifeCells = new Efl.Canvas.Rectangle[LifeBoard.Height * LifeBoard.Width];
lifeCells = new efl.canvas.IRectangle[LifeBoard.Height * LifeBoard.Width];
for (int y = 0; y < LifeBoard.Height; ++y)
for (int x = 0; x < LifeBoard.Width; ++x)
lifeCells[LifeBoard.IndexForPosition(x, y)] = new Efl.Canvas.Rectangle(win);
lifeCells[LifeBoard.IndexForPosition(x, y)] = new efl.canvas.Rectangle(win);
RenderLayout(win);
}
public void CellForCoords(Efl.Ui.Win win, Eina.Position2D coord, out int x, out int y)
public void CellForCoords(efl.ui.IWin win, eina.Position2D coord, out int x, out int y)
{
Eina.Size2D size = win.Size;
eina.Size2D size = win.GetSize();
x = coord.X * LifeBoard.Width / size.W;
y = coord.Y * LifeBoard.Height / size.H;
}
public void RenderLayout(Efl.Ui.Win win)
public void RenderLayout(efl.ui.IWin win)
{
Eina.Size2D size = win.Size;
eina.Size2D size = win.GetSize();
double cw = (double) size.W / LifeBoard.Width;
double ch = (double) size.H / LifeBoard.Height;
@ -39,24 +39,30 @@ public class LifeRender
var rect = lifeCells[LifeBoard.IndexForPosition(x, y)];
// the little +1 here will avoid tearing as we layout non-multiple sizes
rect.Size = new Eina.Size2D((int)(cw + 1), (int)(ch + 1));
eina.Size2D sz;
sz.W = (int)(cw + 1);
sz.H = (int)(ch + 1);
rect.SetSize(sz);
rect.Position = new Eina.Position2D((int)(x * cw), (int)(y * ch));
eina.Position2D pos;
pos.X = (int)(x * cw);
pos.Y = (int)(y * ch);
rect.SetPosition(pos);
}
}
public void RenderCell(Efl.Ui.Win win, int x, int y)
public void RenderCell(efl.ui.IWin win, int x, int y)
{
int i = LifeBoard.IndexForPosition(x, y);
var rect = lifeCells[i];
if (lifeBoard.Cells[i])
rect.Color = (0, 0, 0, 255);
rect.SetColor(0, 0, 0, 255);
else
rect.Color = (255, 255, 255, 255);
rect.SetColor(255, 255, 255, 255);
}
public void Refresh(Efl.Ui.Win win)
public void Refresh(efl.ui.IWin win)
{
for (int y = 0; y < LifeBoard.Height; ++y)
for (int x = 0; x < LifeBoard.Width; ++x)

View File

@ -1,10 +0,0 @@
project(
'efl-example-mvvm', 'cs',
version : '0.0.1',
meson_version : '>= 0.49.0')
efl_mono = dependency('efl-mono', version : '>=1.23.99')
efl_mono_libs = efl_mono.get_pkgconfig_variable('mono_libs')
subdir('src')

View File

@ -1,69 +0,0 @@
using System;
class WeatherStation
{
public String Nick { get; set; }
public float Temperature { get; set; }
public static Efl.UserModel<WeatherStation> CreateModel(Efl.Loop loop)
{
Efl.UserModel<WeatherStation> stations = new Efl.UserModel<WeatherStation>(loop);
stations.Add (new WeatherStation{ Nick="FLN", Temperature=20 });
stations.Add (new WeatherStation{ Nick="SAO", Temperature=25 });
stations.Add (new WeatherStation{ Nick="RIO", Temperature=35 });
stations.Add (new WeatherStation{ Nick="BSB", Temperature=30 });
return stations;
}
}
class WeatherServer
{
}
class Application : Efl.Csharp.Application
{
private Efl.Ui.Win win;
protected override void OnInitialize(string[] args)
{
win = new Efl.Ui.Win(parent: null, winName: "MVVM Example",
winType: Efl.Ui.WinType.Basic);
win.Text = "EFL Life";
win.Autohide = true;
win.VisibilityChangedEvent += QuitEvt;
var factory = new Efl.Ui.ItemFactory<Efl.Ui.ListDefaultItem>(win);
// Text property is temporarily excluded from the extension method generation
// due to conflicts with the text classes.
factory.BindProperty("text", "Nick");
var model = WeatherStation.CreateModel(Efl.App.AppMain);
var manager = new Efl.Ui.PositionManager.List(win);
var list = new Efl.Ui.CollectionView(win);
list.PositionManager = manager;
list.Model = model;
list.Factory = factory;
win.SetContent(list);
win.Size = new Eina.Size2D(640, 480);
win.Visible = true;
}
void QuitEvt(object sender, Efl.Gfx.EntityVisibilityChangedEventArgs ev)
{
if (ev.Arg == false)
{
Efl.App.AppMain.Quit(0);
}
}
public static void Main()
{
var app = new Application();
app.Launch();
}
}

View File

@ -1,197 +1,142 @@
/* Simple text editor with a main text box and a toolbar on top:
+vbox----------------------------------------+
| +hbox------------------------------------+ |
| | +btn-+ +btn-+ +btn-+ +box-----+ +btn-+ | |
| | |NEW | |SAVE| |LOAD| | spacer | |QUIT| | |
| | +----+ +----+ +----+ +--------+ +----+ | |
| +----------------------------------------+ |
| +text------------------------------------+ |
| | | |
| | | |
| | Main text box | |
| | | |
| | | |
| +----------------------------------------+ |
+--------------------------------------------+
*/
using System;
public class TextEditor : Efl.Csharp.Application
public class TextEditor : IDisposable
{
private Efl.Ui.Win win; // The main window
private Efl.Ui.Textbox editorTextBox; // The main text entry
private Efl.Ui.Button toolbarButtonNew; // The "New" button in the toolbar
private Efl.Ui.Button toolbarButtonSave; // The "Save" button in the toolbar
private Efl.Ui.Button toolbarButtonLoad; // The "Load" button in the toolbar
private efl.ui.IWin win;
private efl.ui.IText editor;
private efl.ui.IButton toolbarNew;
private bool edited = false; // Document was edited since last save
private bool edited = false;
// File to load and save is fixed since we do not use a file selection dialog
private readonly string filename = System.IO.Path.Combine(System.IO.Path.GetTempPath(),
"texteditor_example.txt");
// Quits the application
private void GUIQuitCb(object sender, Efl.Gfx.EntityVisibilityChangedEventArgs ea)
private void GUIQuitCb(object sender, EventArgs ea)
{
if (ea.Arg == false)
Efl.App.AppMain.Quit(0);
efl.ui.Config.Exit();
}
// Enables or disables buttons on the toolbar as required
private void GUIToolbarRefresh()
{
// "New" is enabled if there is text in the text box
toolbarButtonNew.Disabled = string.IsNullOrEmpty(editorTextBox.Text);
// "Save" is enabled if the text has been modified since last save or load
toolbarButtonSave.Disabled = !edited;
// "Load" is enabled if there is a file to load
toolbarButtonLoad.Disabled = !System.IO.File.Exists(filename);
}
// Called when the text in the editor has changed
private void EditorChangedCb(object sender, EventArgs ea)
{
edited = true;
GUIToolbarRefresh();
}
// Shows a modal message popup with an "OK" button
private void ShowMessage(string message)
private efl.ui.IButton GUIToolbarButtonAdd(efl.ui.IBox toolbar, string name, string iconName, EventHandler func)
{
var popup = new Efl.Ui.AlertPopup (win);
popup.ScrollableText = message;
popup.HintSizeMax = new Eina.Size2D(200, 200);
popup.SetButton(Efl.Ui.AlertPopupButton.Positive, "OK", null);
popup.ButtonClickedEvent +=
(object sender, Efl.Ui.AlertPopupButtonClickedEventArgs ea) => {
// Dismiss popup when the button is clicked
((Efl.Ui.AlertPopup)sender).Del();
};
}
efl.ui.IButton button = new efl.ui.Button(toolbar);
button.SetText(name);
button.ClickedEvt += func;
// Adds a button to the toolbar, with the given text, icon and click event handler
private Efl.Ui.Button GUIToolbarButtonAdd(Efl.Ui.Box toolbar, string name,
string iconName, EventHandler<Efl.Input.ClickableClickedEventArgs> func)
{
var button = new Efl.Ui.Button(toolbar);
button.Text = name;
button.ClickedEvent += func;
button.HintWeight = (0, 1);
toolbar.DoPack(button);
// Set the content of the button, which is an image
var image = new Efl.Ui.Image(toolbar);
image.SetIcon(iconName);
button.SetContent(image);
efl.ui.IImage img = new efl.ui.Image(toolbar);
img.SetIcon(iconName);
efl.Content.static_cast(button.GetPart("efl.content")).SetContent(img);
toolbar.Pack(button);
return button;
}
// Creates a new toolbar, with all its buttons
private void GUIToolbarSetup(Efl.Ui.Box parent)
private void GUIToolbarSetup(efl.ui.IBox parent)
{
// Create a horizontal box container for the buttons
var bar = new Efl.Ui.Box(parent);
// 0 vertical weight means that the toolbar will have the minimum height
// to accommodate all its buttons and not a pixel more. The rest of the
// space will be given to the other object in the parent container.
bar.HintWeight = (1, 0);
bar.Orientation = Efl.Ui.LayoutOrientation.Horizontal;
parent.Pack(bar);
efl.ui.IBox bar = new efl.ui.Box(parent);
bar.SetHintWeight(1, 0);
bar.SetDirection(efl.ui.Dir.Horizontal);
parent.DoPack(bar);
// "New" button
toolbarButtonNew = GUIToolbarButtonAdd(bar, "New", "document-new",
(object sender, Efl.Input.ClickableClickedEventArgs ea) => {
// When this button is clicked, remove content and refresh toolbar
editorTextBox.Text = "";
toolbarNew = GUIToolbarButtonAdd(bar, "New", "document-new",
(object sender, EventArgs ea) =>
{
editor.SetText("");
edited = false;
GUIToolbarRefresh();
});
});
// "Save" button
toolbarButtonSave = GUIToolbarButtonAdd(bar, "Save", "document-save",
(object sender, Efl.Input.ClickableClickedEventArgs ea) => {
// When this button is clicked, try to save content and refresh toolbar
try {
System.IO.File.WriteAllText(filename, editorTextBox.Text);
edited = false;
GUIToolbarRefresh();
ShowMessage("Saved!");
} catch (Exception e) {
// If something fails, show the error message
ShowMessage(e.Message);
}
});
// spacer box
efl.ui.IBox box = new efl.ui.Box(parent);
box.SetHintWeight(10, 0);
bar.DoPack(box);
// "Load" button
toolbarButtonLoad = GUIToolbarButtonAdd(bar, "Load", "document-open",
(object sender, Efl.Input.ClickableClickedEventArgs ea) => {
// When this button is clicked, try to load content and refresh toolbar
try {
editorTextBox.Text = System.IO.File.ReadAllText(filename);
edited = false;
GUIToolbarRefresh();
ShowMessage("Loaded!");
} catch (Exception e) {
// If something fails, show the error message
ShowMessage(e.Message);
}
});
GUIToolbarButtonAdd(bar, "Quit", "application-exit", GUIQuitCb);
// Spacer box to use all available space not required by buttons
// (It has a default horizontal weight of 1, whereas all buttons have
// a horizontal weight of 0).
// As a result, it pushes the "Quit" button to the right margin and
// the rest to the left.
Efl.Ui.Box box = new Efl.Ui.Box(parent);
bar.Pack(box);
// "Quit" button
GUIToolbarButtonAdd(bar, "Quit", "application-exit", (object sender, Efl.Input.ClickableClickedEventArgs e) => { Efl.Ui.Config.Exit(); } );
GUIToolbarRefresh();
}
// Builds the user interface for the text editor
protected override void OnInitialize(string[] args)
private void GUIToolbarRefresh()
{
// Create a window and initialize it
win = new Efl.Ui.Win(parent: Efl.App.AppMain);
win.Text = "Text Editor";
win.Autohide = true;
win.VisibilityChangedEvent += GUIQuitCb;
toolbarNew.SetDisabled(!edited);
}
public TextEditor()
{
win = new efl.ui.Win(null, (efl.ui.IWin ewin) => {
ewin.SetWinType(efl.ui.Win_Type.Basic);
ewin.SetText("Text Editor");
ewin.SetAutohide(true);
});
// when the user clicks "close" on a window there is a request to hide
win.HideEvt += GUIQuitCb;
efl.ui.IBox box = new efl.ui.Box(win);
eina.Size2D sz;
sz.W = 360;
sz.H = 240;
box.SetHintMin(sz);
// Create a vertical box container
Efl.Ui.Box box = new Efl.Ui.Box(win);
win.SetContent(box);
// Create the toolbar and add it to the box
GUIToolbarSetup(box);
// Create the main text entry
editorTextBox = new Efl.Ui.Textbox(box);
editorTextBox.FontFamily = "Mono";
editorTextBox.FontSize = 14;
editorTextBox.Multiline = true;
editorTextBox.Editable = true;
editorTextBox.Scrollable = true;
editorTextBox.HintSizeMin = new Eina.Size2D(360, 240);
editorTextBox.ChangedEvent += EditorChangedCb;
editorTextBox.ChangedUserEvent += EditorChangedCb;
box.Pack(editorTextBox);
editor = new efl.ui.Text(box);
editor.SetFont("Mono", 14);
editor.SetMultiline(true);
editor.SetEditable(true);
editor.SetScrollable(true);
editor.SetScrollable(true);
editor.ChangedEvt += EditorChangedCb;
editor.ChangedUserEvt += EditorChangedCb;
// Initial refresh of the toolbar buttons
GUIToolbarRefresh();
box.DoPack(editor);
}
~TextEditor()
{
Dispose(false);
}
protected void Dispose(bool disposing)
{
editor.Dispose();
toolbarNew.Dispose();
win.Dispose();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Run()
{
// start main loop
efl.ui.Config.Run();
}
}
public class Example
{
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
TextEditor editor = new TextEditor();
editor.Launch();
efl.All.Init(efl.Components.Ui);
var textEditor = new TextEditor();
textEditor.Run();
// dispose after quit
textEditor.Dispose();
efl.All.Shutdown();
}
}

View File

@ -1,10 +0,0 @@
project('efl-examples',
'c',
version: '1.0'
)
subprojects = $subprojects
foreach subp : subprojects
subproject(subp)
endforeach

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>
@ -68,7 +69,7 @@ _events_freeze(Efl_Loop *mainloop)
efl_add(EFL_LOOP_TIMER_CLASS, mainloop,
efl_name_set(efl_added, "timer2"),
efl_loop_timer_interval_set(efl_added, .1),
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TIMER_TICK, _freezethaw_cb, mainloop));
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK, _freezethaw_cb, mainloop));
}
static void
@ -89,7 +90,7 @@ _timer_cb(void *data EINA_UNUSED, const Efl_Event *event)
}
EFL_CALLBACKS_ARRAY_DEFINE(_callback_array,
{ EFL_LOOP_TIMER_EVENT_TIMER_TICK, _timer_cb },
{ EFL_LOOP_TIMER_EVENT_TICK, _timer_cb },
{ EFL_EVENT_DEL, _del_obj_cb })
static void

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>
@ -59,7 +60,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
efl_add(EFL_LOOP_TIMER_CLASS, loop,
efl_loop_timer_interval_set(efl_added, 0.0005),
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TIMER_TICK, _timer_cb, NULL));
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK, _timer_cb, NULL));
}
EFL_MAIN()

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>
@ -21,7 +22,7 @@ _io_write(const char *filename)
Efl_Io_File *file;
file = efl_new(EFL_IO_FILE_CLASS,
efl_file_set(efl_added, filename), // mandatory
efl_file_set(efl_added, filename, NULL), // mandatory
efl_io_file_flags_set(efl_added, O_WRONLY | O_CREAT), // write and create - default is read
efl_io_file_mode_set(efl_added, 0644), // neccessary if we use O_CREAT
efl_io_closer_close_on_invalidate_set(efl_added, EINA_TRUE)); // recommended
@ -50,7 +51,7 @@ _io_read(const char *filename)
Efl_Io_File *file;
file = efl_new(EFL_IO_FILE_CLASS,
efl_file_set(efl_added, filename), // mandatory
efl_file_set(efl_added, filename, NULL), // mandatory
efl_io_closer_close_on_invalidate_set(efl_added, EINA_TRUE)); // recommended
if (!file)

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>
@ -63,7 +64,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
efl_add(EFL_LOOP_TIMER_CLASS, loop,
efl_loop_timer_interval_set(efl_added, 30),
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TIMER_TICK, _timer_cb, NULL));
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK, _timer_cb, NULL));
}
EFL_MAIN()

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>
@ -102,7 +103,7 @@ _test1_simple_future(Efl_Loop *loop)
// simulate a delayed promise resolve.
efl_add(EFL_LOOP_TIMER_CLASS, loop,
efl_loop_timer_interval_set(efl_added, 1),
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TIMER_TICK,
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK,
_test1_resolve, promise));
}
@ -153,7 +154,7 @@ _test2_failed_future(Efl_Loop *loop)
// simulate a delayed promise rejection.
efl_add(EFL_LOOP_TIMER_CLASS, loop,
efl_loop_timer_interval_set(efl_added, 1),
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TIMER_TICK,
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK,
_test2_reject, promise));
}
@ -277,7 +278,7 @@ _test4_chained_future(Efl_Loop *loop)
// simulate a delayed promise resolve.
efl_add(EFL_LOOP_TIMER_CLASS, loop,
efl_loop_timer_interval_set(efl_added, 1),
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TIMER_TICK,
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK,
_test4_resolve, promise));
}

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>
@ -196,7 +197,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev)
/* The TCP client to use to send/receive network data */
_dialer = efl_add(EFL_NET_DIALER_TCP_CLASS, loop,
efl_name_set(efl_added, "dialer"),
efl_event_callback_add(efl_added, EFL_NET_DIALER_EVENT_DIALER_CONNECTED, _dialer_connected, NULL));
efl_event_callback_add(efl_added, EFL_NET_DIALER_EVENT_CONNECTED, _dialer_connected, NULL));
if (!_dialer)
{
fprintf(stderr, "ERROR: could not create Efl_Net_Dialer_Tcp\n");

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>
@ -137,7 +138,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev)
/* The TCP client to use to send/receive network data */
_dialer = efl_add(EFL_NET_DIALER_TCP_CLASS, loop,
efl_name_set(efl_added, "dialer"),
efl_event_callback_add(efl_added, EFL_NET_DIALER_EVENT_DIALER_CONNECTED, _dialer_connected, NULL));
efl_event_callback_add(efl_added, EFL_NET_DIALER_EVENT_CONNECTED, _dialer_connected, NULL));
if (!_dialer)
{
fprintf(stderr, "ERROR: could not create Efl_Net_Dialer_Tcp\n");

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>
@ -133,7 +134,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev)
// Wait for 10 seconds before exiting this example
efl_add(EFL_LOOP_TIMER_CLASS, loop,
efl_loop_timer_interval_set(efl_added, 10.0),
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TIMER_TICK,
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK,
_quit_cb, NULL));
}
EFL_MAIN()

View File

@ -21,10 +21,3 @@ executable('efl_reference_ui_translation',
install : true
)
executable('efl_reference_ui_focus',
files(['focus_main.c']),
dependencies : deps,
include_directories : inc,
install : true
)

View File

@ -1,10 +1,12 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Eina.h>
#include <Elementary.h>
#include <Efl_Ui.h>
/*
* Efl.UI container examples.
* Efl.UI container exmaples.
*
* Load and pack a selection of containers.
* Each has it's own unique layout and methods which are demonstrated below.
@ -15,6 +17,7 @@
* TODO - still ELM Conformant
* TODO - still ELM Mapbuf
* TODO - still ELM Scroller
* TODO - still ELM Table
*/
// quit the app, called if the user clicks the Quit button or the window is deleted
@ -34,7 +37,7 @@ _ui_table_setup(Efl_Ui_Win *win)
table = efl_add(EFL_UI_TABLE_CLASS, win);
efl_pack_table_columns_set(table, 2);
efl_ui_layout_orientation_set(table, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL);
efl_pack_table_direction_set(table, EFL_UI_DIR_RIGHT, EFL_UI_DIR_DOWN);
efl_add(EFL_UI_BUTTON_CLASS, win,
efl_text_set(efl_added, "Long Button"),
@ -59,7 +62,7 @@ _ui_boxes_setup(Efl_Ui_Win *win)
int i;
box = efl_add(EFL_UI_BOX_CLASS, win,
efl_gfx_arrangement_content_padding_set(efl_added, 5, 0));
efl_pack_padding_set(efl_added, 5, 0, EINA_TRUE));
for (i = 1; i <= 4; i++)
{
@ -68,7 +71,7 @@ _ui_boxes_setup(Efl_Ui_Win *win)
efl_pack(box, efl_added));
if (i == 2)
efl_gfx_hint_size_max_set(button, EINA_SIZE2D(100, 50));
efl_gfx_size_hint_max_set(button, EINA_SIZE2D(100, 50));
}
return box;
@ -87,15 +90,15 @@ _ui_panes_setup(Efl_Ui_Win *win)
horiz_split = efl_add(EFL_UI_PANES_CLASS, win,
efl_content_set(efl_part(split, "second"), efl_added),
efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
efl_ui_direction_set(efl_added, EFL_UI_DIR_HORIZONTAL),
efl_ui_panes_split_ratio_set(efl_added, 0.85));
efl_content_set(efl_part(horiz_split, "first"), _ui_table_setup(win));
efl_add(EFL_UI_BUTTON_CLASS, win,
efl_text_set(efl_added, "Quit"),
efl_gfx_hint_size_max_set(efl_added, EINA_SIZE2D(150, 30)),
efl_gfx_size_hint_max_set(efl_added, EINA_SIZE2D(150, 30)),
efl_content_set(efl_part(horiz_split, "second"), efl_added),
efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED,
efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED,
_gui_quit_cb, efl_added));
}
@ -105,7 +108,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
Eo *win;
win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_BASIC),
efl_text_set(efl_added, "Hello World"),
efl_ui_win_autodel_set(efl_added, EINA_TRUE));

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>
@ -27,7 +28,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
Efl_Ui_Win *win, *box;
win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_BASIC),
efl_text_set(efl_added, "Size Control"),
efl_ui_win_autodel_set(efl_added, EINA_TRUE));
@ -44,12 +45,12 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
efl_add(EFL_UI_BUTTON_CLASS, win,
efl_text_set(efl_added, "Small"),
efl_pack_end(box, efl_added),
efl_gfx_hint_size_max_set(efl_added, EINA_SIZE2D(50, 50)));
efl_gfx_size_hint_max_set(efl_added, EINA_SIZE2D(50, 50)));
efl_add(EFL_UI_BUTTON_CLASS, win,
efl_text_set(efl_added, "Big Button"),
efl_pack_end(box, efl_added),
efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(100, 100)));
efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(100, 100)));
efl_gfx_entity_size_set(win, EINA_SIZE2D(320, 320));
}

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <stdio.h>
@ -33,7 +34,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
Efl_Ui_Win *win, *box;
win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_BASIC),
efl_text_set(efl_added, "Translations"),
efl_ui_win_autodel_set(efl_added, EINA_TRUE));
@ -44,18 +45,18 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
efl_content_set(win, efl_added));
efl_add(EFL_UI_BUTTON_CLASS, win,
efl_ui_l10n_text_set(efl_added, "Translations", _TEXT_DOMAIN),
efl_ui_translatable_text_set(efl_added, "Translations", _TEXT_DOMAIN),
efl_pack_end(box, efl_added));
efl_add(EFL_UI_BUTTON_CLASS, win,
efl_ui_l10n_text_set(efl_added, "Help", _TEXT_DOMAIN),
efl_ui_translatable_text_set(efl_added, "Help", _TEXT_DOMAIN),
efl_pack_end(box, efl_added));
efl_add(EFL_UI_BUTTON_CLASS, win,
efl_ui_l10n_text_set(efl_added, "Quit", _TEXT_DOMAIN),
efl_ui_translatable_text_set(efl_added, "Quit", _TEXT_DOMAIN),
efl_pack_end(box, efl_added),
efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(100, 100)),
efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED,
efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(100, 100)),
efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED,
_gui_quit_cb, efl_added));
efl_gfx_entity_size_set(win, EINA_SIZE2D(320, 320));

View File

@ -1,70 +0,0 @@
/*
* Efl Core Event examples.
*
* This example shows the various ways of adding callbacks for standard events.
* It also demonstrates how to freeze and thaw events on an object.
*/
using System;
public class Example : Efl.Csharp.Application
{
// Polling callback
private static void PollCb(object sender, EventArgs e)
{
Console.WriteLine(" Poll from {0}", ((Efl.Object)sender).Name);
}
protected override void OnInitialize(string[] args)
{
// Retrieve the application's main loop
var mainloop = Efl.App.AppMain;
mainloop.Name = "Mainloop";
// This event gets triggered continuously
mainloop.PollHighEvent += PollCb;
// This timer will control events fired by the main loop
var timer = new Efl.LoopTimer(mainloop, 0.1);
timer.Name = "Timer";
// To count number of timer triggers
int tick_count = 0;
timer.TimerTickEvent += (object sender, EventArgs e) => {
string message = "Tick {0} from {1}: ";
// Depending on the number of timer ticks, it does a different thing
switch (tick_count) {
case 0:
message += "Freezing Mainloop events";
mainloop.FreezeEvent();
break;
case 1:
message += "Thawing Mainloop events";
mainloop.ThawEvent();
break;
default:
message += "Quitting";
mainloop.Quit(new Eina.Value(0));
break;
}
Console.WriteLine(message, tick_count, ((Efl.Object)sender).Name);
tick_count++;
};
Console.WriteLine("Waiting for Timer to call back...");
}
protected override void OnTerminate()
{
Console.WriteLine("Application is over");
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch(Efl.Csharp.Components.Basic);
}
}

View File

@ -1,46 +0,0 @@
/*
* Efl Core Idler examples.
*
* Here we register callbacks to execute code when the loop is idle.
* We also record when we enter or exit the idle state.
*
* We initiate a timer to exit the idle state and then exit the application.
*/
using System;
public class Example : Efl.Csharp.Application
{
protected override void OnInitialize(string[] args)
{
// Retrieve the application's main loop
var mainloop = Efl.App.AppMain;
// Register to all Idle events
mainloop.IdleEnterEvent += (object sender, EventArgs e) => {
Console.WriteLine("IDLE ENTER: Entering idle state.");
};
mainloop.IdleEvent += (object sender, EventArgs e) => {
Console.WriteLine("IDLE: Executing idler callback while in idle state.");
};
mainloop.IdleExitEvent += (object sender, EventArgs e) => {
Console.WriteLine("IDLE EXIT: Leaving idle state.");
};
// Use a timer to exit the application
var timer = new Efl.LoopTimer(mainloop, 0.02);
timer.TimerTickEvent += (object sender, EventArgs e) => {
Console.WriteLine("TIMER: timer callback called, exiting.");
mainloop.Quit(0);
};
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch(Efl.Csharp.Components.Basic);
}
}

View File

@ -1,45 +0,0 @@
/*
* Efl Core Poll examples.
*
* This example sets up poll callbacks for LOW, MEDIUM and HIGH frequency events.
* We run for 30 seconds and print to stdout to show when each is called.
* Depending on your system this may not include any LOW frequency polls.
*/
using System;
public class Example : Efl.Csharp.Application
{
protected override void OnInitialize(string[] args)
{
// Retrieve the application's main loop
var mainloop = Efl.App.AppMain;
// Register to all Poll events
mainloop.PollLowEvent += (object sender, EventArgs e) => {
Console.Write("L");
};
mainloop.PollMediumEvent += (object sender, EventArgs e) => {
Console.Write("M");
};
mainloop.PollHighEvent += (object sender, EventArgs e) => {
Console.Write(".");
};
// Use a timer to exit the application
var timer = new Efl.LoopTimer(mainloop, 30);
timer.TimerTickEvent += (object sender, EventArgs e) => {
Console.WriteLine("\nTIMER: timer callback called, exiting.");
mainloop.Quit(0);
};
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch(Efl.Csharp.Components.Basic);
}
}

View File

@ -1,18 +1,18 @@
/*
* Eina.Array examples.
* Eina Array examples.
*
* These examples demonstrate how to work with Eina.Array data and methods.
* We use a simple array of strings to initialise our Eina.Array before
* These examples demonstrate how to work with eina_array data and methods.
* We use a simple array of strings to initialise our eina_array before
* performing various mutations and printing the results.
*/
using System;
public class Example : Efl.Csharp.Application
public class Example
{
static Eina.Array<string> CreateArray()
static eina.Array<string> CreateArray()
{
// Some content to populate our array
// some content to populate our array
string[] names =
{
"helo", "hera", "starbuck", "kat", "boomer",
@ -21,8 +21,8 @@ public class Example : Efl.Csharp.Application
"skulls", "bulldog", "flat top", "hammerhead", "gonzo"
};
// Set up an array with a growth step to give a little headroom
var array = new Eina.Array<string>(25u);
// set up an array with a growth step to give a little headroom
var array = new eina.Array<string>(25u);
foreach (string name in names)
array.Push(name);
@ -32,51 +32,44 @@ public class Example : Efl.Csharp.Application
static bool ItemRemoveCb(string name)
{
// Let's keep any strings that are no more than 7 characters long
// let's keep any strings that are no more than 7 characters long
if (name.Length <= 7)
return false;
return true;
}
protected override void OnInitialize(string[] args)
public static void Main()
{
efl.All.Init();
var array = CreateArray();
// Show the contents of our array
Console.WriteLine("Array count: {0}", array.Count);
// show the contents of our array
Console.WriteLine("Array count: {0}", array.Count());
Console.WriteLine("Array contents:");
foreach(string name in array)
{
// Content is strings so we simply print the data
// content is strings so we simply print the data
Console.WriteLine(" {0}", name);
}
// Access a specific item in the array
// access a specific item in the array
Console.WriteLine("Top gun: {0}", array[2]);
// Update a single item in the array
// update a single item in the array
array[17] = "flattop";
// Update the array removing items that match the ItemRemoveCb criteria
// update the array removing items that match the ItemRemoveCb criteria
// array.RemoveAll(ItemRemoveCb); // TODO: FIXME
// Print the new contents of our array
Console.WriteLine("New array count: {0}", array.Count);
// print the new contents of our array
Console.WriteLine("New array count: {0}", array.Length);
Console.WriteLine("New array contents:");
foreach(string name in array)
Console.WriteLine(" {0}", name);
array.Dispose();
Efl.App.AppMain.Quit(0);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch(Efl.Csharp.Components.Basic);
efl.All.Shutdown();
}
}

View File

@ -1,7 +1,7 @@
/*
* Eina.Hash examples.
* Eina Hash examples.
*
* These examples demonstrate how to work with Eina.Hash data and methods.
* These examples demonstrate how to work with eina_hash data and methods.
*
* We have two main hash objects here, firstly an int keyed hash with some
* dummy content.
@ -12,12 +12,12 @@
using System;
using System.Collections.Generic;
public class Example : Efl.Csharp.Application
public class Example
{
static Eina.Hash<Int32, string> CreateHash()
static eina.Hash<Int32, string> CreateHash()
{
// Let's create a simple hash with integers as keys
var hash = new Eina.Hash<Int32, string>();
// let's create a simple hash with integers as keys
var hash = new eina.Hash<Int32, string>();
// Add initial entries to our hash
for (int i = 0; i < 10; ++i)
@ -30,13 +30,13 @@ public class Example : Efl.Csharp.Application
{
var hash = CreateHash();
// Get an iterator of the keys so we can print a line per entry
// get an iterator of the keys so we can print a line per entry
var iter = hash.Keys();
Console.WriteLine("Print contents of int hash");
foreach (int key in iter)
{
// Look up the value for the key so we can print both
// look up the value for the key so we can print both
string value = hash.Find(key);
Console.WriteLine($" Item found with id {key} has value {value}");
}
@ -46,26 +46,26 @@ public class Example : Efl.Csharp.Application
hash.Dispose();
}
// Here we begin the phone book example
// here we begin the phone book example
static void PrintPhonebookEntry(string key, string data)
{
Console.WriteLine($" Name: {key}\tNumber {data}\n");
}
static void PrintPhonebook(Eina.Hash<string, string> book)
static void PrintPhonebook(eina.Hash<string, string> book)
{
int count = book.Population();
Console.WriteLine($"Complete phone book ({count}):");
// As an enumerator, iterate over the key and value for each entry
// as an enumerator, iterate over the key and value for each entry
foreach (KeyValuePair<string, string> kvp in book)
PrintPhonebookEntry(kvp.Key, kvp.Value);
Console.WriteLine("");
}
static Eina.Hash<string, string> CreatePhonebook()
static eina.Hash<string, string> CreatePhonebook()
{
string[] names =
{
@ -78,8 +78,8 @@ public class Example : Efl.Csharp.Application
"+23 45 678-91012", "+34 56 789-10123"
};
// Create hash of strings to strings
var hash = new Eina.Hash<string, string>();
// create hash of strings to strings
var hash = new eina.Hash<string, string>();
// Add initial entries to our hash
for (int i = 0; i < 4; ++i)
@ -117,20 +117,13 @@ public class Example : Efl.Csharp.Application
phone_book.Dispose();
}
protected override void OnInitialize(string[] args)
public static void Main()
{
efl.All.Init();
HashDemo();
PhonebookDemo();
Efl.App.AppMain.Quit(0);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch(Efl.Csharp.Components.Basic);
efl.All.Shutdown();
}
}

View File

@ -1,18 +1,18 @@
/*
* Eina.Iterator examples.
* Eina Iterator examples.
*
* These examples demonstrate how to work with Eina.Iterator methods.
* Both an Eina.List and an Eina.Array are created and an iterator obtained
* These examples demonstrate how to work with eina_iterator methods.
* Both an eina_list and an eina_array are created and an iterator obtained
* for both. You can see how we can use iterators irrespective of the source
* and also that there are different ways to work with iterating content.
*/
using System;
public class Example : Efl.Csharp.Application
public class Example
{
static void PrintIterator(Eina.Iterator<string> it)
static void PrintIterator(eina.Iterator<string> it)
{
Console.WriteLine("--iterator start--");
foreach(string s in it)
@ -20,7 +20,7 @@ public class Example : Efl.Csharp.Application
Console.WriteLine("-- iterator end --");
}
static Eina.Array<string> CreateArray()
static eina.Array<string> CreateArray()
{
string[] strings =
{
@ -30,7 +30,7 @@ public class Example : Efl.Csharp.Application
"boomer"
};
var array = new Eina.Array<string>(4u);
var array = new eina.Array<string>(4u);
foreach (string s in strings)
array.Push(s);
@ -38,7 +38,7 @@ public class Example : Efl.Csharp.Application
return array;
}
static Eina.List<string> CreateList()
static eina.List<string> CreateList()
{
string[] more_strings = {
"sentence strings",
@ -47,7 +47,7 @@ public class Example : Efl.Csharp.Application
"then grab your gun and bring the cat in"
};
var list = new Eina.List<string>();
var list = new eina.List<string>();
foreach (string s in more_strings)
list.Append(s);
@ -55,31 +55,24 @@ public class Example : Efl.Csharp.Application
return list;
}
protected override void OnInitialize(string[] args)
public static void Main()
{
// Create an Eina.Array and iterate through its contents
efl.All.Init();
// create an eina.Array and iterate through it's contents
var array = CreateArray();
var it = array.GetIterator();
PrintIterator(it);
it.Dispose();
array.Dispose();
// Perform the same iteration with an Eina.List
// perform the same iteration with an eina.List
var list = CreateList();
it = list.GetIterator();
PrintIterator(it);
it.Dispose();
list.Dispose();
Efl.App.AppMain.Quit(0);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch(Efl.Csharp.Components.Basic);
efl.All.Shutdown();
}
}

View File

@ -1,8 +1,8 @@
/*
* Eina.List examples.
* Eina List examples.
*
* These examples demonstrate how to work with Eina.List data and methods.
* These examples demonstrate how to work with eina_list data and methods.
* We create a simple list of names by appending strings to an empty list
* and then run various mutations and print each result.
*/
@ -10,11 +10,11 @@
using System;
using System.Linq;
public class Example : Efl.Csharp.Application
public class Example
{
static Eina.List<string> CreateList()
static eina.List<string> CreateList()
{
var list = new Eina.List<string>();
var list = new eina.List<string>();
list.Append("Adama");
list.Append("Baltar");
@ -23,17 +23,19 @@ public class Example : Efl.Csharp.Application
return list;
}
protected override void OnInitialize(string[] args)
public static void Main()
{
efl.All.Init();
var list = CreateList();
// Print our list with a simple foreach
// print our list with a simple foreach
Console.WriteLine("List size: {0}", list.Count());
Console.WriteLine("List content:");
foreach(string item in list)
Console.WriteLine(" {0}", item);
// Insert some more elements
// insert some more elements
list.Prepend("Cain");
// list.PrependRelative("Tigh", "Baltar"); // TODO: missing
@ -41,7 +43,7 @@ public class Example : Efl.Csharp.Application
foreach(string item in list)
Console.WriteLine(" {0}", item);
// Promote an item to the top of the list
// promote an item to the top of the list
// TODO: implement ?
// list.PromoteList(list.NthList(1));
// list.Remove("Cain");
@ -50,26 +52,20 @@ public class Example : Efl.Csharp.Application
// foreach(string item in list)
// Console.WriteLine(" {0}", item);
// We can sort the list with any callback
// we can sort the list with any callback
// list.Sort((string strA, string strB) => { return strA.Compare(strB); }); // TODO: FIXME custom sort
list.Sort();
Console.WriteLine("List content sorted:");
foreach(string item in list)
Console.WriteLine(" {0}", item);
// And foreach can be in reverse too
// and foreach can be in reverse too
Console.WriteLine("List content reverse sorted:");
foreach(string item in list.Reverse())
Console.WriteLine(" {0}", item);
list.Dispose();
Efl.App.AppMain.Quit(0);
}
public static void Main()
{
var example = new Example();
example.Launch(Efl.Csharp.Components.Basic);
efl.All.Shutdown();
}
}

View File

@ -1,6 +1,6 @@
/*
* Eina.Log examples.
* Efl Core Log examples.
*
* This demo shows how to log at various levels and to change what log is shown.
* You can also use a custom log printer in your app as shown in _log_custom.
@ -8,19 +8,19 @@
using System;
public class Example : Efl.Csharp.Application
public class Example
{
static double Divide(int num, int denom)
{
if (denom == 0)
Eina.Log.Critical("Attempt to divide by 0\n");
eina.Log.Critical("Attempt to divide by 0\n");
else
{
if (denom < 0)
Eina.Log.Warning("Possible undesirable effect, divide by negative number");
eina.Log.Warning("Possible undesirable effect, divide by negative number");
double ret = ((double) num / denom);
Eina.Log.Info($"{num} / {denom} = {ret}\n");
eina.Log.Info($"{num} / {denom} = {ret}\n");
return ret;
}
@ -39,31 +39,24 @@ public class Example : Efl.Csharp.Application
Console.WriteLine("Executing with default logging");
Divides();
Eina.Log.GlobalLevelSet(Eina.Log.Level.Warning);
Console.WriteLine("Executing with Warning level"); // Same as EINA_LOG_LEVEL = 2
eina.Log.GlobalLevelSet(eina.Log.Level.Warning);
Console.WriteLine("Executing with Warning level"); // same as EINA_LOG_LEVEL = 2
Divides();
Eina.Log.GlobalLevelSet(Eina.Log.Level.Info);
Console.WriteLine("Executing with Info on"); // Same as EINA_LOG_LEVEL = 3
eina.Log.GlobalLevelSet(eina.Log.Level.Info);
Console.WriteLine("Executing with Info on"); // same as EINA_LOG_LEVEL = 3
Divides();
}
protected override void OnInitialize(string[] args)
public static void Main()
{
efl.All.Init();
LogLevels();
// TODO: missing
//LogCustom();
Efl.App.AppMain.Quit(0);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch(Efl.Csharp.Components.Basic);
efl.All.Shutdown();
}
}

View File

@ -1,54 +1,81 @@
/*
* Eina.Value examples.
* Eina Value examples.
*
* These examples demonstrate how to work with Eina.Value data and methods.
* Eina.Value is a way to represent and pass data of varying types and to
* convert efficiently between them.
* Eina.Value can even define structs for managing more complex requirements.
* These examples demonstrate how to work with eina_value data and methods.
* Eina_Value is a way to represent and pass data of varying types and to
* convert efficiently between them..
* Eina_Value can even define structs for managing more complex requirements.
*/
using System;
public class Example : Efl.Csharp.Application
public class Example
{
static void ValueInt()
{
// Setting up an integer value type
Eina.Value int_val = 123;
Console.WriteLine("int_val value is {0}", int_val);
int i;
// It can easily be converted to a string
// Setting up an integer value type
var int_val = new eina.Value(eina.ValueType.Int32);
int_val.Set(123);
int_val.Get(out i);
Console.WriteLine("int_val value is {0}", i);
// It can easily be converted it to a string
string str = int_val.ToString();
Console.WriteLine("int_val to string is \"{0}\"", str);
int_val.Flush();
}
static void ValueString()
{
string str;
// Setting up an string value type
Eina.Value str_val = "My string";
Console.WriteLine("str_val value is \"{0}\"", str_val);
var str_val = new eina.Value(eina.ValueType.String);
str_val.Set("My string");
str_val.Get(out str);
Console.WriteLine("str_val value is \"{0}\"", str);
// To string should have the same content
string newstr = str_val.ToString();
Console.WriteLine("str_val to string is \"{0}\"", newstr);
str_val.Flush();
}
static void ValueConvert()
{
// Convert from int to string:
Eina.Value int_val = 123;
Eina.Value str_val = new Eina.Value(Eina.ValueType.String);
int_val.ConvertTo(str_val);
Console.WriteLine("int_val was {0}, converted to string is \"{1}\"", int_val, str_val);
// set up string and int types to convert between
var str_val = new eina.Value(eina.ValueType.String);
var int_val = new eina.Value(eina.ValueType.Int32);
// And the other way around!
str_val = "33.000";
// convert from int to string:
int i1;
string str1;
int_val.Set(123);
int_val.Get(out i1);
int_val.ConvertTo(str_val);
str_val.Get(out str1);
Console.WriteLine("int_val was {0}, converted to string is \"{1}\"", i1, str1);
// and the other way around!
int i2;
string str2;
str_val.Set("33");
str_val.Get(out str2);
str_val.ConvertTo(int_val);
Console.WriteLine("str_val was \"{0}\", converted to int is {1}", str_val, int_val);
int_val.Get(out i2);
Console.WriteLine("str_val was \"{0}\", converted to int is {1}", str2, i2);
str_val.Flush();
int_val.Flush();
}
protected override void OnInitialize(string[] args)
public static void Main()
{
efl.All.Init();
ValueInt();
Console.WriteLine("");
@ -58,15 +85,9 @@ public class Example : Efl.Csharp.Application
ValueConvert();
Console.WriteLine("");
Efl.App.AppMain.Quit(0);
}
// TODO: FIXME
// ValueStruct();
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch(Efl.Csharp.Components.Basic);
efl.All.Shutdown();
}
}

View File

@ -1,5 +1,5 @@
project(
'efl-reference-core', 'cs',
'efl-reference-net', 'c',
version : '0.0.1',
meson_version : '>= 0.38.0')

View File

@ -1,21 +1,21 @@
deps = [efl_mono]
executable('efl_reference_core_event',
files(['core_event.cs']),
executable('efl_reference_net_io',
files(['net_io.cs']),
dependencies : deps,
cs_args : efl_mono_libs,
install : true
)
executable('efl_reference_core_idler',
files(['core_idler.cs']),
executable('efl_reference_net_io_buffered',
files(['net_io_buffered.cs']),
dependencies : deps,
cs_args : efl_mono_libs,
install : true
)
executable('efl_reference_core_poll',
files(['core_poll.cs']),
executable('efl_reference_net_session',
files(['net_session.cs']),
dependencies : deps,
cs_args : efl_mono_libs,
install : true

View File

@ -0,0 +1,269 @@
/*
* Efl.Net input/output examples.
*
* This example builds on the core_io example by connecting to a remote server
* using a dialer and a command queue. The response is printed to stdout.
*/
using System;
public class ExampleRunner
{
private eina.List<efl.io.Copier> waiting = null;
private eina.List<string> commands = null;
private eina.Slice delimiter;
private efl.net.dialer.Tcp dialer = null;
private efl.io.Copier sender = null;
private efl.io.Copier receiver = null;
public void Run()
{
efl.ui.Config.Run();
}
// call this method to cleanly shut down our example
public void Quit()
{
if (waiting != null)
{
Console.Error.WriteLine("ERROR: {0} operations were waiting!", waiting.Length);
waiting.Dispose();
waiting = null;
}
if (receiver != null)
{
receiver.Close();
receiver.GetDestination().Dispose();
receiver.Dispose();
receiver = null;
}
if (sender)
{
sender.Close();
sender.GetSource().Dispose();
source.Dispose();
}
if (dialer)
dialer.Dispose();
// efl_exit(retval); // TODO missing
efl.ui.Config.Exit();
}
// iterate through the commands to send through the dialler
public void CommandNext()
{
efl.io.Reader send_queue = sender.GetSource();
if (commands != null)
{
send_queue.EosMark();
return;
}
string cmd = commands[0];
// commands.RemoveAt(0); // TODO missing
eina.Slice slice;
// slice = (Eina_Slice)EINA_SLICE_STR(cmd); // TODO missing
send_queue.Write(slice, null);
// Console.WriteLine("INFO: sent '{0}'", EINA_SLICE_STR_PRINT(slice)); // TODO missing
// don't use delimiter directly, 'Len' may be changed!
slice = delimiter;
send_queue.Write(slice, null);
}
void ReceiverData(efl.io.Queue sender, EventArgs e)
{
eina.Slice slice = sender.GetSlice();
// Can be caused when we issue efl.io.Queue.Clear()
if (slice.Len == 0) return;
// If the server didn't send us the line terminator and closed the
// connection (ie: efl_io_reader_eos_get() == true) or if the buffer
// limit was reached then we may have a line without a trailing delimiter.
// if (slice.EndsWith(delimiter)) // TODO missing
// slice.Len -= delimiter.Len;
// Console.WriteLine("INFO: received '{0}'", EINA_SLICE_STR_PRINT(slice)); // TODO missing
sender.Clear();
CommandNext();
}
void DialerConnected(efl.net.dialer.Tcp sender, EventArgs e)
{
Console.WriteLine("INFO: connected to {0} ({1})", sender.GetAddressDial(), sender.GetAddressRemote());
CommandNext();
}
void CopierDone(efl.io.Copier sender, EventArgs e)
{
Console.WriteLine("INFO: {0} done", sender.GetName());
// waiting.Remove(sender); // TODO missing
if (waiting.Empty())
Quit(EXIT_SUCCESS);
}
void CopierError(efl.io.Copier sender, eina.Error perr)
{
Console.Error.WriteLine(stderr, "INFO: {0} error: #{1} '{2}'", sender.GetName(), perr, perr.Message);
Quit(EXIT_FAILURE);
}
private static void SetCopierCbs(efl.io.Copier copier)
{
copier.DONE += CopierDone;
copier.ERROR += CopierError;
}
public ExampleRunner()
{
string address = "example.com:80";
ulong buffer_limit = 128;
efl.io.Queue send_queue, receive_queue;
commands = new eina.List<string>();
commands.Append("HEAD / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n");
// delimiter = (Eina_Slice)EINA_SLICE_STR("\r\n"); // TODO missing
// Without a send_queue we'd have to manually implement an
// efl.io.Reader object that would provide partial data when
// efl.io.Reader.read() is called by efl.io.Copier. This is
// cumbersome... we just want to write a full command and have the
// queue to handle that for us.
//
// Our example's usage is to write each command at once followed by
// the line delimiter, then wait for a reply from the server, then
// write another.
try
{
send_queue = new efl.io.QueueConcrete(null, (efl.io.Queue equeue) => {
equeue.SetName("send_queue");
equeue.SetLimit(buffer_limit);
});
}
catch
{
Console.Error.WriteLine("ERROR: could not create efl.io.Queue (send)");
Quit(EXIT_FAILURE);
throw;
}
// Without a receive_queue we'd have to manually implement an
// efl.io.Writer object that would handle write of partial data
// with efl.io.Writer.write() is called by efl.io.Copier.
//
// For output we could have another solution as well: use null
// destination and handle "line" or "data" events manually,
// stealing the buffer so it doesn't grow.
//
// Our example's usage is to peek its data with GetSlice() then
// Clear().
try
{
receive_queue = new efl.io.QueueConcrete(null, (efl.io.Queue equeue) => {
equeue.SetName("receive_queue");
equeue.SetLimit(buffer_limit);
});
receive_queue.SLICE_CHANGED += ReceiverData;
}
catch
{
Console.Error.WriteLine("ERROR: could not create efl.io.Queue (receive)");
Quit(EXIT_FAILURE);
throw;
}
// some objects such as the Efl.Io.Copier and Efl.Net.Dialer.Tcp
// depend on main loop, thus their parent must be a loop
// provider. We use the loop passed to our main method.
// efl.Loop loop = ev->object; // TODO missing
// The TCP client to use to send/receive network data
try
{
dialer = new efl.net.dialer.TcpConcrete(loop, (efl.net.dialer.Tcp edialer) => {
edialer.SetName("dialer");
});
dialer.CONNECTED += DialerConnected;
}
catch
{
Console.Error.WriteLine("ERROR: could not create efl.net.dialer.Tcp");
Quit(EXIT_FAILURE);
throw;
}
// sender: send_queue->network
try
{
sender = new efl.io.CopierConcrete(loop, (efl.io.Copier esender) => {
esender.SetName("sender");
esender.SetLineDelimiter(delimiter);
esender.SetSource(send_queue);
esender.SetDestination(dialer);
});
SetCopierCbs(sender);
}
catch
{
Console.Error.WriteLine("ERROR: could not create efl.io.Copier (sender)");
Quit(EXIT_FAILURE);
throw;
}
// receiver: network->receive_queue
try
{
receiver = new efl.io.CopierConcrete(loop, (efl.io.Copier ereceiver) => {
ereceiver.SetName("receiver");
ereceiver.SetLineDelimiter(delimiter);
ereceiver.SetSource(dialer);
ereceiver.SetDestination(send_queue);
});
SetCopierCbs(receiver);
}
catch
{
Console.Error.WriteLine("ERROR: could not create Efl_Io_Copier (receiver)");
Quit(EXIT_FAILURE);
throw;
}
eina.Error err = dialer.Dial(address);
if (err != eina.Error.NO_ERROR)
{
var msg = $"ERROR: could not dial {address}: {err.Message}";
Console.Error.WriteLine(msg);
Quit(EXIT_FAILURE);
throw new SEHException(msg);
}
waiting.Append(sender);
waiting.Append(receiver);
}
}
public static class Example
{
public static void Main()
{
efl.All.Init(efl.Components.Basic);
var exr = new ExampleRunner();
exr.Run();
efl.All.Shutdown();
}
}

View File

@ -0,0 +1,181 @@
/*
* Efl.Net buffered input/output examples.
*
* This example builds on the net_io example by using a buffered_stream to
* simplify the logic. This helpfully provides the input and output queues
* and a copier internally. They can be accessed from the buffered stream
* if required but as demonstrated here that is likely not necessary.
*/
using System;
public class ExampleRunner
{
private eina.List<string> commands = null;
private eina.Slice delimiter;
private efl.net.dialer.Tcp dialer = null;
private efl.io.buffered.Stream stream = null;
public void Run()
{
efl.ui.Config.Run();
}
public void Quit(int retval)
{
if (stream != null)
{
stream.Close();
stream.Dispose();
stream = null;
}
if (dialer != null)
{
dialer.Dispose();
dialer = null;
}
// efl_exit(retval); TODO missing
efl.ui.Config.Exit();
}
public void CommandNext()
{
if (commands.Empty())
{
stream.EosMark();
return;
}
string cmd = commands[0];
// commands.RemoveAt(0); // TODO missing
// eina.Slice slice = (Eina_Slice)EINA_SLICE_STR(cmd); // TODO missing
stream.Write(slice, null);
// Console.Error.WriteLine("INFO: sent '{0}'", EINA_SLICE_STR_PRINT(slice)); // TODO missing
// don't use delimiter directly, 'Len' may be changed!
slice = delimiter;
stream.Write(slice, null);
}
void StreamLine(efl.io.buffered.Stream sender, EventArgs e)
{
eina.Slice slice = sender.GetSlice();
// Can be caused when we issue efl.io.buffered.Stream.Clear()
if (slice.Len == 0) return;
// If the server didn't send us the line terminator and closed the
// connection (ie: efl_io_reader_eos_get() == true) or if the buffer
// limit was reached then we may have a line without a trailing delimiter.
// if (slice.EndsWith(delimiter)) // TODO missing
// slice.Len -= delimiter.Len;
// Console.WriteLine("INFO: received '{0}'", EINA_SLICE_STR_PRINT(slice)); // TODO missing
sender.Clear();
CommandNext();
}
void DialerConnected(efl.net.dialer.Tcp sender, EventArgs e)
{
Console.WriteLine("INFO: connected to {0} ({1})", sender.GetAddressDial(), sender.GetAddressRemote());
CommandNext();
}
void StreamDone(efl.io.buffered.Stream sender, EventArgs e)
{
Console.WriteLine("INFO: {0} done", sender.GetName());
Quit(EXIT_SUCCESS);
}
void StreamError(efl.io.buffered.Stream sender, eina.Error err)
{
Console.Error.WriteLine("INFO: {0} error: #{1} '{2}'", sender;GetName(), err, err.Message);
Quit(EXIT_FAILURE);
}
private static void SetStreamCbs(efl.io.buffered.Stream s)
{
s.LINE += StreamLine;
s.EOS += StreamDone;
s.ERROR += StreamError;
}
public ExampleRunner()
{
string address = "example.com:80";
ulong bufferLimit = 128;
commands = new eina.List<string>();
commands.Append("HEAD / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n");
// delimiter = (Eina_Slice)EINA_SLICE_STR("\r\n"); // TODO missing
// some objects such as the Efl.Io.Copier and Efl.Net.Dialer.Tcp
// depend on main loop, thus their parent must be a loop
// provider. We use the loop passed to our main method.
// efl.Loop loop = ev->object; // TODO missing
// The TCP client to use to send/receive network data
try
{
dialer = new efl.net.dialer.TcpConcrete(loop, (efl.net.dialer.Tcp edialer) => {
edialer.SetName("dialer");
});
dialer.CONNECTED += DialerConnected;
}
catch
{
Console.Error.WriteLine("ERROR: could not create efl.net.dialer.Tcp");
Quit(EXIT_FAILURE);
throw;
}
// Without the buffered stream we'd have to create two Efl.Io.Queue
// ourselves, as well as two Efl.Io.Copier to link them with the
// dialer.
//
// Our example's usage is to write each command at once followed by
// the line delimiter, then wait for a reply from the server, then
// write another.
//
// On incoming data we peek at it with GetSlice() and then Clear().
stream = new efl.io.buffered.StreamConcrete(loop, (efl.io.buffered.Stream estream) => {
estream.SetName("stream");
estream.SetInnerIo(dialer);
estream.SetDelimiter(delimiter);
estream.SetMaxQueueSizeInput(bufferLimit);
estream.SetMaxQueueSizeOutput(bufferLimit);
});
SetStreamCbs(stream);
eina.Error err = dialer.Dial(address);
if (err != eina.Error.NO_ERROR)
{
var msg = $"ERROR: could not dial {address}: {err.Message}";
Console.Error.WriteLine(msg);
Quit(EXIT_FAILURE);
throw new SEHException(msg);
}
}
}
public class Example
{
public static void Main()
{
efl.All.Init(efl.Components.Basic);
var exr = new ExampleRunner();
exr.Run();
efl.All.Shutdown();
}
}

View File

@ -0,0 +1,135 @@
/*
* Efl.Net session/connectivity examples.
*
* NOTE: This example currently requires the Connman backend to be running.
*
* This example uses the Efl.Net.Session APIs to get connectivity information
* about the current networking setup. It then sets up a callback for network
* changes and will print the details on any change.
*/
using System;
public class Example
{
// Convert a session state to a string for printing.
public static string StateName(efl.net.session.State state)
{
switch (state)
{
case efl.net.session.State.Offline:
return "offline";
case efl.net.session.State.Local:
return "local";
case efl.net.session.State.Online:
return "online";
default:
return "???";
}
}
private static readonly Dictionary<efl.net.session.Technology, string> names =
new Dictionary<efl.net.session.Technology, string> {
{ efl.net.session.Technology.Unknown, "unknown" },
{ efl.net.session.Technology.Ethernet, "ethernet" },
{ efl.net.session.Technology.Wifi, "wifi" },
{ efl.net.session.Technology.Bluetooth, "bluetooth" },
{ efl.net.session.Technology.Cellular, "cellular" },
{ efl.net.session.Technology.Vpn, "vpn" },
{ efl.net.session.Technology.Gadget, "gadget" }
};
// Convert a session technology to a string for printing.
public static string TechnologyName(efl.net.session.Technology tech)
{
string name;
if (!names.TryGetValue(tech, out name))
return "???";
return name;
}
// Tthe callback that indicates some connectivity changed within the session.
// Print information about the session to the console.
static void SessionChanged(efl.net.Session session, EventArgs e)
{
Console.WriteLine("Session changed:");
Console.WriteLine(" name: '{0}'", session.GetName());
Console.WriteLine(" state: {0}", StateName(session.GetState()));
Console.WriteLine(" technology: {0}", TechnologyName(session.GetTechnology()));
Console.WriteLine(" interface: '{0}'", session.GetInterface());
// print out additional information if we have an IPv4 session
string ip, netmask, gateway;
session.GetIpv4(out ip, out netmask, out gateway);
if (ip != null)
{
Console.WriteLine($" IPv4: {ip}, gateway={gateway}, netmask={netmask}");
}
// print out additional information if we have an IPv6 session
byte prefix;
session.GetIpv6(out ip, out prefix, out netmask, out gateway);
if (ip != null)
{
Console.WriteLine($" IPv6: {ip}/{prefix}, gateway={gateway}, netmask={netmask}");
}
}
// Quit the app after a timer tick.
static void QuitCb(object sender, EventArgs e)
{
// efl_exit(0); // TODO missing
efl.ui.Config.Exit();
}
public static void Main()
{
bool doConnect = true;
bool requireOnline = false;
efl.All.Init(efl.Components.Basic);
// efl.Loop loop = ev->object; // TODO missing
// create a session that watches specifically for ethernet, wifi and bluetooth
int technologies = efl.net.session.Technology.Ethernet |
efl.net.session.Technology.Wifi | efl.net.session.Technology.Bluetooth;
try
{
efl.net.Session session = new efl.net.SessionConcrete(loop, (efl.net.Session esession) => {
esession.SetName("Example Session");
// register the change callback for network state
esession.CHANGED += SessionChanged;
});
}
catch
{
eina.Log.Error("Could not create Efl.Net.Session object.\n");
// efl_exit(EXIT_FAILURE); // TODO missing
efl.ui.Config.Exit();
throw;
}
if (doConnect)
{
Console.WriteLine("Requesting a {0} connection.", requireOnline ? "online" : "local");
session.Connect(requireOnline, technologies);
}
Console.WriteLine("The session will remain active while this application runs.");
Console.WriteLine("Use ^C (Control + C) to close it");
// Wait for 10 seconds before exiting this example
new efl.loop.TimerConcrete(loop, (efl.loop.Timer etimer) => {
etimer.SetInterval(10.0);
etimer.TICK += QuitCb;
});
// start the main loop
efl.ui.Config.Run();
efl.All.Shutdown();
}
}

View File

@ -1,17 +0,0 @@
Efl.Ui.AlertPopup alertPopup = new Efl.Ui.AlertPopup(parent);
alertPopup.SetButton(Efl.Ui.AlertPopupButton.Positive, "Accept", null);
alertPopup.SetButton(Efl.Ui.AlertPopupButton.Negative, "Reject", null);
alertPopup.ButtonClickedEvent += (sender, args) =>
{
if (args.arg.Button_type.Equals(Efl.Ui.AlertPopupButton.Positive))
Console.WriteLine("Positive action invoked");
else if (args.arg.Button_type.Equals(Efl.Ui.AlertPopupButton.Negative))
Console.WriteLine("Negative action invoked");
};
alertPopup.BackwallClickedEvent += (s, e) =>
{
Console.WriteLine("Backwall clicked");
};

View File

@ -1,6 +0,0 @@
Efl.Ui.Bg bg = new Efl.Ui.Bg(parent);
bg.Color = (66, 162, 206, 255);
bg.SetFile(image_path + "background.png");
bg.Load();

View File

@ -1,10 +0,0 @@
Efl.Ui.Box box = new Efl.Ui.Box(parent);
//Creating content which we will pack into the box
//It can be any widget, for example, buttons
Efl.Ui.Button button1 = new Efl.Ui.Button(box);
Efl.Ui.Button button2 = new Efl.Ui.Button(box);
//Packing the content to the box, one after another
box.Pack(button1);
box.Pack(button2);

View File

@ -1,9 +0,0 @@
Efl.Ui.Button button = new Efl.Ui.Button(parent);
button.Text = "Test Button";
button.ClickedEvent += (sender, args) =>
{
Efl.Ui.Button btn = (Efl.Ui.Button)sender;
btn.Text = "Clicked";
};

View File

@ -1,12 +0,0 @@
Efl.Ui.Check check = new Efl.Ui.Check(parent);
check.Text = "Test Check";
check.SetSelected(true);
check.SelectedChangedEvent += (sender, args) =>
{
if (check.Selected)
Console.WriteLine("Check is selected");
else
Console.WriteLine("Check is not selected");
};

View File

@ -1,11 +0,0 @@
Efl.Ui.Datepicker datepicker = new Efl.Ui.Datepicker(parent);
datepicker.SetDateMin(2000, 1, 1);
datepicker.SetDateMax(2030, 1, 1);
datepicker.SetDate(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
datepicker.DateChangedEvent += (sender, args) =>
{
datepicker.GetDate(out int year, out int month, out int day);
Console.WriteLine("Date has been changed! Current date: " + year + "-" + month + "-" + day);
};

View File

@ -1,4 +0,0 @@
Efl.Ui.Image image = new Efl.Ui.Image(parent);
image.SetFile(image_path + "icon.png");
image.Load();

View File

@ -1,12 +0,0 @@
Efl.Ui.Popup popup = new Efl.Ui.Popup(parent);
Efl.Ui.Button button = new Efl.Ui.Button(parent);
button.Text = "Click to hide the popup";
button.ClickedEvent += (sender, args) =>
{
popup.SetVisible(false);
};
popup.SetContent(button);

View File

@ -1,11 +0,0 @@
Efl.Ui.Progressbar progressbar = new Efl.Ui.Progressbar(parent);
// You can choose the range limits according to your needs.
// It can be percentage, but it can be also different value (e.g. number of files to be copied)
progressbar.SetRangeLimits(0.0, 100.0);
// Setting initial progress value
progressbar.RangeValue = 0;
// When progress is made you should modify the RangeValue:
progressbar.RangeValue = 33;

View File

@ -1,14 +0,0 @@
Efl.Ui.RadioBox radioBox = new Efl.Ui.RadioBox(parent);
for (int i = 1; i <= 3; i++)
{
Efl.Ui.Radio radio = new Efl.Ui.Radio(radioBox);
radio.Text = "Choice no. " + i;
radio.SetStateValue(i);
radioBox.Pack(radio);
}
radioBox.ValueChangedEvent += (sender, args) =>
{
System.Console.WriteLine("RadioBox value changed! Current choice value: " + args.arg);
};

View File

@ -1,10 +0,0 @@
Efl.Ui.Scroller scroller = new Efl.Ui.Scroller(parent);
// Create a large image to put it inside the scroller
Efl.Ui.Image image = new Efl.Ui.Image(scroller);
image.HintSizeMin = new Eina.Size2D(1000, 1000);
image.SetFile(image_path + "image.png");
image.Load();
scroller.SetContent(image);

View File

@ -1,16 +0,0 @@
Efl.Ui.Slider slider = new Efl.Ui.Slider(parent);
slider.SetRangeLimits(0, 100);
slider.SetRangeValue(50);
// You get this event every time the slider moves
slider.ChangedEvent += (sender, args) =>
{
Console.WriteLine("Current slider value is: " + slider.GetRangeValue());
};
// You only get this event once the slider is stable
slider.SteadyEvent += (sender, args) =>
{
Console.WriteLine("STEADY slider value is: " + slider.GetRangeValue());
};

View File

@ -1,13 +0,0 @@
Efl.Ui.SpinButton spinButton = new Efl.Ui.SpinButton(parent);
spinButton.Orientation = Efl.Ui.LayoutOrientation.Vertical;
spinButton.SetRangeLimits(0, 100);
spinButton.SetRangeStep(2);
spinButton.SetRangeValue(50);
spinButton.ChangedEvent += (sender, args) =>
{
Efl.Ui.SpinButton spnBtn = (Efl.Ui.SpinButton)sender;
Console.WriteLine("Range value changed to: " + spnBtn.RangeValue);
};

View File

@ -1,10 +0,0 @@
Efl.Ui.Table table = new Efl.Ui.Table(parent);
table.SetTableSize(2, 2);
Efl.Ui.Button button1 = new Efl.Ui.Button(table);
Efl.Ui.Button button2 = new Efl.Ui.Button(table);
// The first column and row have indexes = 0.
table.PackTable(button1, 0, 0, 1, 1);
table.PackTable(button2, 1, 1, 1, 1);

View File

@ -1,3 +0,0 @@
var win = new Efl.Ui.Win(Efl.App.AppMain);
win.FocusHighlightEnabled = true;

View File

@ -1,8 +0,0 @@
var win = new Efl.Ui.Win(Efl.App.AppMain);
win.SetWinType(Efl.Ui.WinType.Basic);
win.Text = "Hello World";
win.Autohide = true;
win.VisibilityChangedEvent +=
(sender, args) => { };

View File

@ -1,9 +0,0 @@
Place code snippets in this folder.
If the file name matches a class name (like Efl.Ui.Win) or a property name (like Efl.Ui.Win.FocusHighlightEnabled)
the mono documentation generator (DocFX) will pick up the content of the file and embed it.
Two file formats are supported:
- Plain code (files with .cs extension): Code snippets are copied into the documentation inside <example> and <code>
tags.
- XML text (files with .xml extension): This allows including explanatory text besides the code snippets, but the file
must include the ESCAPED \<example\> and \<code\> tags. Escaping is accomplished by adding a backslash in front of
angle brackets. Quotes must be escaped too: \"

View File

@ -1,9 +0,0 @@
project(
'snippets', 'cs',
version : '0.0.1',
meson_version : '>= 0.38.0')
efl_mono = dependency('efl-mono', version : '>=1.20.99')
efl_mono_libs = efl_mono.get_pkgconfig_variable('mono_libs')

View File

@ -1,79 +0,0 @@
using System;
public class Example : Efl.Csharp.Application
{
public static void FocusChangedCb(object sender, EventArgs e)
{
Console.WriteLine($"Focus for object {((Efl.IText)sender).Text} changed to {((Efl.Ui.Widget)sender).Focus}");
}
protected override void OnInitialize(string[] args)
{
// Create a window and initialize it
var win = new Efl.Ui.Win(null, winType: Efl.Ui.WinType.Basic);
win.Text = "Focus example";
win.Autohide = true;
win.VisibilityChangedEvent += (object sender, Efl.Gfx.EntityVisibilityChangedEventArgs e) => {
// Exit the EFL main loop
if (e.Arg == false)
Efl.Ui.Config.Exit();
};
// Create the main box container
var vbox = new Efl.Ui.Box(win);
vbox.HintSizeMin = new Eina.Size2D(360, 240);
win.Content = vbox;
// Create some check boxes
Efl.Ui.Check first_checkbox = null;
for (int i = 0; i< 5; i++) {
var checkbox = new Efl.Ui.Check(vbox);
checkbox.Text = "Check " + i;
checkbox.HintFill = (false, false);
checkbox.HintAlign = ((Efl.Gfx.Align)0.5, (Efl.Gfx.Align)0.5);
checkbox.FocusChangedEvent += FocusChangedCb;
vbox.Pack(checkbox);
if (i == 0) first_checkbox = checkbox;
};
// Create an horizontal box to contain the two buttons
var hbox = new Efl.Ui.Box(vbox);
hbox.Orientation = Efl.Ui.LayoutOrientation.Horizontal;
vbox.Pack(hbox);
// Create a "Focus Mover" button
var button = new Efl.Ui.Button(hbox);
button.Text = "Focus mover";
button.FocusChangedEvent += FocusChangedCb;
button.ClickedEvent += (object sender, Efl.Input.ClickableClickedEventArgs e) => {
Console.WriteLine("Clicked Focus Mover");
// Manually transfer focus to the first check box
Efl.Ui.Focus.Util.Focus(first_checkbox);
};
hbox.Pack(button);
// Create a Quit button
button = new Efl.Ui.Button(hbox);
button.Text = "Quit";
button.FocusChangedEvent += FocusChangedCb;
button.ClickedEvent += (object sender, Efl.Input.ClickableClickedEventArgs e) => {
Console.WriteLine("Clicked Quit");
Efl.Ui.Config.Exit();
};
hbox.Pack(button);
// Show the focus highlight
win.FocusHighlightEnabled = true;
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
}
}

View File

@ -13,17 +13,3 @@ executable('efl_reference_ui_container',
cs_args : efl_mono_libs,
install : true
)
executable('efl_reference_ui_focus',
files(['focus_main.cs']),
dependencies : deps,
cs_args : efl_mono_libs,
install : true
)
executable('efl_reference_ui_custom_widget',
files(['ui_custom_widget.cs']),
dependencies : deps,
cs_args : efl_mono_libs,
install : true
)

View File

@ -1,30 +1,60 @@
/*
* Efl.UI container examples.
* Efl.UI container exmaples.
*
* Load and pack a selection of containers.
* Each has its own unique layout and methods which are demonstrated below.
* Each has it's own unique layout and methods which are demonstrated below.
*/
using System;
public class Example : Efl.Csharp.Application
public class Example
{
// Create a box container full of buttons
static Efl.Ui.Box CreateBox(Efl.Ui.Win win)
// quit the app, called if the user clicks the Quit button or the window is hidden
static void GuiQuitCb(object sender, EventArgs e)
{
Efl.Ui.Box box = new Efl.Ui.Box(win);
// Set distance between contained elements
box.ContentPadding = (5, 0);
efl.ui.Config.Exit();
}
// Load a simple table layout into the window
static efl.ui.Table SetupUiTable(efl.ui.Win win)
{
efl.ui.Table table = new efl.ui.TableConcrete(win);
table.SetTableColumns(2);
table.SetTableDirection(efl.ui.Dir.Right, efl.ui.Dir.Down);
efl.ui.Button button = new efl.ui.ButtonConcrete(win);
button.SetText("Long Button");
table.PackTable(button, 0, 2, 2, 1);
for (int i = 1; i <= 4; ++i)
{
// Add 4 buttons, one below the other
var button = new Efl.Ui.Button(win);
button.Text = $"Boxed {i}";
efl.ui.Button btn = new efl.ui.ButtonConcrete(win);
btn.SetText($"Table {i}");
table.Pack(btn);
}
return table;
}
// Load some boxes - a horizontal one for the window layout and a vertical
// one to contain a flow
static efl.ui.Box SetupUiBoxes(efl.ui.Win win)
{
efl.ui.Box box = new efl.ui.BoxConcrete(win);
box.SetPackPadding(5, 0, true);
for (int i = 1; i <= 4; ++i)
{
efl.ui.Button button = new efl.ui.ButtonConcrete(win);
button.SetText($"Boxed {i}");
if (i == 2)
{
// Button 2 has its maximum size limited, so it will be smaller
button.HintSizeMax = new Eina.Size2D(100,50);
eina.Size2D sz;
sz.W = 100;
sz.H = 50;
button.SetHintMax(sz);
}
box.Pack(button);
}
@ -32,86 +62,51 @@ public class Example : Efl.Csharp.Application
return box;
}
// Create a simple table layout
static Efl.Ui.Table CreateTable(Efl.Ui.Win win)
{
Efl.Ui.Table table = new Efl.Ui.Table(win);
// Table with two columns, that get filled left to right, and then top to bottom
table.TableColumns = 2;
table.Orientation = Efl.Ui.LayoutOrientation.Horizontal;
Efl.Ui.Button button;
for (int i = 1; i <= 4; ++i)
{
// Add 4 buttons, following the defined table flow
button = new Efl.Ui.Button(win);
button.Text = $"Table {i}";
table.Pack(button);
}
// Last button spans two table cells
button = new Efl.Ui.Button(win);
button.Text = "Long Button";
table.PackTable(button, 0, 2, 2, 1);
return table;
}
protected override void OnInitialize(string[] args)
{
// Create a window and initialize it
Efl.Ui.Win win = new Efl.Ui.Win(null, winType: Efl.Ui.WinType.Basic);
win.Text = "Container demo";
win.Autohide = true;
win.VisibilityChangedEvent += (object sender, Efl.Gfx.EntityVisibilityChangedEventArgs e) => {
// Exit the EFL main loop
if (e.Arg == false)
Efl.Ui.Config.Exit();
};
// Give the window an initial size so there is room to resize the panes.
// Otherwise, all widgets are tightly packed
win.Size = new Eina.Size2D(350,250);
// Create a vertically-split panes container
Efl.Ui.Panes vsplit = new Efl.Ui.Panes(win);
vsplit.SplitRatio = 0.75;
win.Content = vsplit;
// Create some boxes and set them as the content of the first pane of the container
var box = CreateBox(win);
vsplit.FirstPart.Content = box;
// Create a second, horizontally-split panes container and set it as the content of
// the second pane of the first container
Efl.Ui.Panes hsplit = new Efl.Ui.Panes(win);
hsplit.Orientation = Efl.Ui.LayoutOrientation.Horizontal;
hsplit.SplitRatio = 0.85;
vsplit.SecondPart.SetContent(hsplit);
// Create a table and set it as the content of the first pane of the horizontal
// container
var table = CreateTable(win);
hsplit.FirstPart.SetContent(table);
// Create a button and set it as the content of the second pane of the horizontal
// container
Efl.Ui.Button quit_btn = new Efl.Ui.Button(win);
quit_btn.Text = "Quit";
quit_btn.HintSizeMax = new Eina.Size2D(150, 30);
quit_btn.ClickedEvent += (object sender, Efl.Input.ClickableClickedEventArgs e) => {
// Exit the EFL main loop
Efl.Ui.Config.Exit();
};
hsplit.SecondPart.SetContent(quit_btn);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
efl.All.Init(efl.Components.Ui);
efl.ui.Win win = new efl.ui.WinConcrete(null, (efl.ui.Win ewin) => {
ewin.SetWinType(efl.ui.win.Type.Basic);
ewin.SetText("Hello World");
ewin.SetAutohide(true);
});
eina.Size2D sz;
sz.W = 350;
sz.H = 250;
win.SetSize(sz);
// when the user clicks "close" on a window there is a request to hide
win.HIDE += GuiQuitCb;
// Load a vertical and horizontal split into the window
efl.ui.Panes split = new efl.ui.PanesConcrete(win);
split.SetSplitRatio(0.75);
win.SetContent(split);
var boxes = SetupUiBoxes(win);
efl.ContentConcrete.static_cast(split.Part("first")).SetContent(boxes);
efl.ui.Panes horiz_split = new efl.ui.PanesConcrete(win);
horiz_split.SetDirection(efl.ui.Dir.Horizontal);
horiz_split.SetSplitRatio(0.85);
efl.ContentConcrete.static_cast(split.Part("second")).SetContent(horiz_split);
var table = SetupUiTable(win);
efl.ContentConcrete.static_cast(horiz_split.Part("first")).SetContent(table);
efl.ui.Button quit_btn = new efl.ui.ButtonConcrete(win);
quit_btn.SetText("Quit");
sz.W = 150;
sz.H = 30;
quit_btn.SetHintMax(sz);
quit_btn.CLICKED += GuiQuitCb;
efl.ContentConcrete.static_cast(horiz_split.Part("second")).SetContent(quit_btn);
// Start event loop
efl.ui.Config.Run();
efl.All.Shutdown();
}
}

View File

@ -1,64 +0,0 @@
/*
* Efl.UI custom widget examples.
*
* Inherit from an EFL C# class and customize it
*/
using System;
// This is our own button with customized text functions
public class MyButton : Efl.Ui.Button
{
// This id shows how our data is preserved when overriden methods
// are called from native code
private int button_id;
// Constructor sets an initial text
public MyButton(Efl.Object parent, int id = 0) :
base(parent)
{
button_id = id;
base.Text = "Base text for button id " + id;
}
// This calls the parent's SetText() method with a modified string
public override string Text
{
set {
base.Text = "Overriden text for button id " + button_id + ": " + value;
}
}
}
public class Example : Efl.Csharp.Application
{
protected override void OnInitialize(string[] args)
{
// Create a window and initialize it
Efl.Ui.Win win = new Efl.Ui.Win(null, winType: Efl.Ui.WinType.Basic);
win.Text = "Custom widget demo";
win.Autohide = true;
win.VisibilityChangedEvent += (object sender, Efl.Gfx.EntityVisibilityChangedEventArgs e) => {
// Exit the EFL main loop when the window is closed
if (e.Arg == false)
Efl.Ui.Config.Exit();
};
// Give the window an initial size
win.Size = new Eina.Size2D(350,250);
// Instantiate our custom button widget
MyButton btn = new MyButton(win, 99);
btn.ClickedEvent += (object sender, Efl.Input.ClickableClickedEventArgs e) => {
// When the button is clicked, change its text
MyButton b = (MyButton)sender;
b.Text = "Hello!";
};
win.SetContent(btn);
}
public static void Main()
{
var example = new Example();
example.Launch();
}
}

View File

@ -2,55 +2,58 @@
* Efl.UI sizing examples.
*
* Demonstrate how to use the sizing api from Efl.Gfx.
* We load a box with 3 buttons, one with default sizing, one that has a max size
* and the last one has a min size. Try resizing the window to see how this changes.
* We load a box with 3 buttons, one with default sizing, one that has a max
* and the last has a min size. Try resizing the window to see how this changes.
*/
using System;
public class Example : Efl.Csharp.Application
public class Example
{
protected override void OnInitialize(string[] args)
{
// Create a window and initialize it
Efl.Ui.Win win = new Efl.Ui.Win(null, winType: Efl.Ui.WinType.Basic);
win.Text = "Size Control";
win.Autohide = true;
win.VisibilityChangedEvent += (object sender, Efl.Gfx.EntityVisibilityChangedEventArgs e) => {
// Exit the EFL main loop
if (e.Arg == false)
Efl.Ui.Config.Exit();
};
// Create a box container
Efl.Ui.Box box = new Efl.Ui.Box(win);
win.SetContent(box);
// Create a regular button (without size hints)
var button = new Efl.Ui.Button(win);
button.Text = "Button";
box.Pack(button);
// Create a small button (max size is limited)
button = new Efl.Ui.Button(win);
button.Text = "Small";
button.HintSizeMax = new Eina.Size2D(50,50);
box.Pack(button);
// Create a big button (min size is limited)
button = new Efl.Ui.Button(win);
button.Text = "Big button";
button.HintSizeMin = new Eina.Size2D(100,100);
box.Pack(button);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
efl.All.Init(efl.Components.Ui);
efl.ui.Win win = new efl.ui.WinConcrete(null, (efl.ui.Win ewin) => {
ewin.SetWinType(efl.ui.win.Type.Basic);
ewin.SetText("Size Control");
ewin.SetAutohide(true);
});
eina.Size2D sz;
sz.W = 320;
sz.H = 320;
win.SetSize(sz);
// when the user clicks "close" on a window there is a request to hide
win.HIDE += (object sender, EventArgs e) => {
// quit the app, called if the window is hidden
efl.ui.Config.Exit();
};
efl.ui.Box box = new efl.ui.BoxConcrete(win);
win.SetContent(box);
efl.ui.Button button = new efl.ui.ButtonConcrete(win);
button.SetText("Button");
box.Pack(button);
efl.ui.Button small_btn = new efl.ui.ButtonConcrete(win);
small_btn.SetText("Small");
sz.W = 50;
sz.H = 50;
small_btn.SetHintMax(sz);
box.Pack(small_btn);
efl.ui.Button big_btn = new efl.ui.ButtonConcrete(win);
big_btn.SetText("Big Button");
sz.W = 100;
sz.H = 100;
big_btn.SetHintMin(sz);
box.Pack(big_btn);
efl.ui.Config.Run();
efl.All.Shutdown();
}
}

View File

@ -1,69 +0,0 @@
#!/usr/bin/python3
import os
import subprocess
from string import Template
supported_languages = ["c"]
directories = ["apps", "reference", "tutorial"] # "examples", "legacy-examples"
goals = []
subprojects = []
if subprocess.call("pkg-config --exists efl-mono", shell=True) == 0:
supported_languages += ["csharp"]
else:
print("Disable c# bindings")
if subprocess.call("pkg-config --exists eina-cxx", shell=True) == 0:
supported_languages += ["cxx"]
else:
print("Disable c++ bindings")
class SubProjectGoal:
def __init__(self, language, path):
self.language = language
self.path = path
def verify(self):
assert os.path.isdir(self.path)
assert os.path.isfile(os.path.join(self.path, 'meson.build'))
def flush(self):
os.symlink(os.path.join('..', self.path), os.path.realpath(os.path.join('subprojects', self.link_file_name())))
def link_file_name(self):
return self.language+'-'+os.path.basename(self.path)
for directory in directories:
for lang in supported_languages:
explore_dir = os.path.join(directory, lang)
if os.path.isdir(explore_dir):
meson_build_file = os.path.join(explore_dir, "meson.build")
if os.path.isfile(meson_build_file):
goals.append(SubProjectGoal(lang, explore_dir))
else:
for content in os.listdir(explore_dir):
sub = os.path.join(explore_dir, content)
if os.path.isdir(sub):
goals.append(SubProjectGoal(lang, sub))
if not os.path.isdir('./subprojects'):
os.mkdir('./subprojects')
else:
for content in os.listdir('./subprojects'):
os.unlink(os.path.join('subprojects', content))
for subproject in goals:
subproject.verify()
subproject.flush()
subprojects.append(subproject.link_file_name())
content = { 'subprojects' : '[\''+'\',\''.join(subprojects)+'\']'}
meson_in = open('meson.build.in')
meson_temp = Template(meson_in.read())
content = meson_temp.substitute(content)
if os.path.isfile('meson.build'):
os.unlink('meson.build')
meson_out = open('meson.build', 'a')
meson_out.write(content)

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Eina.h>

View File

@ -1,4 +1,4 @@
class Example.Rectangle extends Efl.Object {
class Example.Rectangle (Efl.Object) {
methods {
@property width {
set {

View File

@ -8,7 +8,7 @@ foreach eo : eo_src
eo_file = eo + '.eo'
eo_csrc += eo + '.c'
eo_gen += custom_target('eolian_gen_eo_classes' + eo_file,
eo_gen += custom_target('eolian_gen_' + eo_file,
input : eo_file,
output : [eo_file + '.h'],
command : [eolian_gen, '-I', meson.current_source_dir(),

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Eina.h>

View File

@ -1,8 +1,5 @@
class Example.Rectangle extends Efl.Object {
[[A rectangle shape object
@since 1.00
]]
class Example.Rectangle (Efl.Object) {
[[A rectangle shape object]]
methods {
@property width {
[[The width of this rectangle]]

View File

@ -1,8 +1,5 @@
class Example.Square extends Example.Rectangle {
[[A square shape object
@since 1.00
]]
class Example.Square (Example.Rectangle) {
[[A square shape object]]
implements {
Example.Rectangle.width {set;}
Example.Rectangle.height {set;}

View File

@ -8,7 +8,7 @@ foreach eo : eo_src
eo_file = eo + '.eo'
eo_csrc += eo + '.c'
eo_gen += custom_target('eolian_gen_eo_inherit' + eo_file,
eo_gen += custom_target('eolian_gen_' + eo_file,
input : eo_file,
output : [eo_file + '.h'],
command : [eolian_gen, '-I', meson.current_source_dir(),

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Eina.h>
@ -12,15 +13,15 @@ static void
_obj_create()
{
// First create a root element
_root = efl_new(EFL_GENERIC_MODEL_CLASS,
_root = efl_new(EFL_MODEL_ITEM_CLASS,
efl_name_set(efl_added, "Root"));
// Create the first child element
_child1 = efl_add(EFL_GENERIC_MODEL_CLASS, _root,
_child1 = efl_add(EFL_MODEL_ITEM_CLASS, _root,
efl_name_set(efl_added, "Child1"));
// Create the second child element, this time, with an extra reference
_child2 = efl_add_ref(EFL_GENERIC_MODEL_CLASS, _root,
_child2 = efl_add_ref(EFL_MODEL_ITEM_CLASS, _root,
efl_name_set(efl_added, "Child2"));
}

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Eina.h>

View File

@ -1,8 +1,5 @@
class Example.Circle extends Efl.Object implements Example.Shape {
[[A circle shape object
@since 1.00
]]
class Example.Circle (Efl.Object, Example.Shape) {
[[A circle shape object]]
methods {
@property radius {
[[The radius of this circle]]

View File

@ -1,8 +1,5 @@
mixin Example.Colored {
[[A mixin for providing APIs for managing colour properties
@since 1.00
]]
[[A mixin for providing APIs for managing colour properties]]
methods {
@property color {
[[The colour to associate with the class we are coloring.

View File

@ -1,8 +1,5 @@
class Example.Rectangle extends Efl.Object implements Example.Shape, Example.Colored {
[[A rectangle shape object
@since 1.00
]]
class Example.Rectangle (Efl.Object, Example.Shape, Example.Colored) {
[[A rectangle shape object]]
methods {
@property width {
[[The width of this rectangle]]

View File

@ -1,8 +1,5 @@
interface Example.Shape {
[[A generic shape object
@since 1.00
]]
[[A generic shape object]]
methods {
area {
[[Calculate the area of the shape.]]

View File

@ -1,8 +1,5 @@
class Example.Square extends Example.Rectangle {
[[A square shape object
@since 1.00
]]
class Example.Square (Example.Rectangle) {
[[A square shape object]]
implements {
Example.Rectangle.width {set;}
Example.Rectangle.height {set;}

View File

@ -9,7 +9,7 @@ foreach eo : eo_src
eo_file = eo + '.eo'
eo_csrc += eo + '.c'
eo_gen += custom_target('eolian_gen_eo_multiinherit' + eo_file,
eo_gen += custom_target('eolian_gen_' + eo_file,
input : eo_file,
output : [eo_file + '.h'],
command : [eolian_gen, '-I', meson.current_source_dir(),

View File

@ -1,3 +1,4 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Eina.h>
@ -51,7 +52,7 @@ static void
_obj_create()
{
// First create a root element
_root = efl_new(EFL_GENERIC_MODEL_CLASS,
_root = efl_new(EFL_MODEL_ITEM_CLASS,
efl_name_set(efl_added, "Root"));
// Add a weak reference so we can keep track of its state
efl_wref_add(_root, &_root_ref);
@ -59,7 +60,7 @@ _obj_create()
efl_event_callback_add(_root, EFL_EVENT_DEL, _obj_del_cb, NULL);
// Create the first child element
_child1 = efl_add(EFL_GENERIC_MODEL_CLASS, _root,
_child1 = efl_add(EFL_MODEL_ITEM_CLASS, _root,
efl_name_set(efl_added, "Child1"));
// Add a weak reference so we can keep track of its state
efl_wref_add(_child1, &_child1_ref);
@ -67,7 +68,7 @@ _obj_create()
efl_event_callback_add(_child1, EFL_EVENT_DEL, _obj_del_cb, NULL);
// Create the second child element, this time, with an extra reference
_child2 = efl_add_ref(EFL_GENERIC_MODEL_CLASS, _root,
_child2 = efl_add_ref(EFL_MODEL_ITEM_CLASS, _root,
efl_name_set(efl_added, "Child2"));
// Add a weak reference so we can keep track of its state
efl_wref_add(_child2, &_child2_ref);

View File

@ -1,5 +1,5 @@
project(
'efl-example-homescreen', 'c',
'efl-example-focus', 'c',
version : '0.0.1',
default_options: [ 'c_std=gnu99', 'warning_level=2' ],
meson_version : '>= 0.38.0')

View File

@ -1,5 +1,7 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Eina.h>
#include <Elementary.h>
#include <Efl_Ui.h>
@ -29,7 +31,7 @@ _gui_setup()
Eo *win, *box, *hbox, *about;
win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_BASIC),
efl_text_set(efl_added, "Hello World"),
efl_event_callback_add(efl_added,
EFL_UI_WIN_EVENT_DELETE_REQUEST,
@ -38,9 +40,9 @@ _gui_setup()
box = efl_add(EFL_UI_BOX_CLASS, win,
efl_content_set(win, efl_added),
efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(360, 240)));
efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(360, 240)));
efl_add(EFL_UI_TEXTBOX_CLASS, box,
efl_add(EFL_UI_TEXT_CLASS, box,
efl_text_set(efl_added, "Label"),
efl_text_interactive_editable_set(efl_added, EINA_FALSE),
efl_event_callback_add(efl_added, EFL_UI_FOCUS_OBJECT_EVENT_FOCUS_CHANGED,
@ -48,8 +50,8 @@ _gui_setup()
efl_pack(box, efl_added));
hbox = efl_add(EFL_UI_BOX_CLASS, box,
efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
efl_gfx_hint_weight_set(efl_added, 1.0, 0.1),
efl_ui_direction_set(efl_added, EFL_UI_DIR_HORIZONTAL),
efl_gfx_size_hint_weight_set(efl_added, 1.0, 0.1),
efl_pack(box, efl_added));
about = efl_add(EFL_UI_BUTTON_CLASS, hbox,
@ -57,7 +59,7 @@ _gui_setup()
efl_pack(hbox, efl_added),
efl_event_callback_add(efl_added, EFL_UI_FOCUS_OBJECT_EVENT_FOCUS_CHANGED,
_focus_changed, NULL),
efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED,
efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED,
_gui_about_clicked_cb, efl_added));
efl_add(EFL_UI_BUTTON_CLASS, hbox,
@ -65,10 +67,10 @@ _gui_setup()
efl_pack(hbox, efl_added),
efl_event_callback_add(efl_added, EFL_UI_FOCUS_OBJECT_EVENT_FOCUS_CHANGED,
_focus_changed, NULL),
efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED,
efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED,
_gui_quit_clicked_cb, efl_added));
efl_ui_focus_util_focus(about);
efl_ui_focus_util_focus(EFL_UI_FOCUS_UTIL_CLASS, about);
}
EAPI_MAIN void

View File

@ -1,10 +1,10 @@
src = files([
'calculator.c',
'focus_main.c',
])
deps = [eina, efl, elm]
executable('efl_example_calculator', src,
executable('efl_example_focus', src,
dependencies : deps,
include_directories : inc,
install : true

Some files were not shown because too many files have changed in this diff Show More