/* * 创建一个部件,作为滚动条的容器 * 再创建一个部件,作为滚动条 * 限制滚动条的移动范围 * */ static void ScrollBar_Init( LCUI_Widget *widget ) { LCUI_ScrollBar *scrollbar; scrollbar = Widget_Create_PrivData(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 = Create_Widget("button"); /* 禁用部件的自动尺寸调整 */ Widget_AutoSize( scrollbar->widget, FALSE, 0 ); Widget_Container_Add( widget, scrollbar->widget ); Set_Widget_Size( scrollbar->widget, "100%", "100%" ); Limit_Widget_Pos( scrollbar->widget, Pos(0,0), Pos(0,0) ); Set_Widget_Border( widget, RGB(100,100,100), Border(1,1,1,1) ); Set_Widget_Padding( widget, Padding(1,1,1,1) ); Set_Widget_Backcolor( widget, RGB(200,200,200) ); Set_Widget_BG_Mode( widget, BG_MODE_FILL_BACKCOLOR ); Show_Widget( scrollbar->widget ); Widget_Drag_Event_Connect( scrollbar->widget, ScrollBar_Drag ); }
int main(int argc, char *argv[]) { int i; LCUI_Init( argc, argv ); LCUI_RGB color[6]={{255,255,255},{127,127,127}, {255,0,0}, {255,165,0}, {30,144,255}, {65,200,65} }; LCUI_Widget *window, *widget[6], *label[6]; window = Create_Widget( "window" ); for(i=0; i<6; ++i) { widget[i] = Create_Widget( NULL ); label[i] = Create_Widget( "label" ); Label_Text( label[i], "Area %d" , i); Widget_Container_Add( widget[i], label[i] ); Window_Client_Area_Add( window, widget[i] ); Resize_Widget( widget[i], Size(80,80) ); Set_Widget_PosType( widget[i], POS_TYPE_STATIC ); Set_Widget_Align( label[i], ALIGN_MIDDLE_CENTER, Pos(0,0) ); Set_Widget_Border( widget[i], RGB(0,0,0), Border(1,1,1,1) ); Set_Widget_BG_Mode( widget[i], BG_MODE_FILL_BACKCOLOR ); Set_Widget_Backcolor( widget[i], color[i] ); Show_Widget( label[i] ); Show_Widget( widget[i] ); } Set_Window_Title_Text( window, "测试部件布局-2" ); Resize_Widget( window, Size(320, 240) ); Show_Widget( window ); return LCUI_Main(); }
int main(int argc,char*argv[]) { /* 声明几个部件 */ LCUI_Widget *window, *label, *logo, *img; int width, height; /* 自定义默认字体文件位置 */ //Set_Default_Font("msyh.ttf"); /* 初始化LCUI */ LCUI_Init(argc, argv); /* 创建一个LCUI程序窗口 */ width = 320;//Get_Screen_Width(); /* 窗口的宽度 */ height = 240;//Get_Screen_Height();; /* 窗口的高度 */ /* 创建部件 */ window = Create_Widget("window"); label = Create_Widget("label"); logo = Create_Widget("picture_box"); img = Create_Widget("picture_box"); //Set_Widget_Border_Style(window, BORDER_STYLE_NONE); Resize_Widget(img, Size(180, 180)); Resize_Widget(logo, Size(128,128)); Resize_Widget(window, Size(width, height)); Set_Window_Title_Text(window, "LCUI"); Set_Widget_Backcolor(window, RGB(94,200,255)); Set_PictureBox_Size_Mode(logo, SIZE_MODE_CENTER); Set_PictureBox_Image_From_File(logo, "logo_128x128.png"); Set_Label_Text(label, "LCUI 正在载入..."); Set_Label_Font(label, 15, NULL); Set_Widget_Align(logo, ALIGN_MIDDLE_CENTER, Pos(0, -20)); Set_Widget_Align(label, ALIGN_MIDDLE_CENTER, Pos(0, +70)); /* 将这三个部件放入窗口客户区中 */ Window_Client_Area_Add(window, label); Window_Client_Area_Add(window, img); Window_Client_Area_Add(window, logo); pthread_t t; LCUI_Thread_Create(&t, NULL, change_graph, (void*)img); /* 显示部件以及窗口 */ Show_Widget(label); Show_Widget(logo); Show_Widget(window); LCUI_Main(); /* 进入主循环 */ return 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 ); }