mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
progress bar support typecheck
This commit is contained in:
parent
bcce9ad72d
commit
4ee8a6ab57
@ -201,18 +201,18 @@ static ret_t progress_bar_set_prop(widget_t* widget, const char* name, const val
|
||||
|
||||
static const char* s_progress_bar_clone_properties[] = {WIDGET_PROP_VALUE, WIDGET_PROP_VERTICAL,
|
||||
WIDGET_PROP_SHOW_TEXT, NULL};
|
||||
static const widget_vtable_t s_progress_bar_vtable = {
|
||||
.size = sizeof(progress_bar_t),
|
||||
.type = WIDGET_TYPE_PROGRESS_BAR,
|
||||
.clone_properties = s_progress_bar_clone_properties,
|
||||
.create = progress_bar_create,
|
||||
.on_paint_self = progress_bar_on_paint_self,
|
||||
.on_paint_background = widget_on_paint_null,
|
||||
.get_prop = progress_bar_get_prop,
|
||||
.set_prop = progress_bar_set_prop};
|
||||
TK_DECL_VTABLE(progress_bar) = {.size = sizeof(progress_bar_t),
|
||||
.type = WIDGET_TYPE_PROGRESS_BAR,
|
||||
.clone_properties = s_progress_bar_clone_properties,
|
||||
.parent = TK_PARENT_VTABLE(widget),
|
||||
.create = progress_bar_create,
|
||||
.on_paint_self = progress_bar_on_paint_self,
|
||||
.on_paint_background = widget_on_paint_null,
|
||||
.get_prop = progress_bar_get_prop,
|
||||
.set_prop = progress_bar_set_prop};
|
||||
|
||||
widget_t* progress_bar_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
widget_t* widget = widget_create(parent, &s_progress_bar_vtable, x, y, w, h);
|
||||
widget_t* widget = widget_create(parent, TK_REF_VTABLE(progress_bar), x, y, w, h);
|
||||
progress_bar_t* progress_bar = PROGRESS_BAR(widget);
|
||||
return_value_if_fail(progress_bar != NULL, NULL);
|
||||
|
||||
@ -224,7 +224,7 @@ widget_t* progress_bar_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h)
|
||||
}
|
||||
|
||||
widget_t* progress_bar_cast(widget_t* widget) {
|
||||
return_value_if_fail(widget != NULL && widget->vt == &s_progress_bar_vtable, NULL);
|
||||
return_value_if_fail(WIDGET_IS_INSTANCE_OF(widget, progress_bar), NULL);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@ -157,7 +157,10 @@ ret_t progress_bar_set_vertical(widget_t* widget, bool_t vertical);
|
||||
*/
|
||||
ret_t progress_bar_set_show_text(widget_t* widget, bool_t show_text);
|
||||
|
||||
#define PROGRESS_BAR(widget) ((progress_bar_t*)(widget))
|
||||
#define PROGRESS_BAR(widget) ((progress_bar_t*)(progress_bar_cast(WIDGET(widget))))
|
||||
|
||||
/*public for subclass and runtime type check*/
|
||||
TK_EXTERN_VTABLE(progress_bar);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
|
@ -1,10 +1,5 @@
|
||||
#include "widgets/progress_bar.h"
|
||||
#include "base/canvas.h"
|
||||
#include "base/widget.h"
|
||||
#include "font_dummy.h"
|
||||
#include "lcd_log.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
TEST(progress_bar, basic) {
|
||||
value_t v1;
|
||||
@ -43,3 +38,11 @@ TEST(ProgressBar, event) {
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
||||
|
||||
TEST(ProgressBar, cast) {
|
||||
widget_t* w = progress_bar_create(NULL, 0, 0, 100, 100);
|
||||
|
||||
ASSERT_EQ(w, progress_bar_cast(w));
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user