Adding GUI support for OLED screens 4: TextBox controls
this blog link: http://blog.csdn.net/jdh99 , Author: jdh, reprint please specify.
Environment:
Host: WIN10
Development environment: MDK5.13
mcu:stm32f103
Description:This article defines a text box control. After adding font support to the GUI, you can use text boxes to display characters.
Source:
Gui_widget_text.h
/*** Copyright (c), 2015-2025* @file gui_widget_text.h* @brief Text Control header file * @author jdh* @date 2015/9/8*/#ifndef _gui_widget_t Ext_h_#define _gui_widget_text_h_/********************************************************************** Header File * * * * * /#include "gui_interface.h"/***************** Macro Definition ******************************************************* @brief text length. Units: Bytes */#define len_widget_text32/*********************************************** Data Structure **********************************************************************//*** @brief text box data structure */typedef struct _widget_text{//x axis position uint16_t x;//y axis position uint16_t y;//horizontal dimension uint16_t xsize;//vertical size uint16_t ysize;// Font uint8_t font;//text char s[len_widget_text];} *widget_text_handle;/********************************************************************** function ***************** *****************************************************@brief Create a control text* @param x: Upper-left corner x-coordinate * @param y: Upper-Left y-coordinate * @param xsize: Horizontal Dimension * @param ysize: Vertical Size * @param font: Font * @param s: text * @retval control handle */widget_text_handle gui_widget_text_create (uint16_t x,uint16_t y,uint16_t xsize,uint16_t ysize,uint8_t Font,char *s)/*** @brief Set text * @param s: Text */void gui_widget_text_set_text (widget_text_handle handle,uint8_t Font,char *s); #endif
Gui_widget_text.c
/*** Copyright (c), 2015-2025* @file gui_widget_text.c* @brief Text Control main file * @author jdh* @date 2015/9/8*//******************* Header file ********************************************************* /#include "gui_widget_text.h" #include "gui_2d_lib.h" #include "gui_text_lib.h" #include "stdlib.h" # Include "string.h"/********************************************************************** static function ****************** @brief control displays * @param handle: Control handle */static void Show (widget_ Text_handle Handle);/********************************************************************** function ****************** @brief Create the control text* @param x: Upper-Left x-coordinate * @param y: Upper-Left y-coordinate * @param Xsize: Horizontal Size * @param ysize: Vertical Size * @param font: Font * @param s: text * @retval control handle */widget_text_handle gui_widget_text_create ( uint16_t x,uint16_t y,uint16_t xsize,uint16_t ysize,uint8_t font,char *s) {Widget_text_hanDle handle;//Control Initialization handle = malloc (sizeof (*handle)); handle->x = X;handle->y = Y;handle->xsize = xsize;handle- >ysize = Ysize;handle->font = font;strcpy (handle->s,s),//Show show (handle); return handle;} /*** @brief Setting Text * @param s: Text */void gui_widget_text_set_text (widget_text_handle handle,uint8_t Font,char *s) {handle- >font = font;strcpy (handle->s,s);//display show (handle);} /*** @brief control displays * @param handle: Control handle */static void Show (Widget_text_handle handle) {//Clear area gui_fill_rect (Handle->x, Handle->y,handle->x + handle->xsize,handle->y + handle->ysize,0);//Display Gui_disp_string_at (handle-> X,handle->y,handle->font,handle->s);}
Examples of Use:
Widget_text_handle widget_text_state; Widget_text_state = Gui_widget_text_create (93,40,30,20,gb18030_20x20, "normal");
Adding GUI support for OLED screens 4: TextBox controls