1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

txt_get_size added +lv_page_focus handle greater objects then page + LV_SIGNAL_PRESSING added

This commit is contained in:
Gabor 2016-12-19 11:58:11 +01:00
parent 2d5366ee09
commit 373b75bd53
11 changed files with 120 additions and 42 deletions

View File

@ -267,10 +267,14 @@ void lv_app_win_close(lv_app_inst_t * app)
{
if(app->win == NULL) return;
lv_app_kb_close();
lv_obj_del(app->win);
app->win = NULL;
dm_free(app->win_data);
app->win_data = NULL;
}
@ -495,6 +499,8 @@ static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t
lv_obj_t * win = lv_win_get_from_ctrl_btn(close_btn);
lv_app_inst_t * app = lv_obj_get_free_p(win);
lv_app_kb_close();
#if LV_APP_ANIM_WIN_CLOSE != 0
lv_obj_anim(app->win, LV_ANIM_FADE | ANIM_OUT, LV_APP_ANIM_WIN_CLOSE, 0, lv_app_win_close_anim_cb);
lv_app_sc_close(app);
@ -503,6 +509,7 @@ static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t
return LV_ACTION_RES_INV;
#endif
return LV_ACTION_RES_OK;
}
@ -511,6 +518,9 @@ static lv_action_res_t lv_app_win_minim_action(lv_obj_t * close_btn, lv_dispi_t
{
lv_obj_t * win = lv_win_get_from_ctrl_btn(close_btn);
lv_app_inst_t * app = lv_obj_get_free_p(win);
lv_app_kb_close();
/*Make an animation on window open*/
#if LV_APP_ANIM_WIN_OPEN != 0
anim_t a;
@ -662,6 +672,7 @@ static void lv_app_init_style(void)
app_style.app_list_style.bg_pages.scrable_rects.opad = 0;
app_style.app_list_style.bg_pages.sb_rects.objs.color = COLOR_GRAY;
app_style.app_list_style.bg_pages.sb_rects.gcolor = COLOR_GRAY;
app_style.app_list_style.bg_pages.sb_width = 8 * LV_DOWNSCALE;
/*Shortcut page styles*/
lv_pages_get(LV_PAGES_DEF,&app_style.sc_page_style);
@ -681,8 +692,8 @@ static void lv_app_init_style(void)
app_style.sc_style.mcolor[LV_BTN_STATE_REL] = COLOR_WHITE;
app_style.sc_style.gcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x20, 0x30, 0x40);
app_style.sc_style.bcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x40, 0x60, 0x80);
app_style.sc_style.mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0xD0, 0xE0, 0xF0);
app_style.sc_style.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x20, 0x30, 0x40);
app_style.sc_style.mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0xB0, 0xD0, 0xF0);
app_style.sc_style.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x00, 0x00, 0x00);
app_style.sc_style.bcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0xB0, 0xD0, 0xF0);
app_style.sc_style.rects.bopa = 70;
app_style.sc_style.rects.bwidth = 1 * LV_STYLE_MULT;

View File

@ -21,11 +21,22 @@
/**********************
* STATIC PROTOTYPES
**********************/
static lv_action_res_t lv_app_kb_action(lv_obj_t * btnm, uint16_t i);
/**********************
* STATIC VARIABLES
**********************/
static lv_obj_t * kb_btnm;
static lv_obj_t * kb_win;
static lv_obj_t * kb_ta;
static const char * kb_map_lc[] = {
"\0021#", "\002q", "\002w", "\002e", "\002r", "\002t", "\002y", "\002u", "\002i", "\002o", "\002p", "\003Del", "\n",
"\002ABC", "a", "s", "d", "f", "g", "h", "j", "k", "l", "\003Enter", "\n",
"*", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ";", "\n",
"\002Free", "\002<", "\006 ", "\002>", "\002Free", ""
};
static lv_btnms_t kb_btnms;
static bool kb_inited;
/**********************
* MACROS
@ -37,29 +48,57 @@ static lv_obj_t * kb_btnm;
void lv_app_kb_open(lv_obj_t * ta)
{
if(kb_inited == false) {
lv_btnms_get(LV_BTNMS_DEF, &kb_btnms);
kb_btnms.rects.opad = 4 + LV_STYLE_MULT;
kb_btnms.rects.vpad = 3 + LV_STYLE_MULT;
kb_btnms.rects.hpad = 3 + LV_STYLE_MULT;
kb_inited = true;
}
if(kb_btnm != NULL) {
lv_app_kb_close();
}
kb_ta = ta;
kb_btnm = lv_btnm_create(lv_scr_act(), NULL);
lv_obj_set_size(kb_btnm, LV_HOR_RES, LV_VER_RES / 2);
lv_obj_align(kb_btnm, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_obj_set_style(kb_btnm, &kb_btnms);
lv_btnm_set_map(kb_btnm, kb_map_lc);
lv_btnm_set_cb(kb_btnm, lv_app_kb_action);
lv_ta_add_text(ta, "alma\n\nkorte\n\ncitrom\nbarack\nbanaaaan\n\n");
lv_ta_set_cursor_pos(ta, LV_TA_CUR_LAST);
kb_win = lv_app_get_win_from_obj(kb_ta);
lv_obj_set_height(kb_win, LV_VER_RES / 2);
lv_obj_set_y(kb_win, 0);
lv_obj_t * win = lv_app_get_win_from_obj(ta);
lv_obj_set_height(win, LV_VER_RES / 2);
lv_obj_set_y(win, 0);
// lv_obj_set_height(kb_ta, LV_VER_RES / 2 - 50);
lv_page_focus(lv_win_get_content(win), ta, true);
lv_ta_add_text(kb_ta, "alma\n\nkorte\n\ncitrom\nbarack\nbanaaaan\n\n");
lv_ta_set_cursor_pos(kb_ta, LV_TA_CUR_LAST);
lv_page_focus(lv_win_get_content(kb_win), kb_ta, true);
}
void lv_app_kb_close(void)
{
if(kb_btnm == NULL) return;
lv_obj_set_size(kb_win, LV_HOR_RES, LV_VER_RES);
kb_win = NULL;
lv_obj_del(kb_btnm);
kb_btnm = NULL;
kb_ta = NULL;
}
static lv_action_res_t lv_app_kb_action(lv_obj_t * btnm, uint16_t i)
{
lv_ta_add_text(kb_ta, kb_map_lc[i]);
lv_page_focus(lv_win_get_content(kb_win), kb_ta, true);
return LV_ACTION_RES_OK;
}
/**********************

View File

@ -166,9 +166,9 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
lv_obj_t * ta;
ta = lv_ta_create(win, NULL);
lv_obj_set_size_us(ta, 200, 300);
lv_obj_set_size_us(ta, 200, 100);
lv_obj_set_pos_us(ta, 20, 270);
lv_rect_set_fit(ta, false, true);
// lv_rect_set_fit(ta, false, true);
lv_page_set_rel_action(ta, kb_open);
}

View File

@ -7,6 +7,7 @@
* INCLUDES
*********************/
#include "text.h"
#include "misc/math/math_base.h"
/*********************
* DEFINES
@ -34,6 +35,37 @@ static bool txt_is_break_char(char letter);
* GLOBAL FUNCTIONS
**********************/
void txt_get_size(point_t * size_res, const char * text, const font_t * font,
uint16_t letter_space, uint16_t line_space, cord_t max_width)
{
uint32_t line_start = 0;
uint32_t new_line_start = 0;
cord_t act_line_length;
uint8_t letter_height = font_get_height(font);
size_res->x = 0;
size_res->y = 0;
/*Calc. the height and longest line*/
while (text[line_start] != '\0')
{
new_line_start += txt_get_next_line(&text[line_start], font, letter_space, max_width);
size_res->y += letter_height;
size_res->y += line_space;
/*Calculate the the longest line*/
act_line_length = txt_get_width(&text[line_start], new_line_start - line_start,
font, letter_space);
size_res->x = max(act_line_length, size_res->x);
line_start = new_line_start;
}
/*Correction with the last line space*/
if(size_res->y >= 0) {
size_res->y -= line_space;
}
}
/**
* Get the next line of text. Check line length and break chars too.
* @param txt a '\0' terminated string

View File

@ -13,6 +13,7 @@
#include <lvgl/lv_misc/area.h>
#include <stdbool.h>
#include "font.h"
#include "area.h"
/*********************
* DEFINES
@ -25,6 +26,8 @@
/**********************
* GLOBAL PROTOTYPES
**********************/
void txt_get_size(point_t * size_res, const char * text, const font_t * font,
uint16_t letter_space, uint16_t line_space, cord_t max_width);
uint16_t txt_get_next_line(const char * txt, const font_t * font_p, uint16_t letter_space, cord_t max_l);
cord_t txt_get_width(const char * txt, uint16_t char_num, const font_t * font_p, uint16_t letter_space);

View File

@ -249,6 +249,7 @@ static void dispi_proc_press(lv_dispi_t * dispi_p)
/* The reset can be set in the signal function.
* In case of reset query ignore the remaining parts.*/
if(lv_dispi_reset_qry == false) {
pr_obj->signal_f(pr_obj, LV_SIGNAL_PRESSING, dispi_p);
dispi_p->act_obj = pr_obj; /*Save the pressed object*/
dispi_p->last_obj = dispi_p->act_obj; /*Refresh the last_obj*/

View File

@ -65,6 +65,7 @@ typedef enum
{
LV_SIGNAL_CLEANUP,
LV_SIGNAL_PRESSED,
LV_SIGNAL_PRESSING,
LV_SIGNAL_PRESS_LOST,
LV_SIGNAL_RELEASED,
LV_SIGNAL_LONG_PRESS,

View File

@ -448,9 +448,14 @@ static void lv_btns_init(void)
lv_btns_def.flags[LV_BTN_STATE_INA].transp= 0;
lv_btns_def.flags[LV_BTN_STATE_INA].empty = 0;
lv_btns_def.rects.objs.color = lv_btns_def.mcolor[LV_BTN_STATE_REL];
lv_btns_def.rects.gcolor = lv_btns_def.gcolor[LV_BTN_STATE_REL];
lv_btns_def.rects.bcolor = lv_btns_def.bcolor[LV_BTN_STATE_REL];
lv_btns_def.rects.objs.transp = 0;
lv_btns_def.rects.empty = 0;
lv_btns_def.rects.light = 0;
lv_btns_def.rects.bwidth = 2 * LV_STYLE_MULT;
lv_btns_def.rects.bopa = 50;
lv_btns_def.rects.light = 8 * LV_STYLE_MULT;
lv_btns_def.rects.empty = 0;
lv_btns_def.rects.round = 4 * LV_STYLE_MULT;
lv_btns_def.rects.hpad = 10 * LV_STYLE_MULT;

View File

@ -159,45 +159,25 @@ void lv_label_set_text(lv_obj_t * label, const char * text)
/*If 'text" still NULL then nothing to do: return*/
if(text == NULL) return;
uint32_t line_start = 0;
uint32_t new_line_start = 0;
cord_t max_length = lv_obj_get_width(label);
lv_labels_t * labels = lv_obj_get_style(label);
const font_t * font = font_get(labels->font);
cord_t max_w = lv_obj_get_width(label);
lv_labels_t * style = lv_obj_get_style(label);
const font_t * font = font_get(style->font);
uint8_t letter_height = font_get_height(font);
cord_t new_height = 0;
cord_t longest_line = 0;
cord_t act_line_length;
ext->dot_end = LV_LABEL_DOT_END_INV; /*Initialize the dot end index*/
/*If the width will be expanded set the max length to very big */
if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) {
max_length = LV_CORD_MAX;
max_w = LV_CORD_MAX;
}
/*Calc. the height and longest line*/
while (text[line_start] != '\0')
{
new_line_start += txt_get_next_line(&text[line_start], font, labels->letter_space, max_length);
new_height += letter_height;
new_height += labels->line_space;
/*Calculate the the longest line if the width will be expanded*/
if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) {
act_line_length = txt_get_width(&text[line_start], new_line_start - line_start,
font, labels->letter_space);
longest_line = max(act_line_length, longest_line);
}
line_start = new_line_start;
}
point_t size;
txt_get_size(&size, ext->txt, font, style->letter_space, style->line_space, max_w);
/*Correction with the last line space*/
new_height -= labels->line_space;
/*Refresh the full size in expand mode*/
if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) {
lv_obj_set_size(label, longest_line, new_height);
lv_obj_set_size(label, size.x, size.y);
/*Start scrolling if the label is greater then its parent*/
if(ext->long_mode == LV_LABEL_LONG_SCROLL) {
@ -244,7 +224,7 @@ void lv_label_set_text(lv_obj_t * label, const char * text)
}
/*In break mode only the height can change*/
else if (ext->long_mode == LV_LABEL_LONG_BREAK) {
lv_obj_set_height(label, new_height);
lv_obj_set_height(label, size.y);
}
/*Replace the last 'LV_LABEL_DOT_NUM' characters with dots
* and save these characters*/

View File

@ -342,15 +342,21 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en)
bool refr = false;
cord_t top_err = -(scrlable_y + obj_y);
cord_t bot_err = scrlable_y + obj_y + obj_h - page_h;
/*If obj is higher then the page focus where the "error" is smaller*/
/*Out of the page on the top*/
if(scrlable_y + obj_y < 0) {
if((obj_h <= page_h && top_err > 0) ||
(obj_h > page_h && top_err >= bot_err)) {
/*Calculate a new position and to let scrable_rects.vpad space above*/
scrlable_y = -(obj_y - style->scrable_rects.vpad - style->bg_rects.vpad);
scrlable_y += style->scrable_rects.vpad;
refr = true;
}
/*Out of the page on the bottom*/
else if(scrlable_y + obj_y + obj_h > page_h) {
else if((obj_h <= page_h && bot_err > 0) ||
(obj_h > page_h && top_err < bot_err)) {
/*Calculate a new position and to let scrable_rects.vpad space below*/
scrlable_y = -obj_y;
scrlable_y += page_h - obj_h;

View File

@ -29,6 +29,7 @@ typedef enum
LV_PAGE_SB_MODE_AUTO,
}lv_page_sb_mode_t;
/*Style of page*/
typedef struct
{
@ -63,7 +64,6 @@ typedef struct
}lv_page_ext_t;
/**********************
* GLOBAL PROTOTYPES
**********************/