Exemplo n.º 1
0
/*
 * 创建一个部件,作为滚动条的容器
 * 再创建一个部件,作为滚动条
 * 限制滚动条的移动范围
 * */
static void 
ScrollBar_Init( LCUI_Widget *widget )
{
	LCUI_ScrollBar *scrollbar;
	
	scrollbar = WidgetPrivData_New(widget, sizeof(LCUI_ScrollBar));
	scrollbar->data.max_num = 100;
	scrollbar->data.current_num = 100;
	scrollbar->data.max_size = 100;
	scrollbar->data.current_size = 100;
	scrollbar->direction = 0;
	scrollbar->callback_func = NULL;
	
	scrollbar->widget = Widget_New("button");
	/* 禁用部件的自动尺寸调整 */
	Widget_SetAutoSize( scrollbar->widget, FALSE, 0 );
	
	Widget_Container_Add( widget, scrollbar->widget );
	Widget_SetSize( scrollbar->widget, "100%", "100%" );
	Widget_LimitPos( scrollbar->widget, Pos(0,0), Pos(0,0) );
	Widget_SetBorder( widget,
	 Border(1, BORDER_STYLE_SOLID, RGB(100,100,100)) );
	Widget_SetPadding( widget, Padding(1,1,1,1) );
	Widget_SetBackgroundColor( widget, RGB(200,200,200) );
	Widget_SetBackgroundTransparent( widget, FALSE );
	Widget_Show( scrollbar->widget );
	Widget_Event_Connect( scrollbar->widget, EVENT_DRAG, ScrollBar_Drag );
}
Exemplo n.º 2
0
static void 
ScrollBar_Update( LCUI_Widget *widget )
{
	static int pos, max_len;
	static double scale;
	static char scale_str[256];
	LCUI_ScrollBar *scrollbar;
	
	scrollbar = Widget_GetPrivData( widget );
	/* 计算比例,之后转换成字符串 */
	scale = scrollbar->data.current_size*1.0 / scrollbar->data.max_size; 
	sprintf( scale_str, "%.2lf%%", scale*100 );
	//_DEBUG_MSG("current_num: %d, max_num: %d\n", 
	//scrollbar->data.current_num, scrollbar->data.max_num);
	/* 判断滚动条的方向 */
	if( scrollbar->direction == 0 ) { /* 纵向 */
		Widget_SetSize( scrollbar->widget, NULL, scale_str );
		max_len = Widget_GetContainerHeight( widget );
		max_len -= _Widget_GetHeight( scrollbar->widget );
		Widget_LimitPos( scrollbar->widget, Pos(0,0), Pos( 0, max_len ) );
		
		scale = scrollbar->data.current_num*1.0 / scrollbar->data.max_num;
		pos = scale * max_len;
		//_DEBUG_MSG("num: %d / %d\n", 
		//scrollbar->data.current_num, scrollbar->data.max_num);
		//_DEBUG_MSG("ScrollBar_Update(), scale: %.2f\n", scale);
		//_DEBUG_MSG("ScrollBar_Update(), y: %d\n", pos);
		/* 移动滚动条 */
		Widget_Move( scrollbar->widget, Pos(0,pos) );
	} else { /* 横向 */ 
		Widget_SetSize( scrollbar->widget, scale_str, NULL );
		max_len = Widget_GetContainerWidth( widget );
		max_len -= _Widget_GetWidth( scrollbar->widget );
		Widget_LimitPos( scrollbar->widget, Pos(0,0), Pos(max_len,0) );
		scale = scrollbar->data.current_num*1.0 / scrollbar->data.max_num;
		pos = scale * max_len;
		//printf("ScrollBar_Update(), num: %d / %d\n", 
		//scrollbar->data.current_num, scrollbar->data.max_num);
		//printf("ScrollBar_Update(), scale: %.2f\n", scale);
		//printf("ScrollBar_Update(), x: %d\n", pos);
		Widget_Move( scrollbar->widget, Pos(pos, 0) );
	}
}
Exemplo n.º 3
0
static void CreateGUI( LCUI_Widget *win )
{
	/* 创建部件 */
	time_box	= Widget_New(NULL);
	pic_bg		= Widget_New(NULL);
	pic_l1		= Widget_New(NULL);
	pic_l2		= Widget_New(NULL);
	pic_c		= Widget_New(NULL);
	pic_btn		= Widget_New(NULL);
	pic_btn_line	= Widget_New(NULL);
	pic_btn		= Widget_New(NULL);
	pic_r1		= Widget_New(NULL);
	pic_r2		= Widget_New(NULL);
	date_label	= Widget_New("label");
	wday_label	= Widget_New("label");
	/* 设置这些部件的初始背景图 */
	Widget_SetBackgroundImage( pic_bg, &img_bg );
	Widget_SetBackgroundImage( pic_btn_line, &img_btn_bg );
	Widget_SetBackgroundLayout( pic_btn_line, LAYOUT_CENTER );
	Widget_SetBackgroundImage( pic_btn, &img_btn );
	Widget_SetBackgroundImage( pic_l1, &img_digital[0] );
	Widget_SetBackgroundImage( pic_l2, &img_digital[0] );
	Widget_SetBackgroundImage( pic_r1, &img_digital[0] );
	Widget_SetBackgroundImage( pic_r2, &img_digital[0] );
	Widget_SetBackgroundImage( pic_c,  &img_dot );
	/* 调整尺寸 */
	Widget_Resize( time_box,	Size(162, 38) );
	Widget_Resize( pic_bg,		Size(300, 90) );
	Widget_Resize( pic_btn_line,	Size(245, 66) );
	Widget_Resize( pic_btn,		Size(46, 66) );
	Widget_Resize( pic_l1,		Size(33, 36) );
	Widget_Resize( pic_l2,		Size(33, 36) );
	Widget_Resize( pic_c,		Size(30, 38) );
	Widget_Resize( pic_r1,		Size(33, 36) );
	Widget_Resize( pic_r2,		Size(33, 36) );
	/* 调整布局 */
	Widget_SetAlign( pic_l1, ALIGN_MIDDLE_CENTER, Pos(-66,0) );
	Widget_SetAlign( pic_l2, ALIGN_MIDDLE_CENTER, Pos(-33,0) );
	Widget_SetAlign( pic_c, ALIGN_MIDDLE_CENTER, Pos(0,0) );
	Widget_SetAlign( pic_r1, ALIGN_MIDDLE_CENTER, Pos(33,0) );
	Widget_SetAlign( pic_r2, ALIGN_MIDDLE_CENTER, Pos(66,0) );
	Widget_SetAlign( time_box, ALIGN_MIDDLE_CENTER, Pos(0,-50) );
	Widget_SetAlign( pic_bg, ALIGN_MIDDLE_CENTER, Pos(0,5) );
	Widget_SetAlign(date_label, ALIGN_MIDDLE_CENTER, Pos(0,35-50) );
	Widget_SetAlign( wday_label, ALIGN_TOP_CENTER, Pos(0,5) );
	Widget_SetAlign( pic_btn_line, ALIGN_BOTTOM_CENTER, Pos(0,-10) );
	/* 放入容器 */
	Widget_Container_Add( time_box, pic_l1 );
	Widget_Container_Add( time_box, pic_l2 );
	Widget_Container_Add( time_box, pic_c );
	Widget_Container_Add( time_box, pic_r1 );
	Widget_Container_Add( time_box, pic_r2 );
	Widget_Container_Add( pic_btn_line, pic_btn );

	Window_ClientArea_Add( win, pic_bg );
	Window_ClientArea_Add( win, time_box );
	Window_ClientArea_Add( win, date_label );
	Window_ClientArea_Add( win, wday_label );
	Window_ClientArea_Add (win, pic_btn_line );
	/* 限制移动范围 */
	Widget_LimitPos(pic_btn, Pos(0,0), Pos(195,0));
	Widget_ConnectEvent(pic_btn, EVENT_DRAG, move_pic_btn);

	Widget_Show(pic_bg);
	Widget_Show(pic_l1);
	Widget_Show(pic_l2);
	Widget_Show(pic_c);
	Widget_Show(pic_r1);
	Widget_Show(pic_r2);
	Widget_Show(time_box);
	Widget_Show(wday_label);
	Widget_Show(date_label);
	Widget_Show(pic_btn);
	Widget_Show(pic_btn_line);

	UpdateTimeView(NULL);
}