improve label

This commit is contained in:
lixianjing 2020-06-02 07:59:23 +08:00
parent 34f673133a
commit af78c31978
2 changed files with 20 additions and 2 deletions

View File

@ -228,7 +228,12 @@ static ret_t label_get_prop(widget_t* widget, const char* name, value_t* v) {
label_t* label = LABEL(widget);
return_value_if_fail(label != NULL && name != NULL && v != NULL, RET_BAD_PARAMS);
if (tk_str_eq(name, WIDGET_PROP_LENGTH)) {
if (tk_str_eq(name, WIDGET_PROP_VALUE)) {
double d = 0;
wstr_to_float(&(widget->text), &d);
value_set_double(v, d);
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_LENGTH)) {
value_set_int(v, label->length);
return RET_OK;
}
@ -239,7 +244,9 @@ static ret_t label_get_prop(widget_t* widget, const char* name, value_t* v) {
static ret_t label_set_prop(widget_t* widget, const char* name, const value_t* v) {
return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS);
if (tk_str_eq(name, WIDGET_PROP_LENGTH)) {
if (tk_str_eq(name, WIDGET_PROP_VALUE)) {
return wstr_from_value(&(widget->text), v);
} else if (tk_str_eq(name, WIDGET_PROP_LENGTH)) {
return label_set_length(widget, tk_roundi(value_float(v)));
}

View File

@ -24,6 +24,17 @@ TEST(Label, basic) {
widget_destroy(l);
}
TEST(Label, value) {
widget_t* l = label_create(NULL, 10, 20, 30, 40);
ASSERT_EQ(widget_set_value(l, 100), RET_OK);
ASSERT_EQ(widget_get_value(l), 100);
ASSERT_EQ(widget_add_value(l, 100), RET_OK);
ASSERT_EQ(widget_get_value(l), 200);
widget_destroy(l);
}
TEST(Label, clone) {
value_t v1;
widget_t* w1 = label_create(NULL, 10, 20, 30, 40);