This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch main
in repository elaro.
View the commit online.
commit c3e3ee7cbae14611a95da55431a18d94af9e2720
Author: Alastair Poole <[email protected]>
AuthorDate: Sat Nov 28 14:20:40 2026 +0000
history: show dividers
---
NEWS | 1 +
src/fe-efl/ui/elaro_ui_history.c | 222 ++++++++++++++++++++++++++++-----------
tests/fe-efl/test-ui-state.c | 20 +++-
3 files changed, 181 insertions(+), 62 deletions(-)
diff --git a/NEWS b/NEWS
index 635e6f9..e7b96aa 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Elaro 0.1.3
===========
* Icons now match each theme’s accent color.
+ * The chat history uses full-height themed dividers with padding between the timestamp, nickname, and message columns.
===========
Elaro 0.1.2
diff --git a/src/fe-efl/ui/elaro_ui_history.c b/src/fe-efl/ui/elaro_ui_history.c
index 66afd78..4b57ea9 100644
--- a/src/fe-efl/ui/elaro_ui_history.c
+++ b/src/fe-efl/ui/elaro_ui_history.c
@@ -1,5 +1,59 @@
#include "elaro_ui_private.h"
+#define HISTORY_COLUMN_PADDING ELM_SCALE_SIZE(5)
+
+typedef struct
+{
+ Evas_Object *dividers[2];
+ Evas_Coord timestamp_width;
+ Evas_Coord gutter;
+} History_Columns;
+
+static void
+_history_dividers_update(Evas_Object *history)
+{
+ History_Columns *columns;
+ Evas_Coord x, y, width, height, text_x;
+ Evas_Coord offsets[2];
+ int r, g, b, a;
+ int secondary_r, secondary_g, secondary_b, secondary_a;
+ int tertiary_r, tertiary_g, tertiary_b, tertiary_a;
+
+ columns = evas_object_data_get(history, "history-columns");
+ if (!columns) return;
+ evas_object_geometry_get(history, &x, &y, &width, &height);
+ evas_object_geometry_get(elm_entry_textblock_get(history), &text_x, NULL, NULL, NULL);
+ /* The second divider leaves padding before both the first and wrapped lines. */
+ offsets[0] = columns->timestamp_width - 1;
+ offsets[1] = columns->gutter - HISTORY_COLUMN_PADDING - 1;
+ if (!edje_color_class_get("/fg/normal/frame/separator", &r, &g, &b, &a,
+ &secondary_r, &secondary_g, &secondary_b, &secondary_a,
+ &tertiary_r, &tertiary_g, &tertiary_b, &tertiary_a))
+ r = g = b = a = 128;
+ for (unsigned int i = 0; i < EINA_C_ARRAY_LENGTH(columns->dividers); i++)
+ {
+ Evas_Object *divider = columns->dividers[i];
+ Evas_Coord divider_x = text_x + offsets[i];
+
+ evas_object_color_set(divider, r * a / 255, g * a / 255, b * a / 255, a);
+ evas_object_move(divider, divider_x, y);
+ evas_object_resize(divider, 1, height);
+ if (evas_object_visible_get(history) && offsets[i] >= 0
+ && divider_x >= x && divider_x < x + width && height > 0)
+ {
+ evas_object_raise(divider);
+ evas_object_show(divider);
+ }
+ else evas_object_hide(divider);
+ }
+}
+
+static void
+_history_dividers_geometry_changed(void *data, Evas *evas, Evas_Object *history, void *info)
+{
+ _history_dividers_update(history);
+}
+
/* Prefixes are separate inline textblocks with an exact width. Their glyph
* advances never affect the message column, including with proportional fonts. */
static Evas_Object *
@@ -66,16 +120,49 @@ _history_prefix_decode(const char *encoded, size_t length)
return result;
}
-static Evas_Object *
-_history_prefix_item(void *data, Evas_Object *history, const char *item)
+static void
+_history_prefix_style(Evas_Object *history, Evas_Object *text, Eina_Bool timestamp,
+ Evas_Coord left_margin, Evas_Coord right_margin)
{
- Evas_Object *text;
Evas_Textblock_Style *style;
const Evas_Textblock_Style *font_style;
const char *font;
const char *end;
- char *prefix;
char *format;
+
+ style = evas_textblock_style_new();
+ /* The user style can be DEFAULT='' or a partial override. Use the resolved
+ * base style so inline cells always have a font and size of their own. */
+ font_style = evas_object_textblock_style_get(elm_entry_textblock_get(history));
+ font = font_style ? evas_textblock_style_get(font_style) : "DEFAULT=''";
+ if (!font) font = "DEFAULT=''";
+ end = strstr(font, "DEFAULT='");
+ if (end)
+ {
+ end += 9;
+ while (*end && (*end != '\'' || (end > font && end[-1] == '\\')))
+ {
+ end++;
+ }
+ }
+ /* Keep the entry's resolved foreground. The desktop's global color class
+ * can change independently and must not make just the prefixes invisible. */
+ format = elaro_string_printf("%.*s wrap=none ellipsis=1.0 align=%s left_margin=%d right_margin=%d'%s",
+ end ? (int) (end - font) : 9, font,
+ timestamp ? "left" : "right", left_margin,
+ right_margin,
+ end && *end ? end + 1 : "");
+ evas_textblock_style_set(style, format);
+ free(format);
+ evas_object_textblock_style_user_push(text, style);
+ evas_textblock_style_free(style);
+}
+
+static Evas_Object *
+_history_prefix_item(void *data, Evas_Object *history, const char *item)
+{
+ Evas_Object *text;
+ char *prefix;
Eina_Bool timestamp;
size_t length;
@@ -94,31 +181,8 @@ _history_prefix_item(void *data, Evas_Object *history, const char *item)
length = strlen(prefix);
if (length && prefix[length - 1] == ' ') prefix[length - 1] = 0;
text = _history_textblock(history);
- style = evas_textblock_style_new();
- /* The user style can be DEFAULT='' or a partial override. Use the resolved
- * base style so inline cells always have a font and size of their own. */
- font_style = evas_object_textblock_style_get(elm_entry_textblock_get(history));
- font = font_style ? evas_textblock_style_get(font_style) : "DEFAULT=''";
- if (!font) font = "DEFAULT=''";
- end = strstr(font, "DEFAULT='");
- if (end)
- {
- end += 9;
- while (*end && (*end != '\'' || (end > font && end[-1] == '\\')))
- {
- end++;
- }
- }
- /* Keep the entry's resolved foreground. The desktop's global color class
- * can change independently and must not make just the prefixes invisible. */
- format = elaro_string_printf("%.*s wrap=none ellipsis=1.0 align=%s left_margin=0 right_margin=%d'%s",
- end ? (int) (end - font) : 9, font,
- timestamp ? "left" : "right", timestamp ? 0 : ELM_SCALE_SIZE(8),
- end && *end ? end + 1 : "");
- evas_textblock_style_set(style, format);
- free(format);
- evas_object_textblock_style_user_push(text, style);
- evas_textblock_style_free(style);
+ _history_prefix_style(history, text, timestamp, timestamp ? 0 : HISTORY_COLUMN_PADDING,
+ timestamp ? HISTORY_COLUMN_PADDING + 1 : 2 * HISTORY_COLUMN_PADDING + 1);
evas_object_textblock_text_markup_set(text, prefix);
evas_object_pass_events_set(text, EINA_TRUE);
free(prefix);
@@ -143,7 +207,7 @@ static char *
_history_columns(Evas_Object *history, const char *markup, Eina_Bool reset)
{
Evas_Object *measure;
- Evas_Coord *saved_gutter;
+ History_Columns *columns;
Eina_Strbuf *out;
const char *line;
const char *end;
@@ -156,11 +220,13 @@ _history_columns(Evas_Object *history, const char *markup, Eina_Bool reset)
Evas_Coord width;
Evas_Coord gutter;
Evas_Coord height;
- Evas_Coord timestamp_width;
+ Evas_Coord timestamp_width = 0;
+ Evas_Coord padding = HISTORY_COLUMN_PADDING;
+ Evas_Coord minimum_gutter;
Eina_Bool repeated;
Evas_Coord nickname_width;
- saved_gutter = evas_object_data_get(history, "history-gutter");
+ columns = evas_object_data_get(history, "history-columns");
author = evas_object_data_del(history, "history-author");
if (reset)
@@ -169,13 +235,28 @@ _history_columns(Evas_Object *history, const char *markup, Eina_Bool reset)
author = NULL;
}
measure = _history_textblock(history);
- evas_object_textblock_text_markup_set(measure, "[00:00] <nickname123> ");
+ if (reset)
+ {
+ _history_prefix_style(history, measure, EINA_TRUE, 0, 0);
+ for (char digit = '0'; digit <= '9'; digit++)
+ {
+ char stamp[] = { '[', digit, digit, ':', digit, digit, ']', 0 };
+ Evas_Coord stamp_width;
+
+ evas_object_textblock_text_markup_set(measure, stamp);
+ evas_object_textblock_size_native_get(measure, &stamp_width, NULL);
+ if (stamp_width > timestamp_width) timestamp_width = stamp_width;
+ }
+ timestamp_width += 2 * padding + 1;
+ }
+ else timestamp_width = columns->timestamp_width;
+ minimum_gutter = timestamp_width + 3 * padding + 1;
+ _history_prefix_style(history, measure, EINA_FALSE, 0, 0);
+ evas_object_textblock_text_markup_set(measure, "<nickname123>");
evas_object_textblock_size_native_get(measure, &gutter, &height);
- evas_object_textblock_text_markup_set(measure, "[00:00] ");
- evas_object_textblock_size_native_get(measure, ×tamp_width, NULL);
- /* Fit actual nicknames, including proportional fonts and IRC markup. Keep
- * the existing width on append so every message uses the same columns. */
- if (!reset && saved_gutter && *saved_gutter > gutter) gutter = *saved_gutter;
+ gutter += minimum_gutter;
+ /* Keep the existing width on append so every message uses the same columns. */
+ if (!reset && columns->gutter > gutter) gutter = columns->gutter;
for (line = markup; *line; line = end + 5)
{
end = strstr(line, "<br/>");
@@ -191,7 +272,7 @@ _history_columns(Evas_Object *history, const char *markup, Eina_Bool reset)
evas_object_textblock_text_markup_set(measure, nick);
evas_object_textblock_size_native_get(measure, &nickname_width, NULL);
free(nick);
- nickname_width += timestamp_width + ELM_SCALE_SIZE(8);
+ nickname_width += minimum_gutter;
if (nickname_width > gutter) gutter = nickname_width;
}
}
@@ -199,15 +280,17 @@ _history_columns(Evas_Object *history, const char *markup, Eina_Bool reset)
}
evas_object_del(measure);
evas_object_geometry_get(history, NULL, NULL, &width, NULL);
- /* Before the first layout the entry can be only one pixel wide. Do not
- * bake zero-width inline items into the history at that provisional size.
- * Wait until the available gutter can hold a timestamp and nickname gap;
- * the resize reflow will apply the normal limit once layout is ready. */
- if (width * 0.45 > timestamp_width + ELM_SCALE_SIZE(8)
- && gutter > width * 0.45)
- gutter = width * 0.45;
- if (timestamp_width > gutter) timestamp_width = gutter;
- if (saved_gutter) *saved_gutter = gutter;
+ /* Preserve space for both dividers when the viewport is narrow. */
+ if (width > minimum_gutter + 2 * padding)
+ {
+ Evas_Coord limit = width * 0.45;
+
+ if (limit < minimum_gutter) limit = minimum_gutter;
+ if (gutter > limit) gutter = limit;
+ }
+ columns->timestamp_width = timestamp_width;
+ columns->gutter = gutter;
+ _history_dividers_update(history);
out = eina_strbuf_new();
if (!out) goto allocation_failed;
for (line = markup; *line; line = end + 5)
@@ -233,8 +316,8 @@ _history_columns(Evas_Object *history, const char *markup, Eina_Bool reset)
else
{
_history_cell_append(out, line, nickname - line, timestamp_width, height, EINA_FALSE);
- _history_cell_append(out, nickname, body - nickname, gutter - timestamp_width, height,
- repeated);
+ _history_cell_append(out, nickname, body - nickname, gutter - timestamp_width,
+ height, repeated);
}
eina_strbuf_append_printf(out, "<left_margin=+%d>", gutter);
eina_strbuf_append_length(out, body, end - body);
@@ -306,7 +389,8 @@ _history_reflow(void *data)
ui = evas_object_data_get(history, "history-ui");
evas_object_data_del(history, "history-reflow");
- if (ui) _history_refresh(ui, EINA_TRUE);
+ if (ui && ui->current) _history_refresh(ui, EINA_TRUE);
+ else free(_history_columns(history, "", EINA_TRUE));
}
static void
@@ -403,7 +487,10 @@ _history_del(void *data, Evas *evas, Evas_Object *obj, void *info)
if (job) ecore_job_del(job);
free(evas_object_data_del(obj, "history-position"));
free(evas_object_data_del(obj, "history-author"));
- free(evas_object_data_del(obj, "history-gutter"));
+ History_Columns *columns = evas_object_data_del(obj, "history-columns");
+ for (unsigned int i = 0; i < EINA_C_ARRAY_LENGTH(columns->dividers); i++)
+ evas_object_del(columns->dividers[i]);
+ free(columns);
free(evas_object_data_del(obj, "history-copy-selection"));
}
@@ -419,6 +506,7 @@ _history_position_restore(void *data)
position = evas_object_data_del(obj, "history-position");
evas_object_data_del(obj, "history-position-job");
+ _history_dividers_update(obj);
if (!position) return;
if (*position >= 1.0) elm_entry_cursor_end_set(obj);
elm_entry_calc_force(obj);
@@ -431,6 +519,7 @@ _history_position_restore(void *data)
static void
_history_loaded(void *data, Evas_Object *obj, void *info)
{
+ _history_dividers_update(obj);
/* Restore the viewport after Elementary has processed the loaded entry's
* cursor and size changes, which otherwise override a synchronous scroll. */
if (evas_object_data_get(obj, "history-position"))
@@ -503,14 +592,24 @@ Evas_Object *
elaro_ui_history_add(Evas_Object *parent)
{
Evas_Object *history;
- Evas_Coord *gutter;
+ History_Columns *columns;
- gutter = calloc(1, sizeof(*gutter));
-
- if (!gutter) return NULL;
+ columns = calloc(1, sizeof(*columns));
+ if (!columns) return NULL;
history = elaro_ui_read_view_add(parent);
elm_object_style_set(history, "elaro/history");
- evas_object_data_set(history, "history-gutter", gutter);
+ evas_object_data_set(history, "history-columns", columns);
+ for (unsigned int i = 0; i < EINA_C_ARRAY_LENGTH(columns->dividers); i++)
+ {
+ Evas_Object *divider = evas_object_rectangle_add(evas_object_evas_get(history));
+
+ columns->dividers[i] = divider;
+ evas_object_smart_member_add(divider, history);
+ evas_object_pass_events_set(divider, EINA_TRUE);
+ }
+ evas_object_event_callback_add(history, EVAS_CALLBACK_MOVE, _history_dividers_geometry_changed, NULL);
+ evas_object_event_callback_add(history, EVAS_CALLBACK_SHOW, _history_dividers_geometry_changed, NULL);
+ evas_object_event_callback_add(history, EVAS_CALLBACK_HIDE, _history_dividers_geometry_changed, NULL);
elm_entry_line_wrap_set(history, ELM_WRAP_MIXED);
elm_entry_select_allow_set(history, EINA_TRUE);
elm_entry_context_menu_disabled_set(history, EINA_FALSE);
@@ -529,6 +628,7 @@ elaro_ui_history_add(Evas_Object *parent)
* as well as font edits, including window opacity and desktop changes. */
evas_object_smart_callback_add(history, "theme,changed", _history_font_changed, NULL);
evas_object_smart_callback_add(history, "selection,copy", _history_copy_requested, NULL);
+ free(_history_columns(history, "", EINA_TRUE));
return history;
}
@@ -541,17 +641,17 @@ elaro_ui_history_refresh(Elaro_Ui *ui)
void
elaro_ui_history_append(Elaro_Ui *ui, const char *markup)
{
- Evas_Coord *gutter;
+ History_Columns *layout;
char *columns;
Evas_Coord previous_gutter;
- gutter = evas_object_data_get(ui->history, "history-gutter");
- previous_gutter = gutter ? *gutter : 0;
+ layout = evas_object_data_get(ui->history, "history-columns");
+ previous_gutter = layout->gutter;
columns = _history_columns(ui->history, markup, EINA_FALSE);
/* The retained buffer already includes this message. Reflow older rows
* when a wider nickname moves the message column. */
- if (gutter && *gutter != previous_gutter)
+ if (layout->gutter != previous_gutter)
_history_refresh(ui, EINA_TRUE);
else elm_entry_entry_append(ui->history, columns);
free(columns);
diff --git a/tests/fe-efl/test-ui-state.c b/tests/fe-efl/test-ui-state.c
index 1a5e13e..022c842 100644
--- a/tests/fe-efl/test-ui-state.c
+++ b/tests/fe-efl/test-ui-state.c
@@ -447,10 +447,28 @@ int main(int argc, char **argv)
Elaro_Ui_Buffer *columns = elaro_ui_buffer_get(&ui, "test", "column-query");
Elaro_Engine_Event line = { .type = ELARO_ENGINE_LINE, .server = "test",
.target = "column-query", .text = "<iii> First message with enough words to wrap across several lines while keeping the message body aligned with the next speaker." };
- elaro_ui_buffer_event(&ui, &line);
elaro_ui_buffer_select(columns);
elm_win_resize_object_add(ui.win, ui.history);
evas_object_show(ui.history);
+ evas_object_resize(ui.win, 700, 300);
+ settle_layout();
+ assert(!strstr(elm_entry_entry_get(ui.history), "<item "));
+ Evas_Coord history_x, history_y, history_w, history_h;
+ evas_object_geometry_get(ui.history, &history_x, &history_y, &history_w, &history_h);
+ Eina_List *members = evas_object_smart_members_get(ui.history), *node;
+ Evas_Object *member;
+ unsigned int dividers = 0;
+ EINA_LIST_FOREACH(members, node, member) {
+ Evas_Coord x, y, w, h;
+ evas_object_geometry_get(member, &x, &y, &w, &h);
+ if (!strcmp(evas_object_type_get(member), "rectangle") &&
+ evas_object_visible_get(member) && w == 1 && y == history_y && h == history_h &&
+ x > history_x && x < history_x + history_w)
+ dividers++;
+ }
+ eina_list_free(members);
+ assert(dividers == 2);
+ elaro_ui_buffer_event(&ui, &line);
for (int pass = 0; pass < 3; pass++) {
evas_object_resize(ui.win, pass == 1 ? 480 : 700, 300);
elm_config_font_overlay_set("entry", pass == 1 ? "Serif" : "Sans", pass == 2 ? 18 : 14);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.