summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwrmr2025-08-25 21:31:26 -0400
committerwrmr2025-08-25 21:31:26 -0400
commit5af124221327b4f5714b4c2475d49b75aec6abb2 (patch)
tree66902a5ee06c6a5d92f87b3bd2b357b5a3ee8559
parentc33cd57aa83ad6d6a8c5bcfd4686e5ce7c190044 (diff)
GFX_PFP_MARGIN; visually center post shorter than pfp
-rw-r--r--main.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/main.c b/main.c
index cc00c83..09a9480 100644
--- a/main.c
+++ b/main.c
@@ -43,6 +43,7 @@
#define HALF_PAGE_LEN ((getmaxy(stdscr) * 75) / 100)
#define GFX_MARGIN_X 2
#define GFX_MARGIN_Y 1
+#define GFX_PFP_MARGIN 1
#define GFX_TEXT_MARGIN_X 1
#define GFX_TEXT_MARGIN_Y 0
#define GFX_POST_SPACING 1
@@ -439,7 +440,7 @@ typedef struct {
int post_left_margin(Post *post) {
int lm = opt.margin.left;
- if (opt.see.pfp && post->user->pfp.cols >= lm) lm = post->user->pfp.cols + 1;
+ if (opt.see.pfp && post->user->pfp.cols >= lm) lm = post->user->pfp.cols + GFX_PFP_MARGIN;
return lm;
}
@@ -486,8 +487,13 @@ int gfx_post_height(GfxPost *post) {
return post->lines + 2 + GFX_TEXT_MARGIN_Y * 2 + n;
}
+int gfx_post_text_height(GfxPost *post) {
+ return post->lines + 2 + GFX_TEXT_MARGIN_Y * 2;
+}
+
void gfx_draw_post(GfxPost *post, int y, int x, int width, Arena *scratch) {
- int height = gfx_post_height(post);
+ int height = gfx_post_text_height(post);
+ int total_height = gfx_post_height(post);
if (!post->drawn) {
gfx_predraw_post(post);
@@ -499,6 +505,12 @@ void gfx_draw_post(GfxPost *post, int y, int x, int width, Arena *scratch) {
int self = is_post_mine(post->src);
User *u = post->src->user;
+ if (total_height > height) {
+ int ydiff = (total_height - height) >> 1;
+ top += ydiff;
+ bottom += ydiff;
+ }
+
color_set(CPAIR_BORDER, 0);
gfx_hline(top, left, right - left, ACS_HLINE);
gfx_vline(top, left, height - 1, ACS_VLINE);
@@ -512,25 +524,25 @@ void gfx_draw_post(GfxPost *post, int y, int x, int width, Arena *scratch) {
color_set(CPAIR_TIME, 0);
Str s = str_trim(str_from_cstr(ctime(&(time_t){post->src->timestamp.tv_sec})));
- mvaddnstr(y, right - s.n, s.s, s.n);
+ mvaddnstr(top, right - s.n, s.s, s.n);
if (opt.see.pfp) {
color_set(self ? CPAIR_PFP_SELF : CPAIR_PFP, 0);
Pfp *pfp = &u->pfp;
- int pfptop = top + GFX_TEXT_MARGIN_Y;
+ int pfptop = y + GFX_TEXT_MARGIN_Y;
if (height > pfp->lines) pfptop += (height - pfp->lines) >> 1;
- int pfpleft = left - pfp->cols - GFX_TEXT_MARGIN_X;
+ int pfpleft = left - pfp->cols - GFX_PFP_MARGIN;
for (int i = 0; i < pfp->lines; i++) {
mvaddnstr(pfptop + i, pfpleft, pfp->line[i].s, pfp->line[i].n);
}
}
color_set(CPAIR_USER, 0);
- mvaddnstr(y, left + 2, u->name.s, u->name.n);
+ mvaddnstr(top, left + 2, u->name.s, u->name.n);
if (opt.see.pronouns && u->pronouns.n) {
color_set(CPAIR_PRONOUNS, 0);
- mvaddstr(y, left + 2 + fast_utf8_width(u->name) + GFX_PRONOUNS_MARGIN, cstr_fmt(scratch, GFX_PRONOUNS_FMT, u->pronouns));
+ mvaddstr(top, left + 2 + fast_utf8_width(u->name) + GFX_PRONOUNS_MARGIN, cstr_fmt(scratch, GFX_PRONOUNS_FMT, u->pronouns));
}
color_set(post->has_mention ? CPAIR_MENTION : CPAIR_TEXT, 0);