button support enable_preview prop

This commit is contained in:
lixianjing 2022-09-30 11:37:24 +08:00
parent e2f5dc1509
commit c5f1fee044
7 changed files with 1125 additions and 922 deletions

View File

@ -2,216 +2,216 @@
<pages x="0" y="bottom" w="100%" h="-28" active="4">
<view name="upper" x="0" y="0" w="100%" h="100%" children_layout="default(r=4,c=1,s=2,m=2)">
<group_box children_layout="default(r=1,c=10,s=2,m=2)">
<button repeat="300" name="Q" text="Q"/>
<button repeat="300" name="W" text="W"/>
<button repeat="300" name="E" text="E"/>
<button repeat="300" name="R" text="R"/>
<button repeat="300" name="T" text="T"/>
<button repeat="300" name="Y" text="Y"/>
<button repeat="300" name="U" text="U"/>
<button repeat="300" name="I" text="I"/>
<button repeat="300" name="O" text="O"/>
<button repeat="300" name="P" text="P"/>
<button name="Q" enable_preview="true" text="Q"/>
<button name="W" enable_preview="true" text="W"/>
<button name="E" enable_preview="true" text="E"/>
<button name="R" enable_preview="true" text="R"/>
<button name="T" enable_preview="true" text="T"/>
<button name="Y" enable_preview="true" text="Y"/>
<button name="U" enable_preview="true" text="U"/>
<button name="I" enable_preview="true" text="I"/>
<button name="O" enable_preview="true" text="O"/>
<button name="P" enable_preview="true" text="P"/>
</group_box>
<group_box children_layout="default(r=1,c=9,s=2,xm=10,ym=2)">
<button repeat="300" name="A" text="A"/>
<button repeat="300" name="S" text="S"/>
<button repeat="300" name="D" text="D"/>
<button repeat="300" name="F" text="F"/>
<button repeat="300" name="G" text="G"/>
<button repeat="300" name="H" text="H"/>
<button repeat="300" name="J" text="J"/>
<button repeat="300" name="K" text="K"/>
<button repeat="300" name="L" text="L"/>
<button name="A" enable_preview="true" text="A"/>
<button name="S" enable_preview="true" text="S"/>
<button name="D" enable_preview="true" text="D"/>
<button name="F" enable_preview="true" text="F"/>
<button name="G" enable_preview="true" text="G"/>
<button name="H" enable_preview="true" text="H"/>
<button name="J" enable_preview="true" text="J"/>
<button name="K" enable_preview="true" text="K"/>
<button name="L" enable_preview="true" text="L"/>
</group_box>
<group_box children_layout="default(r=1,c=9,s=2,m=2)">
<button name="page:lower"><image draw_type="icon" image="shifton" x="center" y="middle" w="100%" h="100%"/></button>
<button repeat="300" name="Z" text="Z"/>
<button repeat="300" name="X" text="X"/>
<button repeat="300" name="C" text="C"/>
<button repeat="300" name="V" text="V"/>
<button repeat="300" name="B" text="B"/>
<button repeat="300" name="N" text="N"/>
<button repeat="300" name="M" text="M"/>
<button repeat="300" name="key:backspace" style="highlight"><image draw_type="icon" image="backspace" x="center" y="middle" w="100%" h="100%"/></button>
<button name="Z" enable_preview="true" text="Z"/>
<button name="X" enable_preview="true" text="X"/>
<button name="C" enable_preview="true" text="C"/>
<button name="V" enable_preview="true" text="V"/>
<button name="B" enable_preview="true" text="B"/>
<button name="N" enable_preview="true" text="N"/>
<button name="M" enable_preview="true" text="M"/>
<button name="key:backspace" style="highlight"><image draw_type="icon" image="backspace" x="center" y="middle" w="100%" h="100%"/></button>
</group_box>
<group_box children_layout="default(r=1,c=0,s=2,m=2)">
<button name="page:symnum" style="highlight" w="15%" text="123"/>
<button name="page:symnum" style="highlight" w="15%" enable_preview="true" text="123"/>
<button name="page:chinese" style="highlight" w="10%"><image draw_type="icon" image="zh" x="center" y="middle" w="100%" h="100%"/></button>
<button repeat="300" name="space" w="55%" text="Space"/>
<button name="action" style="highlight" w="20%" text="Return"/>
<button name="space" w="55%" enable_preview="true" text="Space"/>
<button name="action" style="highlight" w="20%" enable_preview="true" text="Return"/>
</group_box>
</view>
<view name="lower" x="0" y="0" w="100%" h="100%" children_layout="default(r=4,c=1,s=2,m=2)">
<group_box children_layout="default(r=1,c=10,s=2,m=2)">
<button repeat="300" name="q" text="q"/>
<button repeat="300" name="w" text="w"/>
<button repeat="300" name="e" text="e"/>
<button repeat="300" name="r" text="r"/>
<button repeat="300" name="t" text="t"/>
<button repeat="300" name="y" text="y"/>
<button repeat="300" name="u" text="u"/>
<button repeat="300" name="i" text="i"/>
<button repeat="300" name="o" text="o"/>
<button repeat="300" name="p" text="p"/>
<button name="q" enable_preview="true" text="q"/>
<button name="w" enable_preview="true" text="w"/>
<button name="e" enable_preview="true" text="e"/>
<button name="r" enable_preview="true" text="r"/>
<button name="t" enable_preview="true" text="t"/>
<button name="y" enable_preview="true" text="y"/>
<button name="u" enable_preview="true" text="u"/>
<button name="i" enable_preview="true" text="i"/>
<button name="o" enable_preview="true" text="o"/>
<button name="p" enable_preview="true" text="p"/>
</group_box>
<group_box children_layout="default(r=1,c=9,s=2,xm=10,ym=2)">
<button repeat="300" name="a" text="a"/>
<button repeat="300" name="s" text="s"/>
<button repeat="300" name="d" text="d"/>
<button repeat="300" name="f" text="f"/>
<button repeat="300" name="g" text="g"/>
<button repeat="300" name="h" text="h"/>
<button repeat="300" name="j" text="j"/>
<button repeat="300" name="k" text="k"/>
<button repeat="300" name="l" text="l"/>
<button name="a" enable_preview="true" text="a"/>
<button name="s" enable_preview="true" text="s"/>
<button name="d" enable_preview="true" text="d"/>
<button name="f" enable_preview="true" text="f"/>
<button name="g" enable_preview="true" text="g"/>
<button name="h" enable_preview="true" text="h"/>
<button name="j" enable_preview="true" text="j"/>
<button name="k" enable_preview="true" text="k"/>
<button name="l" enable_preview="true" text="l"/>
</group_box>
<group_box children_layout="default(r=1,c=9,s=2,m=2)">
<button name="page:upper" style="highlight"><image draw_type="icon" image="shift" x="center" y="middle" w="100%" h="100%"/></button>
<button repeat="300" name="z" text="z"/>
<button repeat="300" name="x" text="x"/>
<button repeat="300" name="c" text="c"/>
<button repeat="300" name="v" text="v"/>
<button repeat="300" name="b" text="b"/>
<button repeat="300" name="n" text="n"/>
<button repeat="300" name="m" text="m"/>
<button repeat="300" name="key:backspace" style="highlight"><image draw_type="icon" image="backspace" x="center" y="middle" w="100%" h="100%"/></button>
<button name="z" enable_preview="true" text="z"/>
<button name="x" enable_preview="true" text="x"/>
<button name="c" enable_preview="true" text="c"/>
<button name="v" enable_preview="true" text="v"/>
<button name="b" enable_preview="true" text="b"/>
<button name="n" enable_preview="true" text="n"/>
<button name="m" enable_preview="true" text="m"/>
<button name="key:backspace" style="highlight"><image draw_type="icon" image="backspace" x="center" y="middle" w="100%" h="100%"/></button>
</group_box>
<group_box children_layout="default(r=1,c=0,s=2,m=2)">
<button name="page:symnum" style="highlight" w="15%" text="123"/>
<button name="page:symnum" style="highlight" w="15%" enable_preview="true" text="123"/>
<button name="page:chinese" style="highlight" w="10%"><image draw_type="icon" image="zh" x="center" y="middle" w="100%" h="100%"/></button>
<button repeat="300" name="space" w="55%" text="Space"/>
<button name="action" style="highlight" w="20%" text="Return"/>
<button name="space" w="55%" enable_preview="true" text="Space"/>
<button name="action" style="highlight" w="20%" enable_preview="true" text="Return"/>
</group_box>
</view>
<view name="symnum" x="0" y="0" w="100%" h="100%" children_layout="default(r=4,c=1,s=2,m=2)">
<group_box children_layout="default(r=1,c=10,s=2,m=2)">
<button repeat="300" name="1" text="1"/>
<button repeat="300" name="2" text="2"/>
<button repeat="300" name="3" text="3"/>
<button repeat="300" name="4" text="4"/>
<button repeat="300" name="5" text="5"/>
<button repeat="300" name="6" text="6"/>
<button repeat="300" name="7" text="7"/>
<button repeat="300" name="8" text="8"/>
<button repeat="300" name="9" text="9"/>
<button repeat="300" name="0" text="0"/>
<button name="1" enable_preview="true" text="1"/>
<button name="2" enable_preview="true" text="2"/>
<button name="3" enable_preview="true" text="3"/>
<button name="4" enable_preview="true" text="4"/>
<button name="5" enable_preview="true" text="5"/>
<button name="6" enable_preview="true" text="6"/>
<button name="7" enable_preview="true" text="7"/>
<button name="8" enable_preview="true" text="8"/>
<button name="9" enable_preview="true" text="9"/>
<button name="0" enable_preview="true" text="0"/>
</group_box>
<group_box children_layout="default(r=1,c=10,s=2,xm=10,ym=2)">
<button repeat="300" name="-" text="-"/>
<button repeat="300" name="/" text="/"/>
<button repeat="300" name=":" text=":"/>
<button repeat="300" name=";" text=";"/>
<button repeat="300" name="(" text="("/>
<button repeat="300" name=")" text=")"/>
<button repeat="300" name="$" text="$"/>
<button repeat="300" name="@" text="@"/>
<button repeat="300" name="'" text="'"/>
<button repeat="300" name="&quot;" text="&quot;"/>
<button name="-" enable_preview="true" text="-"/>
<button name="/" enable_preview="true" text="/"/>
<button name=":" enable_preview="true" text=":"/>
<button name=";" enable_preview="true" text=";"/>
<button name="(" enable_preview="true" text="("/>
<button name=")" enable_preview="true" text=")"/>
<button name="$" enable_preview="true" text="$"/>
<button name="@" enable_preview="true" text="@"/>
<button name="'" enable_preview="true" text="'"/>
<button name="&quot;" enable_preview="true" text="&quot;"/>
</group_box>
<group_box children_layout="default(r=1,c=10,s=2,m=2)">
<button name="page:symbol" style="highlight" text="#+="/>
<button repeat="300" name="." text="."/>
<button repeat="300" name="," text=","/>
<button repeat="300" name="\" text="\"/>
<button repeat="300" name="?" text="?"/>
<button repeat="300" name="!" text="!"/>
<button repeat="300" name="<" text="<"/>
<button repeat="300" name=">" text=">"/>
<button repeat="300" name="#" text="#"/>
<button repeat="300" name="key:backspace" style="highlight"><image draw_type="icon" image="backspace" x="center" y="middle" w="100%" h="100%"/></button>
<button name="page:symbol" style="highlight" enable_preview="true" text="#+="/>
<button name="." enable_preview="true" text="."/>
<button name="," enable_preview="true" text=","/>
<button name="\" enable_preview="true" text="\"/>
<button name="?" enable_preview="true" text="?"/>
<button name="!" enable_preview="true" text="!"/>
<button name="<" enable_preview="true" text="<"/>
<button name=">" enable_preview="true" text=">"/>
<button name="#" enable_preview="true" text="#"/>
<button name="key:backspace" style="highlight"><image draw_type="icon" image="backspace" x="center" y="middle" w="100%" h="100%"/></button>
</group_box>
<group_box children_layout="default(r=1,c=0,s=2,m=2)">
<button name="page:upper" style="highlight" w="15%" text="ABC"/>
<button repeat="300" name="page:chinese" style="highlight" w="10%"><image draw_type="icon" image="zh" x="center" y="middle" w="100%" h="100%"/></button>
<button repeat="300" name="space" w="55%" text="Space"/>
<button name="action" style="highlight" w="20%" text="Return"/>
<button name="page:upper" style="highlight" w="15%" enable_preview="true" text="ABC"/>
<button name="page:chinese" style="highlight" w="10%"><image draw_type="icon" image="zh" x="center" y="middle" w="100%" h="100%"/></button>
<button name="space" w="55%" enable_preview="true" text="Space"/>
<button name="action" style="highlight" w="20%" enable_preview="true" text="Return"/>
</group_box>
</view>
<view name="symbol" x="0" y="0" w="100%" h="100%" children_layout="default(r=4,c=1,s=2,m=2)">
<group_box children_layout="default(r=1,c=10,s=2,m=2)">
<button repeat="300" name="[" text="["/>
<button repeat="300" name="]" text="]"/>
<button repeat="300" name="{" text="{"/>
<button repeat="300" name="}" text="}"/>
<button repeat="300" name="#" text="#"/>
<button repeat="300" name="%" text="%"/>
<button repeat="300" name="^" text="^"/>
<button repeat="300" name="*" text="*"/>
<button repeat="300" name="+" text="+"/>
<button repeat="300" name="=" text="="/>
<button name="[" enable_preview="true" text="["/>
<button name="]" enable_preview="true" text="]"/>
<button name="{" enable_preview="true" text="{"/>
<button name="}" enable_preview="true" text="}"/>
<button name="#" enable_preview="true" text="#"/>
<button name="%" enable_preview="true" text="%"/>
<button name="^" enable_preview="true" text="^"/>
<button name="*" enable_preview="true" text="*"/>
<button name="+" enable_preview="true" text="+"/>
<button name="=" enable_preview="true" text="="/>
</group_box>
<group_box children_layout="default(r=1,c=9,s=2,xm=10,ym=2)">
<button repeat="300" name="_" text="_"/>
<button repeat="300" name="\" text="\"/>
<button repeat="300" name="|" text="|"/>
<button repeat="300" name="~" text="~"/>
<button repeat="300" name="<" text="<"/>
<button repeat="300" name=">" text=">"/>
<button repeat="300" name="$" text="$"/>
<button repeat="300" name="@" text="@"/>
<button repeat="300" name="`" text="`"/>
<button name="_" enable_preview="true" text="_"/>
<button name="\" enable_preview="true" text="\"/>
<button name="|" enable_preview="true" text="|"/>
<button name="~" enable_preview="true" text="~"/>
<button name="<" enable_preview="true" text="<"/>
<button name=">" enable_preview="true" text=">"/>
<button name="$" enable_preview="true" text="$"/>
<button name="@" enable_preview="true" text="@"/>
<button name="`" enable_preview="true" text="`"/>
</group_box>
<group_box children_layout="default(r=1,c=8,s=2,m=2)">
<button name="page:symnum" style="highlight" text="123"/>
<button repeat="300" name="." text="."/>
<button repeat="300" name="," text=","/>
<button repeat="300" name="?" text="?"/>
<button repeat="300" name="!" text="!"/>
<button repeat="300" name="'" text="'"/>
<button repeat="300" name="&quot;" text="&quot;"/>
<button repeat="300" name="key:backspace" style="highlight"><image draw_type="icon" image="backspace" x="center" y="middle" w="100%" h="100%"/></button>
<button name="page:symnum" style="highlight" enable_preview="true" text="123"/>
<button name="." enable_preview="true" text="."/>
<button name="," enable_preview="true" text=","/>
<button name="?" enable_preview="true" text="?"/>
<button name="!" enable_preview="true" text="!"/>
<button name="'" enable_preview="true" text="'"/>
<button name="&quot;" enable_preview="true" text="&quot;"/>
<button name="key:backspace" style="highlight"><image draw_type="icon" image="backspace" x="center" y="middle" w="100%" h="100%"/></button>
</group_box>
<group_box children_layout="default(r=1,c=0,s=2,m=2)">
<button name="page:upper" style="highlight" w="15%" text="ABC"/>
<button name="page:upper" style="highlight" w="15%" enable_preview="true" text="ABC"/>
<button name="page:chinese" style="highlight" w="10%"><image draw_type="icon" image="zh" x="center" y="middle" w="100%" h="100%"/></button>
<button repeat="300" name="space" w="55%" text="Space"/>
<button name="action" style="highlight" w="20%" text="Return"/>
<button name="space" w="55%" enable_preview="true" text="Space"/>
<button name="action" style="highlight" w="20%" enable_preview="true" text="Return"/>
</group_box>
</view>
<view name="chinese" x="0" y="0" w="100%" h="100%" children_layout="default(r=4,c=1,s=2,m=2)">
<group_box children_layout="default(r=1,c=10,s=2,m=2)">
<button repeat="300" name="key:q" text="q"/>
<button repeat="300" name="key:w" text="w"/>
<button repeat="300" name="key:e" text="e"/>
<button repeat="300" name="key:r" text="r"/>
<button repeat="300" name="key:t" text="t"/>
<button repeat="300" name="key:y" text="y"/>
<button repeat="300" name="key:u" text="u"/>
<button repeat="300" name="key:i" text="i"/>
<button repeat="300" name="key:o" text="o"/>
<button repeat="300" name="key:p" text="p"/>
<button name="key:q" enable_preview="true" text="q"/>
<button name="key:w" enable_preview="true" text="w"/>
<button name="key:e" enable_preview="true" text="e"/>
<button name="key:r" enable_preview="true" text="r"/>
<button name="key:t" enable_preview="true" text="t"/>
<button name="key:y" enable_preview="true" text="y"/>
<button name="key:u" enable_preview="true" text="u"/>
<button name="key:i" enable_preview="true" text="i"/>
<button name="key:o" enable_preview="true" text="o"/>
<button name="key:p" enable_preview="true" text="p"/>
</group_box>
<group_box children_layout="default(r=1,c=9,s=2,xm=10,ym=2)">
<button repeat="300" name="key:a" text="a"/>
<button repeat="300" name="key:s" text="s"/>
<button repeat="300" name="key:d" text="d"/>
<button repeat="300" name="key:f" text="f"/>
<button repeat="300" name="key:g" text="g"/>
<button repeat="300" name="key:h" text="h"/>
<button repeat="300" name="key:j" text="j"/>
<button repeat="300" name="key:k" text="k"/>
<button repeat="300" name="key:l" text="l"/>
<button name="key:a" enable_preview="true" text="a"/>
<button name="key:s" enable_preview="true" text="s"/>
<button name="key:d" enable_preview="true" text="d"/>
<button name="key:f" enable_preview="true" text="f"/>
<button name="key:g" enable_preview="true" text="g"/>
<button name="key:h" enable_preview="true" text="h"/>
<button name="key:j" enable_preview="true" text="j"/>
<button name="key:k" enable_preview="true" text="k"/>
<button name="key:l" enable_preview="true" text="l"/>
</group_box>
<group_box children_layout="default(r=1,c=9,s=2,m=2)">
<button name="page:upper" style="highlight"><image draw_type="icon" image="shift" x="center" y="middle" w="100%" h="100%"/></button>
<button repeat="300" name="key:z" text="z"/>
<button repeat="300" name="key:x" text="x"/>
<button repeat="300" name="key:c" text="c"/>
<button repeat="300" name="key:v" text="v"/>
<button repeat="300" name="key:b" text="b"/>
<button repeat="300" name="key:n" text="n"/>
<button repeat="300" name="key:m" text="m"/>
<button repeat="300" name="key:backspace" style="highlight"><image draw_type="icon" image="backspace" x="center" y="middle" w="100%" h="100%"/></button>
<button name="key:z" enable_preview="true" text="z"/>
<button name="key:x" enable_preview="true" text="x"/>
<button name="key:c" enable_preview="true" text="c"/>
<button name="key:v" enable_preview="true" text="v"/>
<button name="key:b" enable_preview="true" text="b"/>
<button name="key:n" enable_preview="true" text="n"/>
<button name="key:m" enable_preview="true" text="m"/>
<button name="key:backspace" style="highlight"><image draw_type="icon" image="backspace" x="center" y="middle" w="100%" h="100%"/></button>
</group_box>
<group_box children_layout="default(r=1,c=0,s=2,m=2)">
<button name="page:symnum" style="highlight" w="15%" text="123"/>
<button name="page:symnum" style="highlight" w="15%" enable_preview="true" text="123"/>
<button name="page:lower" style="highlight" w="10%"><image draw_type="icon" image="en" x="center" y="middle" w="100%" h="100%"/></button>
<button repeat="300" name="space" w="55%" text="Space"/>
<button name="action" style="highlight" w="20%" text="Return"/>
<button name="space" w="55%" enable_preview="true" text="Space"/>
<button name="action" style="highlight" w="20%" enable_preview="true" text="Return"/>
</group_box>
</view>
</pages>
<candidates x="0" y="0" w="100%" h="30"/>
<button name="close" style="close" self_layout="default(x=r:2, y=2, w=20, h=20)" text="x" />
<button name="close" style="close" self_layout="default(x=r:2, y=2, w=20, h=20)" enable_preview="true" text="x" />
</keyboard>

View File

@ -1,5 +1,8 @@
# 最新动态
2022/09/30
* 按钮增加enable_preview属性用于键盘中按钮preview。
2022/09/29
* 支持设置自定义键值(感谢兆坤提供补丁)

File diff suppressed because it is too large Load Diff

View File

@ -761,6 +761,12 @@ BEGIN_C_DECLS
*/
#define WIDGET_PROP_ENABLE_LONG_PRESS "enable_long_press"
/**
* @const WIDGET_PROP_ENABLE_PREVIEW
*
*/
#define WIDGET_PROP_ENABLE_PREVIEW "enable_preview"
/**
* @const WIDGET_PROP_CLICK_THROUGH
* 穿

View File

@ -83,6 +83,11 @@ static ret_t button_pointer_up_cleanup_impl(widget_t* widget, bool_t ungrab) {
}
widget_set_state(widget, WIDGET_STATE_NORMAL);
if (button->enable_preview) {
widget_t* wm = widget_get_window_manager(widget);
widget_off_by_ctx(wm, widget);
}
return RET_OK;
}
@ -101,6 +106,80 @@ static ret_t button_on_long_press(const timer_info_t* info) {
return RET_REMOVE;
}
#define TK_BUTTON_PREVIEW_SCALE 1.6
static ret_t button_invalidate(widget_t* widget, const rect_t* rect) {
button_t* button = BUTTON(widget);
return_value_if_fail(button != NULL, RET_BAD_PARAMS);
if (button->enable_preview) {
rect_t r;
widget_t* wm = widget_get_window_manager(widget);
int32_t w = widget->w * (1 + TK_BUTTON_PREVIEW_SCALE);
int32_t h = widget->h * (1 + TK_BUTTON_PREVIEW_SCALE);
int32_t x = -(w - widget->w) / 2;
int32_t y = -h;
point_t p = {x, y};
widget_to_screen(widget, &p);
r = rect_init(p.x, p.y, w, h);
widget_invalidate_force(wm, &r);
}
return widget_invalidate_default(widget, rect);
}
static ret_t button_draw_preview(void* ctx, event_t* e) {
rect_t r;
widget_t* widget = WIDGET(ctx);
point_t p = {0, 0};
paint_event_t* evt = paint_event_cast(e);
int32_t w = widget->w * TK_BUTTON_PREVIEW_SCALE;
int32_t h = widget->h * TK_BUTTON_PREVIEW_SCALE;
canvas_t* c = evt->c;
int32_t ox = c->ox;
int32_t oy = c->oy;
int32_t x = 0;
int32_t y = 0;
style_t* style = widget->astyle;
color_t trans = color_init(0, 0, 0, 0xd0);
color_t bg_color = style_get_color(style, STYLE_ID_BG_COLOR, trans);
color_t border_color = style_get_color(style, STYLE_ID_BORDER_COLOR, trans);
color_t text_color = style_get_color(style, STYLE_ID_TEXT_COLOR, trans);
int32_t font_size = style_get_int(style, STYLE_ID_FONT_SIZE, TK_DEFAULT_FONT_SIZE);
const char* font = style_get_str(style, STYLE_ID_FONT_NAME, NULL);
int32_t wox = style_get_int(widget->astyle, STYLE_ID_X_OFFSET, 0);
int32_t woy = style_get_int(widget->astyle, STYLE_ID_Y_OFFSET, 0);
widget_to_screen(widget, &p);
canvas_untranslate(c, ox, oy);
y = p.y - h + 1;
x = p.x - (w - widget->w) / 2;
r = rect_init(x, y, w, h);
canvas_set_fill_color(c, bg_color);
canvas_fill_rect(c, r.x, r.y, r.w, r.h);
canvas_set_text_color(c, text_color);
canvas_set_font(c, font, font_size * TK_BUTTON_PREVIEW_SCALE);
canvas_draw_text_in_rect(c, widget->text.str, widget->text.size, &r);
canvas_set_stroke_color(c, border_color);
canvas_stroke_rect(c, r.x, r.y, r.w, r.h);
p.x = wox;
p.y = woy;
widget_to_screen(widget, &p);
r = rect_init(p.x, p.y - 4, widget->w, widget->h + 4);
widget_fill_bg_rect(widget, c, &r, IMAGE_DRAW_CENTER);
canvas_translate(c, ox, oy);
return RET_OK;
}
static ret_t button_on_event(widget_t* widget, event_t* e) {
uint16_t type = e->type;
button_t* button = BUTTON(widget);
@ -121,6 +200,12 @@ static ret_t button_on_event(widget_t* widget, event_t* e) {
}
widget_grab(widget->parent, widget);
if (button->enable_preview) {
widget_t* wm = widget_get_window_manager(widget);
widget_on(wm, EVT_AFTER_PAINT, button_draw_preview, widget);
}
break;
}
case EVT_BLUR:
@ -186,6 +271,15 @@ ret_t button_set_enable_long_press(widget_t* widget, bool_t enable_long_press) {
return RET_OK;
}
ret_t button_set_enable_preview(widget_t* widget, bool_t enable_preview) {
button_t* button = BUTTON(widget);
return_value_if_fail(button != NULL, RET_BAD_PARAMS);
button->enable_preview = enable_preview;
return RET_OK;
}
static ret_t button_get_prop(widget_t* widget, const char* name, value_t* v) {
button_t* button = BUTTON(widget);
return_value_if_fail(button != NULL && name != NULL && v != NULL, RET_BAD_PARAMS);
@ -199,6 +293,9 @@ static ret_t button_get_prop(widget_t* widget, const char* name, value_t* v) {
} else if (tk_str_eq(name, WIDGET_PROP_ENABLE_LONG_PRESS)) {
value_set_bool(v, button->enable_long_press);
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_ENABLE_PREVIEW)) {
value_set_bool(v, button->enable_preview);
return RET_OK;
}
return RET_NOT_FOUND;
@ -216,6 +313,9 @@ static ret_t button_get_prop_default_value(widget_t* widget, const char* name, v
} else if (tk_str_eq(name, WIDGET_PROP_ENABLE_LONG_PRESS)) {
value_set_bool(v, FALSE);
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_ENABLE_PREVIEW)) {
value_set_bool(v, FALSE);
return RET_OK;
}
return RET_NOT_FOUND;
@ -230,6 +330,8 @@ static ret_t button_set_prop(widget_t* widget, const char* name, const value_t*
return button_set_long_press_time(widget, value_int(v));
} else if (tk_str_eq(name, WIDGET_PROP_ENABLE_LONG_PRESS)) {
return button_set_enable_long_press(widget, value_bool(v));
} else if (tk_str_eq(name, WIDGET_PROP_ENABLE_PREVIEW)) {
return button_set_enable_preview(widget, value_bool(v));
}
return RET_NOT_FOUND;
@ -276,6 +378,7 @@ TK_DECL_VTABLE(button) = {.size = sizeof(button_t),
.return_key_to_activate = TRUE,
.parent = TK_PARENT_VTABLE(widget),
.create = button_create,
.invalidate = button_invalidate,
.clone_properties = s_button_properties,
.persistent_properties = s_button_properties,
.on_event = button_on_event,

View File

@ -98,6 +98,15 @@ typedef struct _button_t {
*/
bool_t enable_long_press;
/**
* @property {bool_t} enable_preview
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
* ()
*
*
*/
bool_t enable_preview;
/**
* @property {uint32_t} long_press_time
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
@ -186,6 +195,17 @@ ret_t button_set_long_press_time(widget_t* widget, uint32_t long_press_time);
*/
ret_t button_set_enable_long_press(widget_t* widget, bool_t enable_long_press);
/**
* @method button_set_enable_preview
*
* @annotation ["scriptable"]
* @param {widget_t*} widget
* @param {bool_t} enable_preview
*
* @return {ret_t} RET_OK表示成功
*/
ret_t button_set_enable_preview(widget_t* widget, bool_t enable_preview);
#define BUTTON(widget) ((button_t*)(button_cast(WIDGET(widget))))
/*public for subclass and runtime type check*/