forked from enlightenment/efl
Add an initial stab at an elm_code widget. It currently does not refresh at any time other than load or resize, so is not respecting content updates, but it's a start.
Use it in place of the list of elm_label objects that were rendered in the log panel. Not colour highlighted yet, but one thing at a time.
This commit is contained in:
parent
7ed960fc52
commit
80373debf7
|
@ -5,7 +5,9 @@
|
|||
|
||||
#include <Eina.h>
|
||||
|
||||
#include <elm_code_common.h>
|
||||
#include <elm_code_file.h>
|
||||
#include <elm_code_widget.h>
|
||||
|
||||
#ifdef EAPI
|
||||
# undef EAPI
|
||||
|
@ -42,13 +44,6 @@ extern "C" {
|
|||
* @brief These routines are used for loading Elm Code widgets.
|
||||
*/
|
||||
|
||||
typedef struct _Elm_Code
|
||||
{
|
||||
Elm_Code_File *file;
|
||||
Eina_List *widgets;
|
||||
|
||||
} Elm_Code;
|
||||
|
||||
/**
|
||||
* @brief Init / shutdown functions.
|
||||
* @defgroup Init Init / Shutdown
|
||||
|
|
|
@ -12,11 +12,13 @@ lib_LTLIBRARIES = libelm_code.la
|
|||
|
||||
includes_HEADERS = \
|
||||
elm_code_file.h \
|
||||
elm_code_widget.h \
|
||||
Elm_Code.h
|
||||
includesdir = $(includedir)/edi-@VMAJ@
|
||||
|
||||
libelm_code_la_SOURCES = \
|
||||
elm_code_file.c \
|
||||
elm_code_widget.c \
|
||||
elm_code.c
|
||||
libelm_code_la_LIBADD = @EFL_LIBS@ -lm
|
||||
libelm_code_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef ELM_CODE_COMMON_H_
|
||||
# define ELM_CODE_COMMON_H_
|
||||
|
||||
#include <Eina.h>
|
||||
|
||||
#include "elm_code_file.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Common data structures and constants.
|
||||
*/
|
||||
|
||||
typedef struct _Elm_Code
|
||||
{
|
||||
Elm_Code_File *file;
|
||||
Eina_List *widgets;
|
||||
} Elm_Code;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ELM_CODE_COMMON_H_ */
|
|
@ -124,6 +124,10 @@ EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, int number)
|
|||
{
|
||||
Elm_Code_Line *line;
|
||||
|
||||
line = eina_list_nth(file->lines, number);
|
||||
line = eina_list_nth(file->lines, number - 1);
|
||||
printf("N %d\n", number);
|
||||
|
||||
if (!line)
|
||||
return NULL;
|
||||
return line->content;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
#ifdef HAVE_CONFIG
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <Elementary.h>
|
||||
|
||||
#include "elm_code_widget.h"
|
||||
|
||||
#include "elm_code_private.h"
|
||||
|
||||
EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code)
|
||||
{
|
||||
Evas_Textgrid_Cell *cells;
|
||||
const char *line, *chr;
|
||||
unsigned int length;
|
||||
int w, h, cw, ch;
|
||||
unsigned int x, y;
|
||||
|
||||
evas_object_geometry_get(o, NULL, NULL, &w, &h);
|
||||
evas_object_textgrid_cell_size_get(o, &cw, &ch);
|
||||
evas_object_textgrid_size_set(o, ceil(((double) w) / cw),
|
||||
ceil(((double) h) / ch));
|
||||
evas_object_textgrid_size_get(o, &w, &h);
|
||||
|
||||
for (y = 1; y <= elm_code_file_lines_get(code->file); y++)
|
||||
{
|
||||
line = elm_code_file_line_content_get(code->file, y);
|
||||
chr = line;
|
||||
|
||||
cells = evas_object_textgrid_cellrow_get(o, y - 1);
|
||||
length = strlen(line);
|
||||
|
||||
for (x = 0; x < (unsigned int) w && x < length; x++)
|
||||
{
|
||||
cells[x].codepoint = *chr;
|
||||
cells[x].bg = 0;
|
||||
cells[x].fg = 1;
|
||||
|
||||
chr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_elm_code_widget_resize_cb(void *data, EINA_UNUSED Evas *e, Evas_Object *obj,
|
||||
EINA_UNUSED void *event_info)
|
||||
{
|
||||
Elm_Code *code;
|
||||
|
||||
code = (Elm_Code *)data;
|
||||
elm_code_widget_fill(obj, code);
|
||||
}
|
||||
|
||||
EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code)
|
||||
{
|
||||
Evas_Object *o;
|
||||
|
||||
o = evas_object_textgrid_add(parent);
|
||||
|
||||
evas_object_textgrid_font_set(o, "Mono", 10 * elm_config_scale_get());
|
||||
|
||||
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, 0,
|
||||
54, 54, 54, 255);
|
||||
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, 1,
|
||||
205, 205, 205, 255);
|
||||
|
||||
evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code);
|
||||
return o;
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef ELM_CODE_WIDGET_H_
|
||||
# define ELM_CODE_WIDGET_H_
|
||||
|
||||
#include <Eina.h>
|
||||
#include <Evas.h>
|
||||
#include "elm_code_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief These routines are used for rendering instances of Elm Code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief UI Loading functions.
|
||||
* @defgroup Init Creating a widget to render an Elm Code backend
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* Functions for UI loading.
|
||||
*
|
||||
*/
|
||||
|
||||
EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code);
|
||||
EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ELM_CODE_WIDGET_H_ */
|
|
@ -50,8 +50,8 @@ START_TEST (elm_code_file_load_content)
|
|||
|
||||
file = elm_code_file_open(path);
|
||||
|
||||
ck_assert_str_eq("line2", elm_code_file_line_content_get(file, 2 - 1));
|
||||
ck_assert_str_eq("another line", elm_code_file_line_content_get(file, 4 - 1));
|
||||
ck_assert_str_eq("line2", elm_code_file_line_content_get(file, 2));
|
||||
ck_assert_str_eq("another line", elm_code_file_line_content_get(file, 4));
|
||||
elm_code_file_close(file);
|
||||
}
|
||||
END_TEST
|
||||
|
|
Loading…
Reference in New Issue