Example #1
0
int main(int argc, char*argv[]) 
{
	LCUI_Init(argc, argv);
	
	window = Create_Widget("window");
	scrollbar = Create_Widget("scrollbar");
	label = Create_Widget("label");
	/* 设定窗口标题的文本 */
	Set_Window_Title_Text(window, "测试滚动条"); 
	/* 改变窗口的尺寸 */
	window->resize(window, Size(320, 240));
	Resize_Widget( scrollbar, Size(10, 100) );
	ScrollBar_Set_MaxSize( scrollbar, 400 );
	/* 设置部件布局 */
	Set_Widget_Align( label, ALIGN_MIDDLE_CENTER, Pos(-20,0) );
	Set_Widget_Align( scrollbar, ALIGN_MIDDLE_CENTER, Pos(0,0) );
	
	Label_Text( label, "0" );
	
	/* 将窗口客户区作为部件的容器添加进去 */
	Window_Client_Area_Add(window, label);
	Window_Client_Area_Add(window, scrollbar); 
	/* 将回调函数与滚动条部件连接 */
	ScrollBar_Connect( scrollbar, callback_func, NULL );
	/* 显示部件 */
	scrollbar->show(scrollbar);
	window->show(window); 
	label->show(label);
	return LCUI_Main(); /* 进入主循环 */
}
Example #2
0
static void 
TextBox_Init( LCUI_Widget *widget )
/* 初始化文本框相关数据 */
{
	LCUI_TextBox *textbox;
	
	widget->valid_state = WIDGET_STATE_ACTIVE | WIDGET_STATE_OVERLAY;
	widget->valid_state |= (WIDGET_STATE_NORMAL | WIDGET_STATE_DISABLE);
	textbox = WidgetPrivData_New(widget, sizeof(LCUI_TextBox));
	textbox->text = Widget_New( "label" );
	textbox->cursor = Widget_New( NULL );
	textbox->scrollbar[0] = Widget_New( "scrollbar" );
	textbox->scrollbar[1] = Widget_New( "scrollbar" );
	/* 不可获得焦点 */
	textbox->text->focus = FALSE;
	textbox->cursor->focus = FALSE;
	textbox->scrollbar[0]->focus = FALSE;
	textbox->scrollbar[1]->focus = FALSE;
	textbox->limit_mode = 0;
	textbox->block_size = 256;
	textbox->show_placeholder = FALSE;
	LCUIWString_Init( &textbox->placeholder );
	TextStyle_Init( &textbox->placeholder_style );
	TextStyle_FontColor( &textbox->placeholder_style, RGB(100,100,100) );
	Label_AutoSize( textbox->text, FALSE, 0 );
	Widget_SetSize( textbox->text, "100%", "100%" );
	
	/* 添加至相应的容器 */
	Widget_Container_Add( textbox->text, textbox->cursor ); 
	Widget_Container_Add( widget, textbox->text ); 
	Widget_Container_Add( widget, textbox->scrollbar[0] );
	Widget_Container_Add( widget, textbox->scrollbar[1] );
	/* 设置滚动条的尺寸 */
	Widget_SetSize( textbox->scrollbar[0], "10px", NULL );
	Widget_SetSize( textbox->scrollbar[1], NULL, "10px" );
	Widget_SetAlign( textbox->scrollbar[0], ALIGN_TOP_RIGHT, Pos(0,0) );
	Widget_SetAlign( textbox->scrollbar[1], ALIGN_BOTTOM_LEFT, Pos(0,0) );
	/* 滚动条设为横向 */
	ScrollBar_SetDirection( textbox->scrollbar[1], 1 );
	/* 将回调函数与滚动条连接 */
	ScrollBar_Connect( textbox->scrollbar[0], TextBox_TextLayer_VertScroll, widget );
	ScrollBar_Connect( textbox->scrollbar[1], TextBox_HoriScroll_TextLayer, widget );
	Widget_Show( textbox->text );
	
	Queue_Init( &textbox->text_block_buff, sizeof(LCUI_TextBlock), destroy_textblock );
	
	TextLayer_UsingStyleTags( Label_GetTextLayer(textbox->text), FALSE );
	Widget_SetPadding( widget, Padding(2,2,2,2) );
	Widget_SetBackgroundColor( textbox->cursor, RGB(0,0,0) );
	Widget_SetBackgroundTransparent( textbox->cursor, FALSE );
	Widget_SetBackgroundTransparent( widget, FALSE );
	
	Widget_Resize( textbox->cursor, Size(1, 14) );
	/* 设置可点击区域的alpha值要满足的条件 */
	Set_Widget_ClickableAlpha( textbox->cursor, 0, 1 );
	Set_Widget_ClickableAlpha( textbox->text, 0, 1 );
	
	/* 设定定时器,每1秒闪烁一次 */
	if( __timer_id == -1 ) {
		__timer_id = set_timer( 500, blink_cursor, TRUE );
	}
	Widget_Event_Connect( widget, EVENT_DRAG, TextBox_TextLayer_Click );
	/* 关联 FOCUS_OUT 和 FOCUS_IN 事件 */
	Widget_Event_Connect( widget, EVENT_FOCUSOUT, _putout_textbox_cursor );
	Widget_Event_Connect( widget, EVENT_FOCUSIN, _putin_textbox_cursor );
	/* 关联按键输入事件 */
	Widget_Event_Connect( widget, EVENT_KEYBOARD, TextBox_Input );
	/* 默认不启用多行文本模式 */
	TextBox_Multiline( widget, FALSE );
}
Example #3
0
static void 
TextBox_Init( LCUI_Widget *widget )
/* 初始化文本框相关数据 */
{
	LCUI_TextBox *textbox;
	
	textbox = Widget_Create_PrivData(widget, sizeof(LCUI_TextBox));
	
	textbox->text = Create_Widget( "label" );
	textbox->cursor = Create_Widget( NULL );
	textbox->scrollbar[0] = Create_Widget( "scrollbar" );
	textbox->scrollbar[1] = Create_Widget( "scrollbar" );
	/* 不可获得焦点 */
	textbox->text->focus = FALSE;
	textbox->cursor->focus = FALSE;
	textbox->scrollbar[0]->focus = FALSE;
	textbox->scrollbar[1]->focus = FALSE;
	textbox->limit_mode = 0;
	textbox->block_size = 256;
	
	Label_AutoSize( textbox->text, FALSE, 0 );
	Set_Widget_Size( textbox->text, "100%", "100%" );
	
	/* 添加至相应的容器 */
	Widget_Container_Add( textbox->text, textbox->cursor ); 
	Widget_Container_Add( widget, textbox->text ); 
	Widget_Container_Add( widget, textbox->scrollbar[0] );
	Widget_Container_Add( widget, textbox->scrollbar[1] );
	/* 设置滚动条的尺寸 */
	Set_Widget_Size( textbox->scrollbar[0], "10px", NULL );
	Set_Widget_Size( textbox->scrollbar[1], NULL, "10px" );
	Set_Widget_Align( textbox->scrollbar[0], ALIGN_TOP_RIGHT, Pos(0,0) );
	Set_Widget_Align( textbox->scrollbar[1], ALIGN_BOTTOM_LEFT, Pos(0,0) );
	/* 滚动条设为横向 */
	ScrollBar_Set_Direction( textbox->scrollbar[1], 1 );
	/* 将回调函数与滚动条连接 */
	ScrollBar_Connect( textbox->scrollbar[0], TextBox_VertScroll_TextLayer, widget );
	ScrollBar_Connect( textbox->scrollbar[1], TextBox_HoriScroll_TextLayer, widget );
	Show_Widget( textbox->text );
	
	Queue_Init( &textbox->text_block_buff, sizeof(LCUI_TextBlock), destroy_textblock );
	
	TextLayer_Using_StyleTags( Label_Get_TextLayer(textbox->text), FALSE );
	Set_Widget_Padding( widget, Padding(2,2,2,2) );
	Set_Widget_Backcolor( textbox->cursor, RGB(0,0,0) );
	Set_Widget_BG_Mode( textbox->cursor, BG_MODE_FILL_BACKCOLOR );
	
	Resize_Widget( textbox->cursor, Size(1, 14) );
	/* 设置可点击区域的alpha值要满足的条件 */
	Set_Widget_ClickableAlpha( textbox->cursor, 0, 1 );
	Set_Widget_ClickableAlpha( textbox->text, 0, 1 );
	/* 设定定时器,每1秒闪烁一次 */
	if( __timer_id == -1 ) {
		__timer_id = set_timer( 500, blink_cursor, TRUE );
	}
	Widget_Drag_Event_Connect( widget, TextBox_TextLayer_Click );
	/* 关联 FOCUS_OUT 和 FOCUS_IN 事件 */
	Widget_FocusOut_Event_Connect( widget, hide_textbox_cursor, NULL );
	Widget_FocusIn_Event_Connect( widget, _put_textbox_cursor, NULL );
	/* 关联按键输入事件 */
	Widget_Keyboard_Event_Connect( widget, TextBox_Input );
	/* 默认不启用多行文本模式 */
	TextBox_Multiline( widget, FALSE );
}