mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
add pages_set_active_by_name
This commit is contained in:
parent
264b287e30
commit
bcc2fb5838
@ -37,6 +37,27 @@ ret_t pages_set_active(widget_t* widget, uint32_t index) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t pages_set_active_by_name(widget_t* widget, const char* name) {
|
||||
uint32_t i = 0;
|
||||
uint32_t nr = 0;
|
||||
widget_t** children = NULL;
|
||||
return_value_if_fail(widget != NULL && name != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if (widget->children && widget->children->elms) {
|
||||
nr = widget->children->size;
|
||||
children = (widget_t**)(widget->children->elms);
|
||||
|
||||
for (i = 0; i < nr; i++) {
|
||||
widget_t* iter = children[i];
|
||||
if (iter->name.str && str_fast_equal(iter->name.str, name)) {
|
||||
return pages_set_active(widget, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return RET_NOT_FOUND;
|
||||
}
|
||||
|
||||
static widget_t* pages_find_target(widget_t* widget, xy_t x, xy_t y) {
|
||||
pages_t* pages = PAGES(widget);
|
||||
return_value_if_fail(pages != NULL, NULL);
|
||||
|
@ -58,14 +58,24 @@ widget_t* pages_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);
|
||||
|
||||
/**
|
||||
* @method pages_set_active
|
||||
* 设置进度条的进度。
|
||||
* 设置当前的Page。
|
||||
* @param {widget_t*} widget 控件对象。
|
||||
* @param {uint32_t} index 当Page的序号。
|
||||
* @param {uint32_t} index 当前Page的序号。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t pages_set_active(widget_t* widget, uint32_t index);
|
||||
|
||||
/**
|
||||
* @method pages_set_active_by_name
|
||||
* 通过页面的名字设置当前的Page。
|
||||
* @param {widget_t*} widget 控件对象。
|
||||
* @param {char*} name 当前Page的名字。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t pages_set_active_by_name(widget_t* widget, const char* name);
|
||||
|
||||
#define PAGES(widget) ((pages_t*)(widget))
|
||||
|
||||
END_C_DECLS
|
||||
|
27
tests/pages_test.cc
Normal file
27
tests/pages_test.cc
Normal file
@ -0,0 +1,27 @@
|
||||
#include "base/pages.h"
|
||||
#include "base/view.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(Pages, basic) {
|
||||
widget_t* pages = pages_create(NULL, 0, 0, 100, 100);
|
||||
widget_t* p0 = view_create(pages, 0, 0, 100, 100);
|
||||
widget_t* p1 = view_create(pages, 0, 0, 100, 100);
|
||||
widget_t* p2 = view_create(pages, 0, 0, 100, 100);
|
||||
|
||||
widget_set_name(p0, "p0");
|
||||
widget_set_name(p1, "p1");
|
||||
widget_set_name(p2, "p2");
|
||||
|
||||
ASSERT_EQ(PAGES(pages)->active, 0);
|
||||
|
||||
pages_set_active(pages, 1);
|
||||
ASSERT_EQ(PAGES(pages)->active, 1);
|
||||
|
||||
pages_set_active_by_name(pages, "p2");
|
||||
ASSERT_EQ(PAGES(pages)->active, 2);
|
||||
|
||||
pages_set_active_by_name(pages, "not found");
|
||||
ASSERT_EQ(PAGES(pages)->active, 2);
|
||||
|
||||
widget_destroy(pages);
|
||||
}
|
Loading…
Reference in New Issue
Block a user