theme: have only one theme_apply function

No more one about theming an elm_layout, nor using only the default theme.
Also, be able to chose which color scheme to use
This commit is contained in:
Boris Faure 2020-10-18 22:32:20 +02:00
parent 458f9a6da6
commit 93da3f87b7
Signed by: borisfaure
GPG Key ID: 35C0410516166BE8
11 changed files with 86 additions and 85 deletions

View File

@ -818,7 +818,8 @@ _type_mov_init(Evas_Object *obj)
evas_object_raise(sd->o_event);
o = sd->o_ctrl = edje_object_add(evas_object_evas_get(obj));
theme_apply(o, sd->config, "terminology/mediactrl");
theme_apply(o, sd->config, "terminology/mediactrl",
NULL, NULL, EINA_FALSE);
vol = emotion_object_audio_volume_get(sd->o_img);
edje_object_part_drag_value_set(o, "terminology.voldrag", vol, vol);
edje_object_signal_callback_add(o, "play", "",
@ -1316,7 +1317,8 @@ media_add(Evas_Object *parent, const char *src, const Config *config, int mode,
o = sd->o_busy = edje_object_add(evas_object_evas_get(obj));
evas_object_smart_member_add(o, obj);
theme_apply(o, sd->config, "terminology/mediabusy");
theme_apply(o, sd->config, "terminology/mediabusy",
NULL, NULL, EINA_FALSE);
evas_object_show(o);
edje_object_signal_emit(o, "busy", "terminology");

View File

@ -681,7 +681,8 @@ miniview_add(Evas_Object *parent, Evas_Object *termio)
mv->termio = termio;
mv->base = edje_object_add(canvas);
theme_apply(mv->base, termio_config_get(termio), "terminology/miniview");
theme_apply(mv->base, termio_config_get(termio), "terminology/miniview",
NULL, NULL, EINA_FALSE);
evas_object_smart_member_add(mv->base, obj);

View File

@ -226,7 +226,8 @@ _add_cursors_option(Evas_Object *bx,
elm_object_text_set(rd, _("Blinking Block"));
elm_radio_state_value_set(rd, 1);
layout = elm_layout_add(rd);
theme_apply_elm(layout, ctx->config, "terminology/cursor");
theme_apply(layout, ctx->config, "terminology/cursor",
NULL, NULL, EINA_TRUE);
evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_image_resizable_set(layout, EINA_FALSE, EINA_FALSE);
@ -245,7 +246,8 @@ _add_cursors_option(Evas_Object *bx,
elm_radio_state_value_set(rd, 2);
elm_radio_group_add(rd, rdg);
layout = elm_layout_add(rd);
theme_apply_elm(layout, ctx->config, "terminology/cursor");
theme_apply(layout, ctx->config, "terminology/cursor",
NULL, NULL, EINA_TRUE);
evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_image_resizable_set(layout, EINA_FALSE, EINA_FALSE);
@ -264,7 +266,8 @@ _add_cursors_option(Evas_Object *bx,
elm_radio_state_value_set(rd, 3);
elm_radio_group_add(rd, rdg);
layout = elm_layout_add(rd);
theme_apply_elm(layout, ctx->config, "terminology/cursor_underline");
theme_apply(layout, ctx->config, "terminology/cursor_underline",
NULL, NULL, EINA_TRUE);
evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_image_resizable_set(layout, EINA_FALSE, EINA_FALSE);
@ -283,7 +286,8 @@ _add_cursors_option(Evas_Object *bx,
elm_radio_state_value_set(rd, 4);
elm_radio_group_add(rd, rdg);
layout = elm_layout_add(rd);
theme_apply_elm(layout, ctx->config, "terminology/cursor_underline");
theme_apply(layout, ctx->config, "terminology/cursor_underline",
NULL, NULL, EINA_TRUE);
evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_image_resizable_set(layout, EINA_FALSE, EINA_FALSE);
@ -302,7 +306,8 @@ _add_cursors_option(Evas_Object *bx,
elm_radio_state_value_set(rd, 5);
elm_radio_group_add(rd, rdg);
layout = elm_layout_add(rd);
theme_apply_elm(layout, ctx->config, "terminology/cursor_bar");
theme_apply(layout, ctx->config, "terminology/cursor_bar",
NULL, NULL, EINA_TRUE);
evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_image_resizable_set(layout, EINA_FALSE, EINA_FALSE);
@ -321,7 +326,8 @@ _add_cursors_option(Evas_Object *bx,
elm_radio_state_value_set(rd, 6);
elm_radio_group_add(rd, rdg);
layout = elm_layout_add(rd);
theme_apply_elm(layout, ctx->config, "terminology/cursor_bar");
theme_apply(layout, ctx->config, "terminology/cursor_bar",
NULL, NULL, EINA_TRUE);
evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_image_resizable_set(layout, EINA_FALSE, EINA_FALSE);

View File

@ -309,7 +309,8 @@ _cb_op_font_content_get(void *data, Evas_Object *obj, const char *part)
Config *config = f->ctx->config;
o = edje_object_add(evas_object_evas_get(obj));
theme_apply(o, config, "terminology/fontpreview");
theme_apply(o, config, "terminology/fontpreview",
NULL, NULL, EINA_FALSE);
theme_auto_reload_enable(o);
evas_object_size_hint_min_set(o,
96 * elm_config_scale_get(),

View File

@ -264,7 +264,8 @@ _on_shortcut_add(void *data,
ctx->layout = elm_layout_add(bt);
evas_object_data_set(ctx->layout, "ctx", ctx);
oe = elm_layout_edje_get(ctx->layout);
theme_apply_elm(ctx->layout, ctx->config, "terminology/keybinding");
theme_apply(ctx->layout, ctx->config, "terminology/keybinding",
NULL, NULL, EINA_TRUE);
theme_auto_reload_enable(oe);
elm_layout_text_set(ctx->layout, "label", _("Please press key sequence"));
evas_object_show(ctx->layout);

View File

@ -110,8 +110,8 @@ options_theme_preview_add(Evas_Object *parent,
o = elm_layout_add(parent);
oe = elm_layout_edje_get(o);
obg = oe;
if (!edje_object_file_set(oe, file, "terminology/background"))
edje_object_file_set(oe, theme_path_default_get(), "terminology/background");
theme_apply(oe, config, "terminology/background",
file, NULL, EINA_FALSE);
if (config->translucent)
edje_object_signal_emit(oe, "translucent,on", "terminology");
else
@ -132,8 +132,8 @@ options_theme_preview_add(Evas_Object *parent,
// create a bg and swallow into core frame
o = elm_layout_add(parent);
oe = elm_layout_edje_get(o);
if (!edje_object_file_set(oe, file, "terminology/core"))
edje_object_file_set(oe, theme_path_default_get(), "terminology/core");
theme_apply(oe, config, "terminology/core",
file, NULL, EINA_FALSE);
if (config->translucent)
edje_object_signal_emit(oe, "translucent,on", "terminology");
else
@ -208,8 +208,8 @@ options_theme_preview_add(Evas_Object *parent,
// create a cursor and put it in the grid
o = elm_layout_add(parent);
oe = elm_layout_edje_get(o);
if (!edje_object_file_set(oe, file, "terminology/cursor"))
edje_object_file_set(oe, theme_path_default_get(), "terminology/cursor");
theme_apply(oe, config, "terminology/cursor",
file, NULL, EINA_FALSE);
edje_object_signal_emit(oe, "focus,in", "terminology");
evas_object_show(o);
evas_object_data_set(oo, "cursor", o);
@ -218,8 +218,8 @@ options_theme_preview_add(Evas_Object *parent,
// create a selection and put it in the grid
o = edje_object_add(evas);
oe = o;
if (!edje_object_file_set(oe, file, "terminology/selection"))
edje_object_file_set(oe, theme_path_default_get(), "terminology/selection");
theme_apply(oe, config, "terminology/selection",
file, NULL, EINA_FALSE);
edje_object_signal_emit(oe, "focus,in", "terminology");
edje_object_signal_emit(oe, "mode,oneline", "terminology");
evas_object_show(o);

View File

@ -729,7 +729,8 @@ sel_entry_add(Evas_Object *obj, Evas_Object *entry,
en->selected_before = selected;
en->selected_orig = selected;
en->bg = edje_object_add(evas_object_evas_get(obj));
theme_apply(en->bg, config, "terminology/sel/item");
theme_apply(en->bg, config, "terminology/sel/item",
NULL, NULL, EINA_FALSE);
evas_object_smart_member_add(en->bg, obj);
evas_object_clip_set(en->bg, sd->clip);
edje_object_part_swallow(en->bg, "terminology.content", en->obj);

View File

@ -527,7 +527,8 @@ termio_config_set(Evas_Object *obj, Config *config)
termio_set_cursor_shape(obj, sd->cursor.shape);
theme_apply(sd->sel.theme, config, "terminology/selection");
theme_apply(sd->sel.theme, config, "terminology/selection",
NULL, NULL, EINA_FALSE);
theme_auto_reload_enable(sd->sel.theme);
edje_object_part_swallow(sd->sel.theme, "terminology.top_left", sd->sel.top);
edje_object_part_swallow(sd->sel.theme, "terminology.bottom_right", sd->sel.bottom);
@ -554,7 +555,8 @@ termio_set_cursor_shape(Evas_Object *obj, Cursor_Shape shape)
EINA_SAFETY_ON_NULL_RETURN(sd);
config = sd->config;
theme_apply(sd->cursor.obj, config, _cursor_shape_to_group_name(shape));
theme_apply(sd->cursor.obj, config, _cursor_shape_to_group_name(shape),
NULL, NULL, EINA_FALSE);
theme_auto_reload_enable(sd->cursor.obj);
evas_object_resize(sd->cursor.obj, sd->font.chw, sd->font.chh);
evas_object_show(sd->cursor.obj);
@ -1464,7 +1466,8 @@ _color_tooltip_content(void *data,
const char *txt;
o = edje_object_add(canvas);
theme_apply(o, sd->config, "terminology/color_preview");
theme_apply(o, sd->config, "terminology/color_preview",
NULL, NULL, EINA_FALSE);
evas_object_size_hint_min_set(o, 80, 80);
edje_object_color_class_set(o, "color_preview",
sd->link.color.r, sd->link.color.g, sd->link.color.b, sd->link.color.a,
@ -1527,7 +1530,8 @@ _update_link(Termio *sd, Eina_Bool same_geom)
{
o = elm_layout_add(sd->win);
evas_object_smart_member_add(o, obj);
theme_apply(elm_layout_edje_get(o), sd->config, "terminology/link");
theme_apply(o, sd->config, "terminology/link",
NULL, NULL, EINA_TRUE);
if (y == sd->link.y1)
{
@ -1682,8 +1686,8 @@ _hyperlink_mouseover(Termio *sd,
{
o = elm_layout_add(sd->win);
evas_object_smart_member_add(o, sd->self);
theme_apply(elm_layout_edje_get(o), sd->config,
"terminology/link");
theme_apply(o, sd->config, "terminology/link",
NULL, NULL, EINA_TRUE);
evas_object_move(o,
ox + (x * sd->font.chw),
oy + (y * sd->font.chh));

View File

@ -54,71 +54,46 @@ theme_path_default_get(void)
}
Eina_Bool
theme_apply(Evas_Object *edje, const Config *config, const char *group)
theme_apply(Evas_Object *obj,
const Config *config,
const char *group,
const char *theme_file,
const Color_Scheme *cs,
Eina_Bool is_elm_layout)
{
const char *theme_path = theme_file;
Evas_Object *edje = obj;
const char *errmsg;
EINA_SAFETY_ON_NULL_RETURN_VAL(edje, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(config, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(group, EINA_FALSE);
if (!theme_file)
theme_path = config_theme_path_get(config);
/* use default if nord is chosen
* but rely on color_scheme_apply_from_config() */
if (!eina_str_has_suffix(config->theme, "/nord.edj"))
if (is_elm_layout)
{
edje = elm_layout_edje_get(obj);
if (elm_layout_file_set(obj, config_theme_path_get(config), group))
goto done;
if (elm_layout_file_set(obj, theme_path_default_get(), group))
goto done;
}
else
{
if (edje_object_file_set(edje, config_theme_path_get(config), group))
goto done;
errmsg = edje_load_error_str(edje_object_load_error_get(edje));
INF(_("Could not find theme: file=%s group=%s error='%s', trying default theme"),
config_theme_path_get(config), group, errmsg);
}
if (edje_object_file_set(edje, theme_path_default_get(), group))
goto done;
errmsg = edje_load_error_str(edje_object_load_error_get(edje));
ERR(_("Could not load any theme for group=%s: %s"), group, errmsg);
return EINA_FALSE;
done:
color_scheme_apply_from_config(edje, config);
return EINA_TRUE;
}
Eina_Bool
theme_apply_elm(Evas_Object *layout, const Config *config, const char *group)
{
const char *errmsg;
Evas_Object *edje;
EINA_SAFETY_ON_NULL_RETURN_VAL(layout, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(config, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(group, EINA_FALSE);
edje = elm_layout_edje_get(layout);
/* use default if nord is chosen
* but rely on color_scheme_apply_from_config() */
if (!eina_str_has_suffix(config->theme, "/nord.edj"))
{
if (elm_layout_file_set(layout, config_theme_path_get(config), group))
if (edje_object_file_set(edje, theme_path_default_get(), group))
goto done;
}
errmsg = edje_load_error_str(edje_object_load_error_get(edje));
INF(_("Could not find theme: file=%s group=%s error='%s', trying default theme"),
config_theme_path_get(config), group, errmsg);
if (elm_layout_file_set(layout, theme_path_default_get(), group))
goto done;
errmsg = edje_load_error_str(edje_object_load_error_get(edje));
ERR(_("Could not load any theme for group=%s: %s"), group, errmsg);
return EINA_FALSE;
done:
color_scheme_apply_from_config(edje, config);
if (cs)
color_scheme_apply(edje, cs);
else
color_scheme_apply_from_config(edje, config);
return EINA_TRUE;
}

View File

@ -3,9 +3,15 @@
#include <Evas.h>
#include "config.h"
#include "colors.h"
Eina_Bool theme_apply(Evas_Object *edje, const Config *config, const char *group);
Eina_Bool theme_apply_elm(Evas_Object *edje, const Config *config, const char *group);
Eina_Bool
theme_apply(Evas_Object *obj,
const Config *config,
const char *group,
const char *theme_file,
const Color_Scheme *cs,
Eina_Bool is_elm_layout);
void theme_reload(Evas_Object *edje);
void theme_auto_reload_enable(Evas_Object *edje);
const char *theme_path_get(const char *name);

View File

@ -2219,7 +2219,7 @@ win_new(const char *name, const char *role, const char *title,
wn->base = o = elm_layout_add(wn->win);
elm_object_focus_allow_set(o, EINA_TRUE);
evas_object_propagate_events_set(o, EINA_FALSE);
theme_apply_elm(o, config, "terminology/base");
theme_apply(o, config, "terminology/base", NULL, NULL, EINA_TRUE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_content_set(wn->conform, o);
@ -3579,7 +3579,8 @@ _tab_inactive_get_or_create(Evas *canvas,
term->tab_inactive = o = edje_object_add(canvas);
theme_apply(o, term->config, "terminology/tabbar_back");
theme_apply(o, term->config, "terminology/tabbar_back",
NULL, NULL, EINA_FALSE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
edje_object_size_min_calc(o, &w, &h);
@ -4155,7 +4156,8 @@ _tab_drag_start(void *data EINA_UNUSED)
for_each_term_do(_tab_drag->term->wn, &_term_hdrag_off, NULL);
_tab_drag->icon = o;
theme_apply_elm(o, term->config, "terminology/tab_drag_thumb");
theme_apply(o, term->config, "terminology/tab_drag_thumb",
NULL, NULL, EINA_TRUE);
elm_layout_text_set(o, "terminology.title",
term->container->title);
elm_layout_content_unset(term->bg, "terminology.content");
@ -4401,7 +4403,8 @@ _cb_tab_selector_show(Tabs *tabs, Tab_Item *to_item)
evas_object_geometry_get(o, &x, &y, &w, &h);
tabs->selector_bg = edje_object_add(evas_object_evas_get(tc->wn->win));
theme_apply(tabs->selector_bg, wn->config, "terminology/sel/base");
theme_apply(tabs->selector_bg, wn->config, "terminology/sel/base",
NULL, NULL, EINA_FALSE);
evas_object_geometry_set(tabs->selector_bg, x, y, w, h);
evas_object_hide(o);
@ -5909,7 +5912,8 @@ void change_theme(Evas_Object *win, Config *config)
{
Evas_Object *edje = term->bg_edj;
if (!theme_apply_elm(term->bg, config, "terminology/background"))
if (!theme_apply(term->bg, config, "terminology/background",
NULL, NULL, EINA_TRUE))
ERR("Couldn't find terminology theme!");
colors_term_init(termio_textgrid_get(term->termio), edje, config);
termio_config_set(term->termio, config);
@ -7373,7 +7377,7 @@ term_new(Win *wn, Config *config, const char *cmd,
term->config = config;
term->core = o = elm_layout_add(wn->win);
theme_apply_elm(o, term->config, "terminology/core");
theme_apply(o, term->config, "terminology/core", NULL, NULL, EINA_TRUE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
@ -7386,7 +7390,7 @@ term_new(Win *wn, Config *config, const char *cmd,
term->bg_edj = elm_layout_edje_get(o);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
if (!theme_apply_elm(o, config, "terminology/background"))
if (!theme_apply(o, config, "terminology/background", NULL, NULL, EINA_TRUE))
{
CRITICAL(_("Couldn't find terminology theme! Forgot 'ninja install'?"));
evas_object_del(term->bg);