elm_code: support setting custom fonts

For EDI create the config that would allow this to be altered.
Actual setting widget to follow...
This commit is contained in:
Andy Williams 2015-05-24 18:39:57 +01:00
parent b68312de33
commit f4c48d4ca9
12 changed files with 55 additions and 34 deletions

View File

@ -71,7 +71,7 @@ _elm_code_test_welcome_setup(Evas_Object *parent)
widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
elm_code_widget_code_set(code));
eo_do(widget,
elm_code_widget_font_size_set(12),
elm_code_widget_font_set(NULL, 12),
eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL);
eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code));
@ -101,7 +101,7 @@ _elm_code_test_editor_setup(Evas_Object *parent)
widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
elm_code_widget_code_set(code));
eo_do(widget,
elm_code_widget_font_size_set(14),
elm_code_widget_font_set(NULL, 14),
elm_code_widget_editable_set(EINA_TRUE),
elm_code_widget_show_whitespace_set(EINA_TRUE),
elm_code_widget_line_numbers_set(EINA_TRUE));
@ -123,14 +123,14 @@ _elm_code_test_editor_setup(Evas_Object *parent)
}
static Evas_Object *
_elm_code_test_mirror_setup(Elm_Code *code, Evas_Object *parent)
_elm_code_test_mirror_setup(Elm_Code *code, char *font_name, Evas_Object *parent)
{
Elm_Code_Widget *widget;
widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
elm_code_widget_code_set(code));
eo_do(widget,
elm_code_widget_font_size_set(11),
elm_code_widget_font_set(font_name, 11),
elm_code_widget_line_numbers_set(EINA_TRUE));
evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@ -212,8 +212,8 @@ _elm_code_test_welcome_mirror_cb(void *data, Evas_Object *obj EINA_UNUSED, void
code = elm_code_widget_code_get());
elm_box_pack_end(screen, widget);
elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, screen));
elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, screen));
elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, "Mono:style=Oblique", screen));
elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, "Nimbus Mono", screen));
evas_object_show(screen);
elm_naviframe_item_push(naviframe, "Mirrored editor",

View File

@ -121,13 +121,13 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code)
}
EAPI void
elm_code_diff_widget_font_size_set(Evas_Object *widget, int size)
elm_code_diff_widget_font_set(Evas_Object *widget, char *name, int size)
{
Elm_Code_Widget *child;
child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_LEFT);
eo_do(child, elm_code_widget_font_size_set(size));
eo_do(child, elm_code_widget_font_set(name, size));
child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_RIGHT);
eo_do(child, elm_code_widget_font_size_set(size));
eo_do(child, elm_code_widget_font_set(name, size));
}

View File

@ -23,7 +23,7 @@ extern "C" {
EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code);
EAPI void elm_code_diff_widget_font_size_set(Evas_Object *widget, int size);
EAPI void elm_code_diff_widget_font_set(Evas_Object *widget, char *name, int size);
/**
* @}

View File

@ -1277,16 +1277,28 @@ _elm_code_widget_lines_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd
}
EOLIAN static void
_elm_code_widget_font_size_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Evas_Font_Size font_size)
_elm_code_widget_font_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, char *name,
Evas_Font_Size size)
{
evas_object_textgrid_font_set(pd->grid, "Mono", font_size * elm_config_scale_get());
pd->font_size = font_size;
char *face = name;
if (!face)
face = "Mono";
evas_object_textgrid_font_set(pd->grid, face, size * elm_config_scale_get());
if (pd->font_name)
free((char *)pd->font_name);
pd->font_name = strdup(face);
pd->font_size = size;
}
EOLIAN static Evas_Font_Size
_elm_code_widget_font_size_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
EOLIAN static void
_elm_code_widget_font_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, char **name,
Evas_Font_Size *size)
{
return pd->font_size;
if (name)
*name = strdup((const char *)pd->font_name);
if (size)
*size = pd->font_size;
}
EOLIAN static void
@ -1517,7 +1529,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd)
eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj),
eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_cb, obj));
_elm_code_widget_font_size_set(obj, pd, 10);
_elm_code_widget_font_set(obj, pd, NULL, 10);
}
#include "elm_code_widget_text.c"

View File

@ -21,21 +21,24 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text)
code: Elm_Code *; /*@ Our underlying Elm_Code object */
}
}
@property font_size {
@property font {
set {
/*@
Set the font size that this widget uses, the font will always be a system monospaced font
Set the font that this widget uses, the font should be a monospaced scalable font.
Passing NULL will load the default system monospaced font.
@ingroup Style */
}
get {
/*@
Get the font size currently in use
Get the font currently in use.
The font name is a copy ad should be freed once it is no longer needed
@ingroup Style */
}
values {
font_size: Evas_Font_Size; /*@ The font size of the widgget */
name: char *; /*@ The name of the font to load */
size: Evas_Font_Size; /*@ The font size for the widget */
}
}
@property gravity {

View File

@ -15,6 +15,7 @@ typedef struct
Elm_Code *code;
Evas_Object *grid, *scroller;
const char *font_name;
Evas_Font_Size font_size;
double gravity_x, gravity_y;

View File

@ -38,7 +38,7 @@
# define EDI_CONFIG_FILE_VERSION \
((EDI_CONFIG_FILE_EPOCH << 16) | EDI_CONFIG_FILE_GENERATION)
# define EDI_PROJECT_CONFIG_FILE_EPOCH 0x0001
# define EDI_PROJECT_CONFIG_FILE_EPOCH 0x0002
# define EDI_PROJECT_CONFIG_FILE_GENERATION 0x0001
# define EDI_PROJECT_CONFIG_FILE_VERSION \
((EDI_PROJECT_CONFIG_FILE_EPOCH << 16) | EDI_PROJECT_CONFIG_FILE_GENERATION)
@ -235,6 +235,7 @@ _edi_config_init(void)
#define T Edi_Project_Config
#define D _edi_proj_cfg_edd
EDI_CONFIG_VAL(D, T, version, EET_T_INT);
EDI_CONFIG_VAL(D, T, font.name, EET_T_STRING);
EDI_CONFIG_VAL(D, T, font.size, EET_T_INT);
EDI_CONFIG_VAL(D, T, gui.translucent, EET_T_UCHAR);
EDI_CONFIG_VAL(D, T, gui.width, EET_T_INT);
@ -435,8 +436,6 @@ _edi_project_config_load()
/* setup defaults */
IFPCFG(0x0001);
_edi_project_config->font.size = 12;
_edi_project_config->gui.translucent = EINA_TRUE;
_edi_project_config->gui.width = 640;
_edi_project_config->gui.height = 480;
@ -453,8 +452,13 @@ _edi_project_config_load()
_edi_project_config->tabs = NULL;
IFPCFGEND;
IFPCFG(0x0002);
_edi_project_config->font.name = "Mono";
_edi_project_config->font.size = 12;
IFPCFGEND;
/* limit config values so they are sane */
EDI_CONFIG_LIMIT(_edi_project_config->font.size, 8, 96);
EDI_CONFIG_LIMIT(_edi_project_config->font.size, 6, 96);
EDI_CONFIG_LIMIT(_edi_project_config->gui.width, 150, 10000);
EDI_CONFIG_LIMIT(_edi_project_config->gui.height, 100, 8000);
EDI_CONFIG_LIMIT(_edi_project_config->gui.leftsize, 0.0, 1.0);

View File

@ -50,8 +50,9 @@ struct _Edi_Project_Config
{
int version;
struct
struct
{
char *name;
int size;
} font;

View File

@ -319,13 +319,13 @@ _edi_consolepanel_config_changed(void *data EINA_UNUSED, int type EINA_UNUSED, v
EINA_LIST_FOREACH(_edi_console_code->widgets, item, widget)
{
eo_do(widget,
elm_code_widget_font_size_set(_edi_project_config->font.size));
elm_code_widget_font_set(_edi_project_config->font.name, _edi_project_config->font.size));
}
EINA_LIST_FOREACH(_edi_test_code->widgets, item, widget)
{
eo_do(widget,
elm_code_widget_font_size_set(_edi_project_config->font.size));
elm_code_widget_font_set(_edi_project_config->font.name, _edi_project_config->font.size));
}
return ECORE_CALLBACK_RENEW;
@ -342,7 +342,7 @@ void edi_consolepanel_add(Evas_Object *parent)
widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
elm_code_widget_code_set(code));
eo_do(widget,
elm_code_widget_font_size_set(_edi_project_config->font.size),
elm_code_widget_font_set(_edi_project_config->font.name, _edi_project_config->font.size),
elm_code_widget_gravity_set(0.0, 1.0),
eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _edi_consolepanel_line_cb, NULL),
eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _edi_consolepanel_clicked_cb, code));
@ -369,7 +369,7 @@ void edi_testpanel_add(Evas_Object *parent)
widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
elm_code_widget_code_set(code));
eo_do(widget,
elm_code_widget_font_size_set(_edi_project_config->font.size),
elm_code_widget_font_set(_edi_project_config->font.name, _edi_project_config->font.size),
elm_code_widget_gravity_set(0.0, 1.0),
eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _edi_testpanel_line_cb, NULL),
eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _edi_consolepanel_clicked_cb, code));

View File

@ -42,7 +42,7 @@ _edi_content_provider_diff_add(Evas_Object *parent, Edi_Mainview_Item *item)
code = elm_code_create();
elm_code_file_open(code, item->path);
diff = elm_code_diff_widget_add(parent, code);
elm_code_diff_widget_font_size_set(diff, 12);
elm_code_diff_widget_font_set(diff, NULL, 12);
return diff;
}

View File

@ -50,7 +50,7 @@ static Eina_Bool
_edi_logpanel_config_changed(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
{
eo_do(_info_widget,
elm_code_widget_font_size_set(_edi_project_config->font.size));
elm_code_widget_font_set(_edi_project_config->font.name, _edi_project_config->font.size));
return ECORE_CALLBACK_RENEW;
}
@ -64,7 +64,7 @@ void edi_logpanel_add(Evas_Object *parent)
widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
elm_code_widget_code_set(code));
eo_do(widget,
elm_code_widget_font_size_set(_edi_project_config->font.size),
elm_code_widget_font_set(_edi_project_config->font.name, _edi_project_config->font.size),
elm_code_widget_gravity_set(0.0, 1.0),
eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _edi_logpanel_line_cb, NULL));
evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

View File

@ -578,7 +578,7 @@ _edi_editor_config_changed(void *data, int type EINA_UNUSED, void *event EINA_UN
widget = (Elm_Code_Widget *) data;
eo_do(widget,
elm_code_widget_font_size_set(_edi_project_config->font.size),
elm_code_widget_font_set(_edi_project_config->font.name, _edi_project_config->font.size),
elm_code_widget_show_whitespace_set(_edi_project_config->gui.show_whitespace),
elm_code_widget_line_width_marker_set(_edi_project_config->gui.width_marker),
elm_code_widget_tabstop_set(_edi_project_config->gui.tabstop));