selection list started

This commit is contained in:
olikraus 2016-06-01 19:27:05 +02:00
parent 5bdc9d1ab6
commit b6d6acd933
4 changed files with 92 additions and 20 deletions

View File

@ -546,8 +546,8 @@ u8g2_uint_t u8g2_DrawUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char
#define u8g2_GetMaxCharHeight(u8g2) ((u8g2)->font_info.max_char_height)
#define u8g2_GetMaxCharWidth(u8g2) ((u8g2)->font_info.max_char_width)
#define u8g2_GetAscent(u8g2) ((u8g2)->font_info.ascent_A)
#define u8g2_GetDescent(u8g2) ((u8g2)->font_info.descent_g)
#define u8g2_GetAscent(u8g2) ((u8g2)->font_ref_ascent)
#define u8g2_GetDescent(u8g2) ((u8g2)->font_ref_descent)
u8g2_uint_t u8g2_GetStrWidth(u8g2_t *u8g2, const char *s);
u8g2_uint_t u8g2_GetUTF8Width(u8g2_t *u8g2, const char *str);
@ -557,6 +557,13 @@ void u8g2_SetFontPosBottom(u8g2_t *u8g2);
void u8g2_SetFontPosTop(u8g2_t *u8g2);
void u8g2_SetFontPosCenter(u8g2_t *u8g2);
void u8g2_SetFontRefHeightText(u8g2_t *u8g2);
void u8g2_SetFontRefHeightExtendedText(u8g2_t *u8g2);
void u8g2_SetFontRefHeightAll(u8g2_t *u8g2);
/*==========================================*/
/* u8g2_selection_list.c */
void u8g2_DrawUTF8Line(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, const char *s, uint8_t border_size, uint8_t is_invert);
/*==========================================*/
/* u8x8_d_sdl_128x64.c */
@ -573,6 +580,9 @@ void u8g2_SetupBuffer_TGA_LCD(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb);
/* 96x32 stdout */
void u8g2_SetupBuffer_Utf8(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb);
/*==========================================*/
/* itoa procedures */
#define u8g2_u8toa u8x8_u8toa

View File

@ -39,30 +39,47 @@
/*
Draw a string
Extend the string to size "w"
Center the string, if the first char is a '\t' (center with respect to "w")
return the size of the string
Draw a string at x,y
Center string within w (left adjust if w < pixel len of s)
Side effects:
u8g2_SetFontDirection(u8g2, 0);
*/
void u8g2_DrawUTF8Line(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, const char *s)
void u8g2_DrawUTF8Line(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, const char *s, uint8_t border_size, uint8_t is_invert)
{
u8g2_uint_t d, lw;
u8g2_uint_t d, str_width;
/* only horizontal strings are supported, so force this here */
u8g2_SetFontDirection(u8g2, 0);
/* revert y position back to baseline ref */
y += u8g2->font_calc_vref(u8g2);
d = 0;
if ( *s == '\t' )
/* calculate the width of the string in pixel */
str_width = u8g2_GetUTF8Width(u8g2, s);
/* calculate delta d within the box */
d = 0;
if ( str_width < w )
{
s++; /* skip '\t' */
lw = u8g2_GetUTF8Len(u8g2, s);
if ( lw < w )
{
d = w;
d -=lw;
d /= 2;
}
d = w;
d -=str_width;
d /= 2;
}
x += d
u8g2_DrawUTF8(u8g2, x, y, s);
/*
if ( is_invert )
{
u8g2_SetDrawColor(u8g2, 1);
}
*/
u8g2_DrawUTF8(u8g2, x+d, y, s);
}

View File

@ -0,0 +1,14 @@
CC = gcc
CFLAGS = -g -W -Wall -Wextra -Wcast-qual -Wno-overlength-strings -Wno-unused-parameter -I../../../csrc/.
SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) main.c
OBJ = $(SRC:.c=.o)
u8g2_utf8: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o u8g2_utf8
clean:
-rm $(OBJ) u8g2_utf8

View File

@ -0,0 +1,31 @@
#include "u8g2.h"
#include <stdio.h>
u8g2_t u8g2;
int main(void)
{
u8g2_SetupBuffer_Utf8(&u8g2, U8G2_R0);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
u8g2_SetFont(&u8g2, u8g2_font_6x13_tf);
u8g2_SetFontDirection(&u8g2, 0);
u8g2_FirstPage(&u8g2);
do
{
u8g2_DrawUTF8Line(&u8g2, 5, 15, 40, "abc", 1,0);
} while( u8g2_NextPage(&u8g2) );
utf8_show();
return 0;
}