{"id":668,"date":"2022-12-27T10:09:47","date_gmt":"2022-12-27T02:09:47","guid":{"rendered":"http:\/\/www.huangrongzhen.ink\/?p=668"},"modified":"2023-03-04T20:19:20","modified_gmt":"2023-03-04T12:19:20","slug":"%e5%8d%95%e7%89%87%e6%9c%ba-gui-%e8%ae%be%e8%ae%a1%ef%bc%88%e5%85%ad%ef%bc%89-%e8%a1%8c%e8%be%93%e5%85%a5%e6%8e%a7%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.huangrongzhen.ink\/?p=668","title":{"rendered":"\u5355\u7247\u673a GUI \u8bbe\u8ba1\uff08\u516d\uff09- \u884c\u8f93\u5165\u63a7\u4ef6"},"content":{"rendered":"<div class=\"wp-block-post-excerpt\"><p class=\"wp-block-post-excerpt__excerpt\">\u57fa\u4e8e GD32F303ZET6 \u82f9\u679c\u6d3e\u5f00\u53d1\u677f <\/p><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%AE%80%E4%BB%8B\"><\/span>\u7b80\u4ecb<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u884c\u8f93\u5165\u662f\u4e00\u79cd\u8f93\u5165\u63a7\u4ef6\uff0c\u7528\u4e8e\u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u4e00\u884c\u5b57\u7b26\u4e32\uff0c\u5e94\u7528\u5e7f\u6cdb\uff0c\u6d4f\u89c8\u5668\u7684\u641c\u7d22\u680f\u3001\u4e00\u4e9b\u5c0f\u5de5\u5177\u7684\u53c2\u6570\u8bbe\u7f6e\uff0c\u7b49\u7b49\u3002\u884c\u8f93\u5165\u63a7\u4ef6\u901a\u5e38\u6709\u4e24\u79cd\u72b6\u6001\uff0c\u5206\u522b\u662f\u6709\u7126\u70b9\u548c\u65e0\u7126\u70b9\u3002\u5199\u5165\u65f6\u53ea\u80fd\u5199\u5165\u6709\u7126\u70b9\u7684\u884c\u8f93\u5165\u63a7\u4ef6\uff0c\u4e0d\u80fd\u5199\u5165\u6ca1\u6709\u7126\u70b9\u7684\u884c\u8f93\u5165\u63a7\u4ef6\uff1b\u8bfb\u53d6\u65f6\u4e0d\u8bba\u63a7\u4ef6\u662f\u5426\u6709\u7126\u70b9\uff0c\u90fd\u80fd\u8bfb\u53d6\u6210\u529f\u3002<\/p>\n\n\n\n<p>\u884c\u8f93\u5165\u63a7\u4ef6\u901a\u5e38\u4e0e\u6309\u952e\u8f93\u5165\u63a7\u4ef6\u642d\u914d\u4f7f\u7528\uff0c\u5b9e\u73b0\u57fa\u672c\u7684\u7528\u6237\u4ea4\u4e92\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%8E%A7%E5%88%B6%E7%BB%93%E6%9E%84%E4%BD%93%E8%AE%BE%E8%AE%A1\"><\/span>\u63a7\u5236\u7ed3\u6784\u4f53\u8bbe\u8ba1<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u884c\u8f93\u5165\u63a7\u4ef6\u5177\u6709\u201c\u6709\u7126\u70b9\u201d\u548c\u201c\u65e0\u7126\u70b9\u201d\u4e24\u79cd\u72b6\u6001\uff0c\u901a\u8fc7\u70b9\u51fb\u6539\u53d8\u72b6\u6001\u3002\u70b9\u51fb\u4e00\u4e2a\u884c\u8f93\u5165\u63a7\u4ef6\u540e\uff0c\u5982\u679c\u8be5\u63a7\u4ef6\u6ca1\u6709\u7126\u70b9\uff0c\u90a3\u4e48\u4f1a\u81ea\u52a8\u83b7\u53d6\u7126\u70b9\u3002\u6b64\u65f6\uff0c\u5982\u679c\u754c\u9762\u5185\u6709\u5176\u5b83\u884c\u8f93\u5165\u63a7\u4ef6\u5177\u6709\u7126\u70b9\uff0c\u90a3\u4e48\u5c31\u8981\u53d6\u6d88\u8be5\u63a7\u4ef6\u7684\u7126\u70b9\uff0c\u4fdd\u8bc1\u754c\u9762\u5185\u53ea\u80fd\u6709\u4e00\u4e2a\u884c\u8f93\u5165\u63a7\u4ef6\u6709\u7126\u70b9\u3002\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u72b6\u6001\u662f\u901a\u8fc7\u70b9\u51fb\u6539\u53d8\u7684\uff0c\u4e0e\u6309\u952e\u7c7b\u4f3c\uff0c\u56e0\u6b64\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u63a7\u5236\u7ed3\u6784\u4f53\u53ef\u4ee5\u53c2\u8003\u6309\u952e\u63a7\u4ef6\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">\/\/\u884c\u8f93\u5165\u63a7\u4ef6\u63a7\u5236\u7ed3\u6784\u4f53\ntypedef struct\n{\n  u16   x, y, width, height;  \/\/\u539f\u70b9\u3001\u5bbd\u5ea6\u3001\u9ad8\u5ea6\n  char* text;                 \/\/\u8f93\u5165\u7ed3\u679c\uff0c\u521b\u5efa\u65f6\u81ea\u52a8\u52a8\u6001\u5206\u914d\n  u8    textSize;             \/\/\u5b57\u4f53\u5927\u5c0f\uff0c\u53ef\u4ee5\u662f 12\u300116\u300124\n  u16   textColor;            \/\/\u5b57\u4f53\u989c\u8272\n  u8    focus;                \/\/0-\u65e0\u7126\u70b9\uff0c1-\u6709\u7126\u70b9\n  u16   hasFocusColor;        \/\/\u6709\u7126\u70b9\u65f6\u663e\u793a\u7684\u989c\u8272\uff0c\u6ca1\u6709\u80cc\u666f\u56fe\u7247\u65f6\u4f7f\u7528\n  u16   noFocusColor;         \/\/\u65e0\u7126\u70b9\u65f6\u663e\u793a\u7684\u989c\u8272\uff0c\u6ca1\u6709\u80cc\u666f\u56fe\u7247\u65f6\u4f7f\u7528\n  void* hasFocusImage;        \/\/\u6709\u7126\u70b9\u65f6\u663e\u793a\u7684\u56fe\u7247\uff0c\u4f7f\u7528 JPEG \u56fe\u7247\uff0c\u4e0d\u7528\u65f6\u8bf7\u586b\u5165 NULL\n  void* noFocusImage;         \/\/\u65e0\u7126\u70b9\u65f6\u663e\u793a\u7684\u56fe\u7247\uff0c\u4f7f\u7528 JPEG \u56fe\u7247\uff0c\u4e0d\u7528\u65f6\u8bf7\u586b\u5165 NULL\n}StructLineEdit;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"API_%E5%87%BD%E6%95%B0%E8%AE%BE%E8%AE%A1\"><\/span>API \u51fd\u6570\u8bbe\u8ba1<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u884c\u8f93\u5165\u63a7\u4ef6\u6240\u9700\u8981\u7684 API \u63a5\u53e3\u51fd\u6570\u6bd4\u8f83\u591a\uff0c\u5177\u4f53\u5982\u4e0b\u6240\u793a\u3002\u901a\u8fc7 LineEditScan \u51fd\u6570\u626b\u63cf\u884c\u8f93\u5165\u63a7\u4ef6\u65f6\uff0c\u5982\u679c\u68c0\u6d4b\u5230\u63a7\u4ef6\u6709\u88ab\u6309\u4e0b\uff0c\u90a3\u4e48\u63a7\u4ef6\u5c06\u81ea\u52a8\u83b7\u5f97\u7126\u70b9\u5e76\u66f4\u65b0\u72b6\u6001\u3002\u5bf9\u4e8e\u591a\u4e2a\u884c\u8f93\u5165\u63a7\u4ef6\uff0c\u901a\u5e38\u53ea\u6709\u4e00\u4e2a\u62e5\u6709\u7126\u70b9\uff0c\u6240\u4ee5\u9700\u8981\u7528 LineEditRemoveFocus \u51fd\u6570\u6e05\u9664\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u7126\u70b9\u72b6\u6001\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">void CreateLineEdit(StructLineEdit* widget);         \/\/\u521b\u5efa\u884c\u7f16\u8f91\u63a7\u4ef6\nu32  LineEditScan(StructLineEdit* widget);           \/\/\u884c\u7f16\u8f91\u63a7\u4ef6\u626b\u63cf\nvoid LineEditRemoveFocus(StructLineEdit* widget);    \/\/\u53d6\u6d88\u884c\u7f16\u8f91\u63a7\u4ef6\u7684\u7126\u70b9\nvoid LineEditAdd(StructLineEdit* widget, char code); \/\/\u884c\u7f16\u8f91\u63a7\u4ef6\u6dfb\u52a0\u4e00\u4e2a\u5b57\u7b26\nvoid LineEditDelete(StructLineEdit* widget);         \/\/\u5220\u9664\u4e00\u4e2a\u5b57\u7b26<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%A9%B1%E5%8A%A8%E6%BA%90%E6%96%87%E4%BB%B6%E5%8C%85%E5%90%AB%E7%9A%84%E5%A4%B4%E6%96%87%E4%BB%B6\"><\/span>\u9a71\u52a8\u6e90\u6587\u4ef6\u5305\u542b\u7684\u5934\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"block-33a711a7-74c0-4d60-bc08-b973691aff1d\">\u9a71\u52a8\u6587\u4ef6\u9700\u8981\u5305\u542b\u7684\u5934\u6587\u4ef6\u5982\u4e0b\u6240\u793a\uff0c\u4e3a\u4e86\u7f8e\u89c2\uff0c\u6211\u4eec\u53ef\u4ee5\u7528 JPEG \u56fe\u7247\u6765\u88c5\u9970\u884c\u8f93\u5165\u63a7\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">#include \"LineEdit.h\"\n#include \"LCD.h\"\n#include \"Touch.h\"\n#include \"JPEG.h\"\n#include \"stdio.h\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%88%9B%E5%BB%BA%E6%8E%A7%E4%BB%B6%E5%87%BD%E6%95%B0\"><\/span>\u521b\u5efa\u63a7\u4ef6\u51fd\u6570<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5728\u521b\u5efa\u63a7\u4ef6\u51fd\u6570\u4e2d\uff0c\u6211\u4eec\u8981\u8bbe\u7f6e\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u521d\u59cb\u72b6\u6001\uff0c\u540c\u65f6\u8fd8\u8981\u4e3a\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u7ed3\u679c\u8f93\u5165\u51c6\u5907\u4e00\u4e2a\u7f13\u51b2\u533a\uff0c\u7528\u4e8e\u50a8\u5b58\u7528\u6237\u8f93\u5165\uff0c\u5177\u4f53\u5982\u4e0b\u6240\u793a\u3002\u4e00\u822c\u884c\u8f93\u5165\u63a7\u4ef6\u90fd\u4f1a\u6709\u9ed1\u8272\u6216\u767d\u8272\u8fb9\u6846\uff0c\u4e3a\u4e86\u663e\u793a\u7684\u5b57\u7b26\u4e0d\u4f1a\u8986\u76d6\u5230\u8fb9\u6846\uff0c\u672c\u9a71\u52a8\u4e2d\u884c\u8f93\u5165\u7684\u9996\u4f4d\u90fd\u9884\u7559\u4e86\u4e00\u4e2a\u7a7a\u683c\u7684\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">void CreateLineEdit(StructLineEdit* widget)\n{\n  \/\/\u884c\u8f93\u5165\u63a7\u4ef6\u80fd\u5bb9\u7eb3\u7684\u6700\u5927\u5b57\u7b26\u6570\u91cf\n  unsigned int maxStringLen;\n  \n  \/\/\u8ba1\u7b97\u884c\u7f16\u8f91\u63a7\u4ef6\u6700\u5927\u5b57\u7b26\u4e32\u957f\u5ea6\n  maxStringLen = widget-&gt;width \/ (widget-&gt;textSize \/ 2);\n  \n  \/\/\u4e3a\u5b57\u7b26\u4e32\u7f13\u51b2\u533a\u7533\u8bf7\u52a8\u6001\u5185\u5b58\n  widget-&gt;text = (char*)malloc(maxStringLen + 1);\n  if(NULL == widget-&gt;text)\n  {\n    printf(\"Fail to malloc\\r\\n\");\n    while(1){}\n  }\n  \n  \/\/\u8bbe\u5b9a\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e3a\u7a7a\u683c\n  widget-&gt;text[0] = ' ';\n  widget-&gt;text[1] = 0;\n  \n  \/\/\u9ed8\u8ba4\u65e0\u7126\u70b9\n  widget-&gt;focus = 0;\n  \n  \/\/\u66f4\u65b0\u663e\u793a\n  UpdateShow(widget);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%88%B7%E6%96%B0%E6%98%BE%E7%A4%BA%E5%87%BD%E6%95%B0\"><\/span>\u5237\u65b0\u663e\u793a\u51fd\u6570<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4e0a\u8ff0\u4ee3\u7801\u4e2d\u7684 UpdateShow \u51fd\u6570\u7528\u4e8e\u5237\u65b0\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u663e\u793a\uff0c\u53ef\u4ee5\u505a\u4e3a\u4e00\u4e2a\u5185\u90e8\u51fd\u6570\uff0c\u5982\u4e0b\u6240\u793a\u3002UpdateShow \u51fd\u6570\u9996\u5148\u5237\u65b0\u80cc\u666f\uff0c\u53ef\u4ee5\u662f\u5237\u56fe\u6216\u77e9\u5f62\u586b\u5145\u3002\u56e0\u4e3a\u884c\u8f93\u5165\u63a7\u4ef6\u901a\u5e38\u662f\u77e9\u5f62\u7684\uff0c\u4e3a\u4e86\u8282\u7701\u5185\u5b58\u7a7a\u95f4\uff0c\u5728\u8fd9\u91cc\u5c06\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u56fe\u7247\u7c7b\u578b\u5b9a\u4e3a JPEG \u56fe\u7247\u3002\u5237\u65b0\u5b8c\u80cc\u666f\u540e\uff0c\u53ef\u4ee5\u6309\u7167\u7eb5\u5750\u6807\u5c45\u4e2d\u7684\u65b9\u5f0f\u6253\u5370\u884c\u8f93\u5165\u63a7\u4ef6\u8f93\u5165\u7ed3\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">static void UpdateShow(StructLineEdit* widget)\n{\n  unsigned int x0, y0, x1, y1, i, x, y;\n  \n  \/\/\u8ba1\u7b97\u8ba1\u7b97\u63a7\u4ef6\u5750\u6807\u8303\u56f4\n  x0 = widget-&gt;x;\n  y0 = widget-&gt;y;\n  x1 = widget-&gt;x + widget-&gt;width - 1;\n  y1 = widget-&gt;y + widget-&gt;height - 1;\n  \n  \/\/\u6709\u7126\u70b9\u65f6\u5237\u65b0\u80cc\u666f\n  if(1 == widget-&gt;focus)\n  {\n    if(NULL != widget-&gt;hasFocusImage)\n    {\n      DrawJPEG(widget-&gt;hasFocusImage, widget-&gt;x, widget-&gt;y);\n    }\n    else\n    {\n      LCDFill(x0, y0, x1, y1, widget-&gt;hasFocusColor);\n    }\n  }\n  \n  \/\/\u65e0\u7126\u70b9\u65f6\u5237\u65b0\u80cc\u666f\n  else\n  {\n    if(NULL != widget-&gt;noFocusImage)\n    {\n      DrawJPEG(widget-&gt;noFocusImage, widget-&gt;x, widget-&gt;y);\n    }\n    else\n    {\n      LCDFill(x0, y0, x1, y1, widget-&gt;noFocusColor);\n    }\n  }\n  \n  \/\/\u8ba1\u7b97\u5b57\u7b26\u4e32\u8d77\u70b9\u7684\u6a2a\u5750\u6807\u548c\u7eb5\u5750\u6807\n  x0 = widget-&gt;x;\n  y0 = widget-&gt;y + ((widget-&gt;height - widget-&gt;textSize) \/ 2);\n  \n  \/\/\u663e\u793a\u5b57\u7b26\u4e32\n  i = 0;\n  x = x0;\n  y = y0;\n  while(0 != widget-&gt;text[i])\n  {\n    LCDShowChar(x, y, widget-&gt;text[i], widget-&gt;textSize, 1);\n    x = x + (widget-&gt;textSize \/ 2);\n    i++;\n  }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%89%AB%E6%8F%8F%E5%87%BD%E6%95%B0\"><\/span>\u626b\u63cf\u51fd\u6570<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u626b\u63cf\u51fd\u6570\u5982\u4e0b\u6240\u793a\uff0c\u4e00\u65e6\u786e\u5b9a\u884c\u8f93\u5165\u6309\u952e\u6709\u88ab\u6309\u4e0b\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u5c06\u7126\u70b9\u6807\u5fd7\u4f4d\u8bbe\u4e3a 1 \uff0c\u6700\u540e\u8c03\u7528 UpdateShow \u66f4\u65b0\u663e\u793a\u5373\u53ef\u3002\u8fd9\u91cc\u7684\u8fd4\u56de\u503c\u53ea\u662f\u4e3a\u4e86\u901a\u77e5\u7528\u6237\u884c\u8f93\u5165\u63a7\u4ef6\u662f\u5426\u6709\u72b6\u6001\u6539\u53d8\uff0c\u7528\u6237\u53ef\u4ee5\u636e\u6b64\u89e3\u9664\u5176\u5b83\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u7126\u70b9\u72b6\u6001\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">u32 LineEditScan(StructLineEdit* widget)\n{\n  unsigned int x0, y0, x1, y1;\n  unsigned short tx, ty;\n  \n  \/\/\u5df2\u7ecf\u83b7\u5f97\u7126\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n  if(0 != widget-&gt;focus)\n  {\n    return 0;\n  }\n  \n  \/\/\u8ba1\u7b97\u63a7\u4ef6\u5750\u6807\u8303\u56f4\n  x0 = widget-&gt;x;\n  y0 = widget-&gt;y;\n  x1 = widget-&gt;x + widget-&gt;width - 1;\n  y1 = widget-&gt;y + widget-&gt;height - 1;\n  \n  \/\/\u83b7\u53d6\u89e6\u5c4f\u626b\u63cf\u7ed3\u679c\n  if(0 != ScanTouch(&amp;tx, &amp;ty))\n  {\n    \/\/\u68c0\u6d4b\u5230\u63a7\u4ef6\u88ab\u6309\u4e0b\n    if((tx &gt;= x0) &amp;&amp; (tx &lt;= x1) &amp;&amp; (ty &gt;= y0) &amp;&amp; (ty &lt;= y1))\n    {\n      \/\/\u6807\u8bb0\u83b7\u5f97\u4e86\u7126\u70b9\n      widget-&gt;focus = 1;\n      \n      \/\/\u5237\u65b0\u663e\u793a\n      UpdateShow(widget);\n      \n      \/\/\u8fd4\u56de\u72b6\u6001\u6539\u53d8\u4e86\n      return 1;\n    }\n  }\n  \n  \/\/\u8fd4\u56de\u72b6\u6001\u672a\u6539\u53d8\n  return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%B8%85%E9%99%A4%E7%84%A6%E7%82%B9%E5%87%BD%E6%95%B0\"><\/span>\u6e05\u9664\u7126\u70b9\u51fd\u6570<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u6e05\u9664\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u7126\u70b9\u72b6\u6001\u66f4\u4e3a\u7b80\u5355\uff0c\u53ea\u9700\u8981\u6e05\u7a7a\u6807\u5fd7\u4f4d\uff0c\u7136\u540e\u5237\u65b0\u663e\u793a\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">void LineEditRemoveFocus(StructLineEdit* widget)\n{\n  \/\/\u5f53\u524d\u5e76\u672a\u83b7\u5f97\u7126\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n  if(0 == widget-&gt;focus)\n  {\n    return;\n  }\n  \n  \/\/\u6807\u8bb0\u672a\u83b7\u5f97\u7126\u70b9\n  widget-&gt;focus = 0;\n  \n  \/\/\u5237\u65b0\u663e\u793a\n  UpdateShow(widget);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%BE%93%E5%85%A5%E5%87%BD%E6%95%B0\"><\/span>\u8f93\u5165\u51fd\u6570<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>LineEditAdd \u51fd\u6570\u7528\u4e8e\u5411\u884c\u8f93\u5165\u63a7\u4ef6\u6dfb\u52a0\u4e00\u4e2a\u8f93\u5165\uff0c\u5177\u4f53\u5b9a\u4e49\u5982\u4e0b\u6240\u793a\u3002\u9700\u8981\u6ce8\u610f\uff1a\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u9996\u4f4d\u4e24\u7aef\u9700\u8981\u9884\u7559\u81f3\u5c11\u4e00\u4e2a\u7a7a\u683c\u7684\u7a7a\u767d\u533a\u57df\uff0c\u4ee5\u514d\u5b57\u7b26\u663e\u793a\u8986\u76d6\u5230\u4e86\u8fb9\u6846\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">void LineEditAdd(StructLineEdit* widget, char code)\n{\n  unsigned int maxStringLen, stringLen;\n  \n  \/\/\u5f53\u524d\u5e76\u672a\u83b7\u5f97\u7126\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n  if(0 == widget-&gt;focus)\n  {\n    return;\n  }\n  \n  \/\/\u975e\u6cd5\u5b57\u7b26\uff0c\u76f4\u63a5\u8fd4\u56de\n  if(code &lt; ' ')\n  {\n    return;\n  }\n  \n  \/\/\u8ba1\u7b97\u884c\u7f16\u8f91\u63a7\u4ef6\u6700\u5927\u5b57\u7b26\u4e32\u957f\u5ea6\n  maxStringLen = widget-&gt;width \/ (widget-&gt;textSize \/ 2);\n  maxStringLen = maxStringLen - 1;\n  \n  \/\/\u7edf\u8ba1\u5f53\u524d\u5b57\u7b26\u4e32\u957f\u5ea6\n  stringLen = 0;\n  while(0 != widget-&gt;text[stringLen])\n  {\n    stringLen++;\n  }\n  \n  \/\/\u5b57\u7b26\u4e32\u957f\u5ea6\u5927\u4e8e\u7b49\u4e8e\u6700\u5927\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u76f4\u63a5\u8fd4\u56de\n  if(stringLen &gt;= maxStringLen)\n  {\n    return;\n  }\n  \n  \/\/\u5c06\u5b57\u7b26\u6dfb\u52a0\u5230\u5b57\u7b26\u4e32\u672b\u5c3e\n  widget-&gt;text[stringLen] = code;\n  widget-&gt;text[stringLen + 1] = 0;\n  \n  \/\/\u5237\u65b0\u663e\u793a\n  UpdateShow(widget);\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%88%A0%E9%99%A4%E5%87%BD%E6%95%B0\"><\/span>\u5220\u9664\u51fd\u6570<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>LineEditDelete \u51fd\u6570\u7528\u4e8e\u4ece\u672b\u5c3e\u5220\u9664\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u8f93\u5165\u7ed3\u679c\uff0c\u5177\u4f53\u5b9a\u4e49\u5982\u4e0b\u6240\u793a\u3002\u5728\u8fd9\u91cc\u8981\u6ce8\u610f\u4e0d\u8981\u8bef\u5220\u4e86\u6700\u524d\u8fb9\u9884\u7559\u7684\u7a7a\u683c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">void LineEditDelete(StructLineEdit* widget)\n{\n  unsigned int stringLen;\n  \n  \/\/\u5f53\u524d\u5e76\u672a\u83b7\u5f97\u7126\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n  if(0 == widget-&gt;focus)\n  {\n    return;\n  }\n  \n  \/\/\u7edf\u8ba1\u5b57\u7b26\u4e32\u957f\u5ea6\n  stringLen = 0;\n  while(0 != widget-&gt;text[stringLen])\n  {\n    stringLen++;\n  }\n  \n  \/\/\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\uff0c\u76f4\u63a5\u8fd4\u56de\uff0c\u7528\u4e8e\u4fdd\u62a4\u6700\u524d\u8fb9\u7684\u7a7a\u683c\n  if(1 == stringLen)\n  {\n    return;\n  }\n  \n  \/\/\u5220\u9664\u672b\u5c3e\u7684\u5b57\u7b26\n  widget-&gt;text[stringLen - 1] = 0;\n  \n  \/\/\u5237\u65b0\u663e\u793a\n  UpdateShow(widget);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%B5%8B%E8%AF%95%E4%BB%A3%E7%A0%81\"><\/span>\u6d4b\u8bd5\u4ee3\u7801<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u6d4b\u8bd5\u4ee3\u7801\u5982\u4e0b\uff0c\u56e0\u4e3a\u8fd9\u91cc\u6240\u6709\u7684\u63a7\u4ef6\u90fd\u9700\u8981\u505a\u89e6\u5c4f\u626b\u63cf\uff0c\u4ee5\u524d\u7684\u89e6\u5c4f\u626b\u63cf\u51fd\u6570\u6bcf\u8c03\u7528\u4e00\u6b21\u90fd\u4f1a\u89e6\u53d1 IIC \u4f20\u8f93\uff0c\u6548\u7387\u6781\u4f4e\uff0c\u6240\u4ee5\u4ee3\u7801\u5de5\u7a0b\u4e2d\u505a\u4e86\u4f18\u5316\uff0c\u65b0\u6dfb\u4e86\u89e6\u5c4f\u626b\u63cf\u4efb\u52a1\uff0c\u7528\u4e8e\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u505a\u4e00\u6b21\u89e6\u5c4f\u626b\u63cf\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">#include \"Button.h\"\n#include \"LineEdit.h\"\n\nint main(void)\n{\n  \/\/\u884c\u8f93\u5165\u63a7\u4ef6\n  static StructLineEdit s_structLineEdit1;\n  static StructLineEdit s_structLineEdit2;\n  \n  \/\/\u6309\u952e\u63a7\u4ef6\n  static StructButton s_structButton1Widget;\n  static StructButton s_structButton2Widget;\n  static StructButton s_structButton3Widget;\n  static StructButton s_structButton4Widget;\n  \n  \/\/\u521d\u59cb\u5316\n  InitHardware();   \/\/\u521d\u59cb\u5316\u786c\u4ef6\u76f8\u5173\n  InitSoftware();   \/\/\u521d\u59cb\u5316\u8f6f\u4ef6\u76f8\u5173\n\n  \/\/\u8bbe\u7f6e LCD \u521d\u59cb\u72b6\u6001\n  LCDDisplayDir(1);\n  LCDClear(WHITE);\n  \n  \/\/\u521b\u5efa\u884c\u8f93\u5165 1\n  s_structLineEdit1.x = 150;\n  s_structLineEdit1.y = 150;\n  s_structLineEdit1.width = 475;\n  s_structLineEdit1.height = 50;\n  s_structLineEdit1.textColor = WHITE;\n  s_structLineEdit1.textSize = 24;\n  s_structLineEdit1.hasFocusColor = GREEN;\n  s_structLineEdit1.noFocusColor = BLUE;\n  s_structLineEdit1.hasFocusImage = NULL;\n  s_structLineEdit1.noFocusImage = NULL;\n  CreateLineEdit(&amp;s_structLineEdit1);\n  \n  \/\/\u521b\u5efa\u884c\u8f93\u5165 2\n  s_structLineEdit2.x = s_structLineEdit1.x;\n  s_structLineEdit2.y = s_structLineEdit1.y + s_structLineEdit1.height + 25;\n  s_structLineEdit2.width = s_structLineEdit1.width;\n  s_structLineEdit2.height = s_structLineEdit1.height;\n  s_structLineEdit2.textColor = s_structLineEdit1.textColor;\n  s_structLineEdit2.textSize = s_structLineEdit1.textSize;\n  s_structLineEdit2.hasFocusColor = s_structLineEdit1.hasFocusColor;\n  s_structLineEdit2.noFocusColor = s_structLineEdit1.noFocusColor;\n  s_structLineEdit2.hasFocusImage = s_structLineEdit1.hasFocusImage;\n  s_structLineEdit2.noFocusImage = s_structLineEdit1.noFocusImage;\n  CreateLineEdit(&amp;s_structLineEdit2);\n  \n  \/\/\u6309\u952e 1 \u521d\u59cb\u5316\n  s_structButton1Widget.x = 150;\n  s_structButton1Widget.y = 340;\n  s_structButton1Widget.width = 100;\n  s_structButton1Widget.height = 50;\n  s_structButton1Widget.text = \"1\";\n  s_structButton1Widget.textColor = WHITE;\n  s_structButton1Widget.textSize = 24;\n  s_structButton1Widget.pressColor = GREEN;\n  s_structButton1Widget.releaseColor = BLUE;\n  s_structButton1Widget.pressImage = NULL;\n  s_structButton1Widget.releaseImage = NULL;\n  ButtonCreate(&amp;s_structButton1Widget);\n  \n  \/\/\u6309\u952e 2 \u521d\u59cb\u5316\n  s_structButton2Widget.x = s_structButton1Widget.x + s_structButton1Widget.width + 25;\n  s_structButton2Widget.y = s_structButton1Widget.y;\n  s_structButton2Widget.width = s_structButton1Widget.width;\n  s_structButton2Widget.height = s_structButton1Widget.height;\n  s_structButton2Widget.text = \"2\";\n  s_structButton2Widget.textColor = s_structButton1Widget.textColor;\n  s_structButton2Widget.textSize = s_structButton1Widget.textSize;\n  s_structButton2Widget.pressColor = s_structButton1Widget.pressColor;\n  s_structButton2Widget.releaseColor = s_structButton1Widget.releaseColor;\n  s_structButton2Widget.pressImage = s_structButton1Widget.pressImage;\n  s_structButton2Widget.releaseImage = s_structButton1Widget.releaseImage;\n  ButtonCreate(&amp;s_structButton2Widget);\n  \n  \/\/\u6309\u952e 3 \u521d\u59cb\u5316\n  s_structButton3Widget.x = s_structButton2Widget.x + s_structButton2Widget.width + 25;\n  s_structButton3Widget.y = s_structButton1Widget.y;\n  s_structButton3Widget.width = s_structButton1Widget.width;\n  s_structButton3Widget.height = s_structButton1Widget.height;\n  s_structButton3Widget.text = \"3\";\n  s_structButton3Widget.textColor = s_structButton1Widget.textColor;\n  s_structButton3Widget.textSize = s_structButton1Widget.textSize;\n  s_structButton3Widget.pressColor = s_structButton1Widget.pressColor;\n  s_structButton3Widget.releaseColor = s_structButton1Widget.releaseColor;\n  s_structButton3Widget.pressImage = s_structButton1Widget.pressImage;\n  s_structButton3Widget.releaseImage = s_structButton1Widget.releaseImage;\n  ButtonCreate(&amp;s_structButton3Widget);\n  \n  \/\/\u6309\u952e BACK \u521d\u59cb\u5316\n  s_structButton4Widget.x = s_structButton3Widget.x + s_structButton3Widget.width + 25;\n  s_structButton4Widget.y = s_structButton1Widget.y;\n  s_structButton4Widget.width = s_structButton1Widget.width;\n  s_structButton4Widget.height = s_structButton1Widget.height;\n  s_structButton4Widget.text = \"&lt;-\";\n  s_structButton4Widget.textColor = s_structButton1Widget.textColor;\n  s_structButton4Widget.textSize = s_structButton1Widget.textSize;\n  s_structButton4Widget.pressColor = s_structButton1Widget.pressColor;\n  s_structButton4Widget.releaseColor = s_structButton1Widget.releaseColor;\n  s_structButton4Widget.pressImage = s_structButton1Widget.pressImage;\n  s_structButton4Widget.releaseImage = s_structButton1Widget.releaseImage;\n  ButtonCreate(&amp;s_structButton4Widget);\n\n  while(1)\n  {\n    \/\/LED \u95ea\u70c1\n    LEDFlicker(10);\n    \n    \/\/\u89e6\u5c4f\u626b\u63cf\n    TouchScanTask();\n    \n    \/\/\u884c\u8f93\u5165 1 \u626b\u63cf\n    if(LineEditScan(&amp;s_structLineEdit1))\n    {\n      LineEditRemoveFocus(&amp;s_structLineEdit2);\n    }\n    \n    \/\/\u884c\u8f93\u5165 2 \u626b\u63cf\n    if(LineEditScan(&amp;s_structLineEdit2))\n    {\n      LineEditRemoveFocus(&amp;s_structLineEdit1);\n    }\n    \n    \/\/\u6309\u952e 1 \u626b\u63cf\n    if(ButtonScan(&amp;s_structButton1Widget))\n    {\n      LineEditAdd(&amp;s_structLineEdit1, '1');\n      LineEditAdd(&amp;s_structLineEdit2, '1');\n    }\n    \n    \/\/\u6309\u952e 2 \u626b\u63cf\n    if(ButtonScan(&amp;s_structButton2Widget))\n    {\n      LineEditAdd(&amp;s_structLineEdit1, '2');\n      LineEditAdd(&amp;s_structLineEdit2, '2');\n    }\n    \n    \/\/\u6309\u952e 3 \u626b\u63cf\n    if(ButtonScan(&amp;s_structButton3Widget))\n    {\n      LineEditAdd(&amp;s_structLineEdit1, '3');\n      LineEditAdd(&amp;s_structLineEdit2, '3');\n    }\n    \n    \/\/\u6309\u952e BACK \u626b\u63cf\n    if(ButtonScan(&amp;s_structButton4Widget))\n    {\n      LineEditDelete(&amp;s_structLineEdit1);\n      LineEditDelete(&amp;s_structLineEdit2);\n    }\n    \n    \/\/\u5ef6\u65f6 50 ms\n    DelayNms(50);\n  }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%AE%9E%E9%AA%8C%E7%BB%93%E6%9E%9C\"><\/span>\u5b9e\u9a8c\u7ed3\u679c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5b9e\u9a8c\u7ed3\u679c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"768\" src=\"http:\/\/www.huangrongzhen.ink\/wp-content\/uploads\/2023\/03\/\u5355\u7247\u673a-GUI-\u8bbe\u8ba1\uff08\u516d\uff09-\u884c\u8f93\u5165\u63a7\u4ef6-\u5b9e\u9a8c\u7ed3\u679c-20230304-1024x768.jpg\" alt=\"\" class=\"wp-image-1107\" srcset=\"https:\/\/www.huangrongzhen.ink\/wp-content\/uploads\/2023\/03\/\u5355\u7247\u673a-GUI-\u8bbe\u8ba1\uff08\u516d\uff09-\u884c\u8f93\u5165\u63a7\u4ef6-\u5b9e\u9a8c\u7ed3\u679c-20230304-1024x768.jpg 1024w, https:\/\/www.huangrongzhen.ink\/wp-content\/uploads\/2023\/03\/\u5355\u7247\u673a-GUI-\u8bbe\u8ba1\uff08\u516d\uff09-\u884c\u8f93\u5165\u63a7\u4ef6-\u5b9e\u9a8c\u7ed3\u679c-20230304-300x225.jpg 300w, https:\/\/www.huangrongzhen.ink\/wp-content\/uploads\/2023\/03\/\u5355\u7247\u673a-GUI-\u8bbe\u8ba1\uff08\u516d\uff09-\u884c\u8f93\u5165\u63a7\u4ef6-\u5b9e\u9a8c\u7ed3\u679c-20230304-768x576.jpg 768w, https:\/\/www.huangrongzhen.ink\/wp-content\/uploads\/2023\/03\/\u5355\u7247\u673a-GUI-\u8bbe\u8ba1\uff08\u516d\uff09-\u884c\u8f93\u5165\u63a7\u4ef6-\u5b9e\u9a8c\u7ed3\u679c-20230304-1536x1152.jpg 1536w, https:\/\/www.huangrongzhen.ink\/wp-content\/uploads\/2023\/03\/\u5355\u7247\u673a-GUI-\u8bbe\u8ba1\uff08\u516d\uff09-\u884c\u8f93\u5165\u63a7\u4ef6-\u5b9e\u9a8c\u7ed3\u679c-20230304-2048x1536.jpg 2048w, https:\/\/www.huangrongzhen.ink\/wp-content\/uploads\/2023\/03\/\u5355\u7247\u673a-GUI-\u8bbe\u8ba1\uff08\u516d\uff09-\u884c\u8f93\u5165\u63a7\u4ef6-\u5b9e\u9a8c\u7ed3\u679c-20230304-400x300.jpg 400w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%80%BB%E7%BB%93\"><\/span>\u603b\u7ed3<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u7528\u94fe\u8868\u7684\u5f62\u5f0f\u7ec4\u7ec7\u884c\u8f93\u5165\u63a7\u4ef6\uff0c\u4e3a\u884c\u8f93\u5165\u63a7\u4ef6\u5206\u7ec4\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u5f53\u4e00\u4e2a\u884c\u8f93\u5165\u63a7\u4ef6\u83b7\u5f97\u7126\u70b9\u540e\uff0c\u53e6\u4e00\u4e2a\u5c06\u81ea\u52a8\u5931\u53bb\u7126\u70b9\uff0c\u5c31\u4e0d\u7528\u7528\u6237\u81ea\u5df1\u53bb\u7ba1\u7406\u6bcf\u4e2a\u884c\u8f93\u5165\u63a7\u4ef6\u7684\u72b6\u6001\u4e86\u3002\u540c\u65f6\uff0c\u5f80\u884c\u8f93\u5165\u63a7\u4ef6\u5199\u5165\u6216\u5220\u9664\u65f6\uff0c\u53ef\u4ee5\u76f4\u63a5\u9488\u5bf9\u63a7\u4ef6\u5206\u7ec4\u8fdb\u884c\u3002\u5728\u5199\u5165\/\u5220\u9664\u51fd\u6570\u4e2d\uff0c\u904d\u5386\u94fe\u8868\uff0c\u67e5\u627e\u51fa\u5177\u6709\u7126\u70b9\u7684\u63a7\u4ef6\uff0c\u5e76\u66f4\u65b0\u72b6\u6001\uff0c\u8fd9\u6837\u7528\u6237\u5c31\u65e0\u9700\u591a\u6b21\u8c03\u7528\u5199\u5165\/\u5220\u9664\u51fd\u6570\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%BA%90%E7%A0%81\"><\/span>\u6e90\u7801<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u672c\u7ae0\u8282\u4e2d\u7684\u6e90\u7801\u8bf7\u53c2\u8003\u300a<em><a href=\"http:\/\/www.huangrongzhen.ink\/?p=451\">\u5355\u7247\u673a GUI \u8bbe\u8ba1\uff08\u96f6\uff09- \u5927\u7eb2<\/a><\/em>\u300b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8e GD32F303ZET6 \u82f9\u679c\u6d3e\u5f00\u53d1\u677f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"_links":{"self":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts\/668"}],"collection":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=668"}],"version-history":[{"count":22,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts\/668\/revisions"}],"predecessor-version":[{"id":1140,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts\/668\/revisions\/1140"}],"wp:attachment":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}