commit 7b5498e387d5d8d05ffaf404e665a32f2de32e75
parent c990c56e3031b2973a251347dc2f8935b957cd79
Author: lumidify <nobody@lumidify.org>
Date: Thu, 21 May 2020 17:53:49 +0200
Convert button to use new text renderer
Diffstat:
4 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,7 +1,7 @@
LIBS = -lm `pkg-config --libs x11 harfbuzz fontconfig fribidi`
STD = -std=c99
CFLAGS = -g -w -fcommon -Wall -Werror -Wextra `pkg-config --cflags x11 harfbuzz fontconfig fribidi` -pedantic
-OBJ = stb_truetype.o text_edit.o text-common.o text_buffer.o text-hb.o ltk.o ini.o grid.o button.o test1.o
+OBJ = stb_truetype.o text_edit.o text-common.o text_buffer.o ltk.o ini.o grid.o button.o test1.o
test1: $(OBJ)
gcc $(STD) -o $@ $(OBJ) $(LIBS)
diff --git a/button.c b/button.c
@@ -22,6 +22,7 @@
*/
#include <stdio.h>
+#include <stdint.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "khash.h"
@@ -31,7 +32,8 @@
#include <harfbuzz/hb.h>
#include <fontconfig/fontconfig.h>
#include "text-common.h"
-#include "text-hb.h"
+#include "array.h"
+#include "text_buffer.h"
#include "button.h"
extern Ltk *ltk_global;
@@ -122,7 +124,12 @@ void ltk_draw_button(LtkButton *button)
XSetLineAttributes(ltk_global->display, window->gc, bw, LineSolid, CapButt, JoinMiter);
XDrawRectangle(ltk_global->display, window->xwindow, window->gc, rect.x + bw / 2, rect.y + bw / 2, rect.w - bw, rect.h - bw);
if (!img) {
- img = ltk_render_text_line(button->tl, ltk_global->display, window->xwindow, window->gc, ltk_global->colormap, theme->text_color, fill);
+ /* FIXME: make this a bit nicer - text_line is made for text_buffer, but
+ it really doesn't make much sense here to store the image in text_line */
+ ltk_text_line_render(button->tl, ltk_global->display, window->xwindow, window->gc, ltk_global->colormap, theme->text_color, fill);
+ img = button->tl->img;
+ /* set to NULL so it isn't freed on next call to render */
+ button->tl->img = NULL;
/* FIXME: any nicer way to do this? */
switch (button->widget.state) {
case LTK_NORMAL:
@@ -162,7 +169,10 @@ LtkButton *ltk_create_button(LtkWindow *window, const char *text, void (*callbac
button->callback = callback;
button->data = data;
LtkTheme *theme = ltk_global->theme;
- button->tl = ltk_create_text_line(ltk_global->tm, text, ltk_global->tm->default_font, theme->button->font_size);
+ button->tl = ltk_text_line_create();
+ /* FIXME: support font size */
+ ltk_text_line_insert_utf8(button->tl, 0, text);
+ ltk_text_line_wrap(button->tl, -1);
button->widget.rect.w = button->tl->w + (theme->button->border_width + theme->button->pad) * 2;
button->widget.rect.h = button->tl->h + (theme->button->border_width + theme->button->pad) * 2;
button->text = NULL;
@@ -184,7 +194,7 @@ void ltk_destroy_button(LtkButton *button)
if (button->text_pressed) XDestroyImage(button->text_pressed);
if (button->text_active) XDestroyImage(button->text_active);
if (button->text_disabled) XDestroyImage(button->text_disabled);
- ltk_destroy_text_line(button->tl);
+ ltk_text_line_destroy(button->tl);
free(button);
}
diff --git a/button.h b/button.h
@@ -24,13 +24,13 @@
#ifndef _LTK_BUTTON_H_
#define _LTK_BUTTON_H_
-/* Requires the following includes: <X11/Xlib.h>, "ltk.h", "text-hb.h" */
+/* Requires the following includes: <X11/Xlib.h>, "ltk.h", "text_buffer.h" */
typedef struct {
LtkWidget widget;
void (*callback) (void *, XEvent, void *);
void *data;
- LtkTextLine *tl;
+ struct ltk_text_line *tl;
XImage *text;
XImage *text_hover;
XImage *text_pressed;
diff --git a/ltkx.h b/ltkx.h
@@ -9,7 +9,6 @@
#include <harfbuzz/hb.h>
#include <harfbuzz/hb-ot.h>
#include "text-common.h"
-#include "text-hb.h"
#include "button.h"
#include "grid.h"
#include "array.h"