improve tab_button

This commit is contained in:
xianjimli 2019-07-16 18:07:52 +08:00
parent 80403e86e9
commit ae078f6d6c
3 changed files with 30 additions and 3 deletions

View File

@ -22,6 +22,8 @@
#include "awtk.h"
#include "ext_widgets.h"
static ret_t on_clone_tab(void* ctx, event_t* e);
static ret_t widget_clone_tab(widget_t* widget) ;
static void install_click_hander(widget_t* widget);
uint32_t tk_mem_speed_test(void* buffer, uint32_t length, uint32_t* pmemcpy_speed,
@ -90,6 +92,13 @@ static void open_window(const char* name, widget_t* to_close) {
install_click_hander(win);
if(tk_str_eq(name, "tab_scrollable")) {
widget_clone_tab(win);
widget_clone_tab(win);
widget_clone_tab(win);
widget_clone_tab(win);
}
if (tk_str_eq(widget_get_type(win), WIDGET_TYPE_DIALOG)) {
int32_t ret = dialog_modal(win);
@ -374,9 +383,8 @@ static ret_t on_clone_self(void* ctx, event_t* e) {
return RET_OK;
}
static ret_t on_clone_tab(void* ctx, event_t* e) {
static ret_t widget_clone_tab(widget_t* widget) {
char text[32];
widget_t* widget = WIDGET(ctx);
widget_t* button = widget_lookup(widget, "clone_button", TRUE);
widget_t* view = widget_lookup(widget, "clone_view", TRUE);
widget_t* new_button = widget_clone(button, button->parent);
@ -392,6 +400,10 @@ static ret_t on_clone_tab(void* ctx, event_t* e) {
return RET_OK;
}
static ret_t on_clone_tab(void* ctx, event_t* e) {
return widget_clone_tab(WIDGET(ctx));
}
static ret_t on_show_fps(void* ctx, event_t* e) {
widget_t* button = WIDGET(ctx);
widget_t* widget = window_manager();

View File

@ -30,13 +30,20 @@ ret_t pages_set_active(widget_t* widget, uint32_t index) {
return_value_if_fail(pages != NULL, RET_BAD_PARAMS);
if (pages->active != index) {
widget_t* active = NULL;
event_t evt = event_init(EVT_VALUE_WILL_CHANGE, widget);
widget_dispatch(widget, &evt);
pages->active = index;
evt = event_init(EVT_VALUE_CHANGED, widget);
widget_dispatch(widget, &evt);
widget_invalidate(widget, NULL);
widget_set_as_key_target(widget_get_child(widget, pages->active));
if (index < widget_count_children(widget)) {
active = widget_get_child(widget, pages->active);
if (active != NULL) {
widget_set_as_key_target(active);
}
}
}
return RET_OK;

View File

@ -52,6 +52,7 @@ static ret_t tab_button_group_on_layout_children_compact(widget_t* widget) {
int32_t y = 0;
int32_t w = 0;
int32_t h = widget->h;
widget_t* active = NULL;
tab_button_group_t* tab_button_group = TAB_BUTTON_GROUP(widget);
WIDGET_FOR_EACH_CHILD_BEGIN(widget, iter, i)
@ -65,12 +66,19 @@ static ret_t tab_button_group_on_layout_children_compact(widget_t* widget) {
widget_move_resize(iter, x, y, w, h);
widget_layout_children(iter);
x += w;
if (widget_get_value(iter)) {
active = iter;
}
WIDGET_FOR_EACH_CHILD_END();
hscrollable_set_xoffset(tab_button_group->hscrollable, 0);
hscrollable_set_virtual_w(tab_button_group->hscrollable, x - 1);
hscrollable_set_always_scrollable(tab_button_group->hscrollable, FALSE);
if (active != NULL) {
widget_ensure_visible_in_viewport(active);
}
return RET_OK;
}