/* 动态改变进度条的数据 */ static void change_progress( void *arg ) { char str[15]; int i, max = 100; LCUI_Widget *label; LCUI_Widget *widget; /* 创建一个label部件 */ widget = (LCUI_Widget *)arg; label = Widget_New("label"); /* 放到进度条里 */ Widget_Container_Add( widget, label ); /* 并且居中 */ Widget_SetAlign( label, ALIGN_MIDDLE_CENTER, Pos(0,0) ); /* 显示它 */ Widget_Show( label ); /* 设置最大值 */ ProgressBar_SetMaxValue(widget, max); for( i=0; i<max; i+=rand()%5 ) { /* 设置当前值 */ ProgressBar_SetValue(widget, i); /* 转换成字符串 */ sprintf( str, "%d%%", (int)(i*100.0/max) ); /* 设置显示的文本 */ Label_Text( label, str ); /* 暂停0.1秒 */ LCUI_MSleep(100); } ProgressBar_SetValue( widget, max ); Label_Text( label, "100%" ); LCUIThread_Exit(NULL); }
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_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(); /* 进入主循环 */ }
int main(void) { int i; char str[10]; 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]; LCUI_Init(); window = Widget_New( "window" ); for(i=0; i<6; ++i) { widget[i] = Widget_New( NULL ); label[i] = Widget_New( "label" ); sprintf(str, "Area %d" , i); Label_Text( label[i], str); Widget_Container_Add( widget[i], label[i] ); Window_ClientArea_Add( window, widget[i] ); Widget_Resize( widget[i], Size(80,80) ); Widget_SetPosType( widget[i], POS_TYPE_STATIC ); Widget_SetAlign( label[i], ALIGN_MIDDLE_CENTER, Pos(0,0) ); Widget_SetBorder( widget[i], Border(1,BORDER_STYLE_SOLID,RGB(0,0,0)) ); Widget_SetBackgroundTransparent( widget[i], FALSE ); Widget_SetBackgroundColor( widget[i], color[i] ); Widget_Show( label[i] ); Widget_Show( widget[i] ); } Window_SetTitleText( window, "测试部件布局-2" ); Widget_Resize( window, Size(320, 240) ); Widget_Event_Connect( Window_GetCloseButton(window), EVENT_CLICKED, destroy ); Widget_Show( window ); return LCUI_Main(); }
static void view_result(LCUI_Widget *widget, LCUI_WidgetEvent *unused) { char str[256]; strcpy(str, "你的年龄段是: "); if(RadioButton_IsOn(age_rb[0])) { strcat(str, "15岁以下"); } if(RadioButton_IsOn(age_rb[1])) { strcat(str, "15-20岁"); } if(RadioButton_IsOn(age_rb[2])) { strcat(str, "21-25岁"); } if(RadioButton_IsOn(age_rb[3])) { strcat(str, "26-30岁"); } if(RadioButton_IsOn(age_rb[4])) { strcat(str, "31-40岁"); } if(RadioButton_IsOn(age_rb[5])) { strcat(str, "40岁以上"); } strcat(str, "。"); Label_Text(age_label, str); Widget_Disable(button); }
/* 设定与复选框部件关联的文本内容 */ LCUI_API void CheckBox_Text( LCUI_Widget *widget, const char *text ) { LCUI_Widget *label; label = CheckBox_GetLabel(widget); Label_Text(label, text); }
/* 更新文本 */ static void update_text( void ) { char str[256]; sprintf( str, TEXT_SCROE, win, lose, standoff ); Label_Text( label, str ); }
int main(int argc, char **argv) { int i; LCUI_Init(0,0,0); /* 创建部件 */ window = Widget_New("window"); age_label = Widget_New("label"); button = Button_New("提交"); age_rb[0] = RadioButton_New("A. 15岁以下"); age_rb[1] = RadioButton_New("B. 15-20岁"); age_rb[2] = RadioButton_New("C. 21-25岁"); age_rb[3] = RadioButton_New("D. 26-30岁"); age_rb[4] = RadioButton_New("E. 31-40岁"); age_rb[5] = RadioButton_New("F. 40岁以上"); /* 设定窗口标题的文本 */ Window_SetTitleText(window, "测试复选框部件"); /* 改变尺寸 */ Widget_Resize(window, Size(320, 240)); Widget_SetAutoSize( button, FALSE, 0 ); Widget_Resize(button, Size(60, 25)); /* 将窗口客户区作为这些部件的容器 */ Window_ClientArea_Add(window, age_label); Window_ClientArea_Add(window, button); for(i=0; i<6; i++) { Window_ClientArea_Add(window, age_rb[i]); } /* 调整部件的布局*/ Widget_SetAlign(age_label, ALIGN_MIDDLE_CENTER, Pos(0,-40)); Widget_SetAlign(button, ALIGN_MIDDLE_CENTER, Pos(0,60)); Widget_SetAlign(age_rb[0], ALIGN_MIDDLE_LEFT, Pos(5,-20)); Widget_SetAlign(age_rb[1], ALIGN_MIDDLE_LEFT, Pos(100,-20)); Widget_SetAlign(age_rb[2], ALIGN_MIDDLE_LEFT, Pos(200,-20)); Widget_SetAlign(age_rb[3], ALIGN_MIDDLE_LEFT, Pos(5,0)); Widget_SetAlign(age_rb[4], ALIGN_MIDDLE_LEFT, Pos(100,0)); Widget_SetAlign(age_rb[5], ALIGN_MIDDLE_LEFT, Pos(200,0)); Label_Text(age_label, "你的年龄段是?"); RadioButton_CreateMutex(age_rb[0], age_rb[1]); RadioButton_CreateMutex(age_rb[0], age_rb[2]); RadioButton_CreateMutex(age_rb[0], age_rb[3]); RadioButton_CreateMutex(age_rb[0], age_rb[4]); RadioButton_CreateMutex(age_rb[0], age_rb[5]); /* 显示部件 */ Widget_Show(age_label); Widget_Show(button); Widget_Show(age_rb[0]); for(i=0; i<6; ++i) { Widget_Show(age_rb[i]); } Widget_Show(window); Widget_ConnectEvent( button, EVENT_CLICKED, view_result ); Widget_ConnectEvent( Window_GetCloseButton(window), EVENT_CLICKED, destroy ); LCUI_Main(); return 0; }
/* 设定按钮部件显示的文本内容 */ LCUI_API void Button_Text( LCUI_Widget *widget, const char *text ) { LCUI_Button *button; LCUI_Widget *label; button = (LCUI_Button*)Widget_GetPrivData(widget); label = button->label; /* 设定部件显示的文本 */ Label_Text( label, text ); }
/* 为窗口设置标题文字 */ LCUI_API void Window_SetTitleText( LCUI_Widget *win_p, const char *text ) { LCUI_Widget *titlebar; LCUI_TitleBar *title; if( win_p == NULL ) { return; } titlebar = Window_GetTitleBar(win_p); title = (LCUI_TitleBar *)Widget_GetPrivData(titlebar); Label_Text(title->label, text); }
int main(void) { int i; char text[5][10] = { "蓝色","绿色", "红色", "橙色", "紫色" }; LCUI_Pos offset_pos[5]={{-120,0},{-60,0},{0,0},{60,0},{120,0}}; LCUI_Init(); main_window = Widget_New( "window" ); btn_ok = Widget_New( "button" ); label = Widget_New( "label" ); /* 设置窗口的尺寸以及标题栏文本 */ Widget_Resize( main_window, Size(320, 240) ); Window_SetTitleText( main_window, "测试窗口的风格切换" ); /* 创建5个单选框部件 */ for(i=0; i<5; ++i) { rdbtn[i] = Widget_New( "radio_button" ); Window_ClientArea_Add( main_window, rdbtn[i] ); Widget_SetAlign( rdbtn[i], ALIGN_MIDDLE_CENTER, offset_pos[i] ); RadioButton_Text( rdbtn[i], text[i] ); Widget_Show( rdbtn[i] ); } /* 为单选框建立互斥关系 */ RadioButton_CreateMutex(rdbtn[0], rdbtn[1]); RadioButton_CreateMutex(rdbtn[0], rdbtn[2]); RadioButton_CreateMutex(rdbtn[0], rdbtn[3]); RadioButton_CreateMutex(rdbtn[0], rdbtn[4]); RadioButton_SetOn( rdbtn[0] ); /* 禁用按钮部件的自动尺寸调整 */ Widget_SetAutoSize( btn_ok, FALSE, 0 ); Widget_Resize( btn_ok, Size(100, 30) ); /* 将部件加入窗口客户区 */ Window_ClientArea_Add( main_window, btn_ok ); Window_ClientArea_Add( main_window, label ); /* 设置部件的布局 */ Widget_SetAlign( btn_ok, ALIGN_MIDDLE_CENTER, Pos(0,50) ); Widget_SetAlign( label, ALIGN_MIDDLE_CENTER, Pos(0,-50) ); /* 设置部件的文本 */ Button_Text( btn_ok, "应用" ); Label_Text( label, "选择窗口配色:" ); /* 为按钮的点击事件关联回调函数 */ Widget_Event_Connect( btn_ok, EVENT_CLICKED, switch_style ); Widget_Event_Connect( Window_GetCloseButton(main_window), EVENT_CLICKED, destroy ); /* 显示部件 */ Widget_Show( btn_ok ); Widget_Show( label ); Widget_Show( main_window ); /* 进入主循环 */ return LCUI_Main(); }
int main( int argc, char*argv[] ) { LCUI_Graph pic; int width = 320, height = 240; LCUI_Widget *window, *label, *pic_box, *fore_box; LCUI_Init(); Graph_Init(&pic); window = Widget_New("window"); label = Widget_New("label"); pic_box = Widget_New("picture_box"); fore_box = Widget_New("picture_box"); Widget_Resize(fore_box, Size(190, 190)); Widget_Resize(pic_box, Size(135,135)); Widget_Resize(window, Size(width, height)); Window_SetTitleText(window, "头像"); PictureBox_SetSizeMode(pic_box, SIZE_MODE_STRETCH); PictureBox_SetImageFile(pic_box, "image.jpg"); PictureBox_SetImageFile(fore_box, "border.png"); Label_Text(label, "蛋疼的头像"); Widget_SetAlign(pic_box, ALIGN_MIDDLE_CENTER, Pos(0, -20)); Widget_SetAlign(fore_box, ALIGN_MIDDLE_CENTER, Pos(0, -20)); Widget_SetAlign(label, ALIGN_MIDDLE_CENTER, Pos(0, +75)); Window_ClientArea_Add(window, label); Window_ClientArea_Add(window, pic_box); Window_ClientArea_Add(window, fore_box); Widget_Event_Connect( Window_GetCloseButton(window), EVENT_CLICKED, destroy ); Widget_Show(label); Widget_Show(pic_box); Widget_Show(fore_box); Widget_Show(window); return LCUI_Main(); }
static void thread(void *arg) { LCUI_Widget *widget, *label; widget = (LCUI_Widget*)arg; label = Widget_New( "label" ); Widget_Container_Add( widget, label ); Widget_SetAlign( label, ALIGN_MIDDLE_CENTER, Pos(0,0) ); Widget_Show( label ); while(LCUI_Active()) { Label_Text( label, "DOCK_TYPE_TOP" ); Widget_SetDock( widget, DOCK_TYPE_TOP ); Widget_SetSize( widget, "120px", "120px" ); /* 还原尺寸 */ LCUI_Sleep(1); Label_Text( label, "DOCK_TYPE_LEFT" ); Widget_SetDock( widget, DOCK_TYPE_LEFT ); Widget_SetSize( widget, "120px", "120px" ); LCUI_Sleep(1); Label_Text( label, "DOCK_TYPE_RIGHT" ); Widget_SetDock( widget, DOCK_TYPE_RIGHT ); Widget_SetSize( widget, "120px", "120px" ); LCUI_Sleep(1); Label_Text( label, "DOCK_TYPE_BOTTOM" ); Widget_SetDock( widget, DOCK_TYPE_BOTTOM ); Widget_SetSize( widget, "120px", "120px" ); LCUI_Sleep(1); Label_Text( label, "DOCK_TYPE_FILL" ); Widget_SetDock( widget, DOCK_TYPE_FILL ); Widget_SetSize( widget, "120px", "120px" ); LCUI_Sleep(1); Label_Text( label, "DOCK_TYPE_NONE" ); Widget_SetDock( widget, DOCK_TYPE_NONE ); Widget_SetSize( widget, "120px", "120px" ); LCUI_Sleep(1); } LCUIThread_Exit(NULL); }
void callback_func( ScrollBar_Data data, void *arg ) { Label_Text( label, "%d", data.current_num ); }
int main(void) { int i, x, y = 3; LCUI_Init(); window = Window_New( "测试MessageBox", NULL, Size(320,240) ); label_btn = Widget_New( "label" ); label_icon = Widget_New( "label" ); btn = Widget_New( "button" ); Window_ClientArea_Add( window, label_btn ); Label_Text( label_btn, "请选择按钮类型:" ); Widget_Move( label_btn, Pos(5,y) ); Widget_Show( label_btn ); for(i=0; i<6; ++i) { rb_btn[i] = RadioButton_New( rb_btn_text[i] ); if( i>0 ) { RadioButton_CreateMutex( rb_btn[0], rb_btn[i] ); } else { RadioButton_SetOn( rb_btn[0] ); } Window_ClientArea_Add( window, rb_btn[i] ); y += 16; Widget_Move( rb_btn[i], Pos(5,y) ); Widget_Show( rb_btn[i] ); } y += 16; Window_ClientArea_Add( window, label_icon ); Label_Text( label_icon, "请选择图标类型:" ); Widget_Move( label_icon, Pos(5,y) ); Widget_Show( label_icon ); for(i=0; i<5; ++i) { rb_icon[i] = RadioButton_New( rb_icon_text[i] ); if( i>0 ) { RadioButton_CreateMutex( rb_icon[0], rb_icon[i] ); } else { RadioButton_SetOn( rb_icon[0] ); } Window_ClientArea_Add( window, rb_icon[i] ); /* 计算当前单选框的坐标 */ if(i%2 == 0) { y += 16; x = 5; } else { x = 150; } Widget_Move( rb_icon[i], Pos(x,y) ); Widget_Show( rb_icon[i] ); } Button_Text( btn, "显示MessageBox" ); Widget_SetAlign( btn, ALIGN_BOTTOM_CENTER, Pos(0,-3) ); Widget_Resize( btn, Size(80, 20) ); Window_ClientArea_Add( window, btn ); Widget_Show( btn ); Widget_Event_Connect( btn, EVENT_CLICKED, show_msgbox ); Widget_Event_Connect( Window_GetCloseButton(window), EVENT_CLICKED, program_quit ); Widget_Show( window ); return LCUI_Main(); }
int main(int argc, char*argv[]) { int mode; LCUI_Widget *window, *text[2], *tb_username, *tb_password; LCUI_Widget *area, *login_btn; LCUI_Widget *fore_pb, *back_pb; LCUI_Init(argc, argv); /* 创建所需的部件 */ window = Create_Widget("window"); area = Create_Widget(NULL); tb_password = Create_Widget("text_box"); tb_username = Create_Widget("text_box"); text[0] = Create_Widget("label"); text[1] = Create_Widget("label"); fore_pb = Create_Widget("picture_box"); back_pb = Create_Widget("picture_box"); login_btn = Create_Widget("button"); /* 设置界面上显示的文本 */ Set_Window_Title_Text(window, "用户登录"); Label_Text( text[0], "帐号:" ); Label_Text( text[1], "密码:" ); Set_Button_Text( login_btn, "登录" ); /* 调整部件的尺寸 */ Resize_Widget( login_btn, Size(50, 50) ); Resize_Widget( window, Size(320, 240) ); Resize_Widget( back_pb, Size(128, 128)); Resize_Widget( fore_pb, Size(95,95)); Resize_Widget( area, Size(225,50) ); /* 设置这两个图片框内显示的图片 */ Set_PictureBox_Size_Mode( back_pb, SIZE_MODE_STRETCH ); Set_PictureBox_Size_Mode( fore_pb, SIZE_MODE_STRETCH ); Set_PictureBox_Image_From_File( back_pb, "faceback.png" ); Set_PictureBox_Image_From_File( fore_pb, "image.jpg" ); /* 限制文本框内的字符总数为32个 */ TextBox_Text_Set_MaxLength( tb_username, 32 ); TextBox_Text_Set_MaxLength( tb_password, 32 ); tb_password->resize( tb_password, Size(125, 22) ); TextBox_Text_Set_PasswordChar( tb_password, L'●' ); /* 限制文本框输入的字符 */ mode = ONLY_0_TO_9 | ONLY_A_TO_Z | ONLY_a_TO_z | ONLY_UNDERLINE; TextBox_Text_Limit( tb_username, mode ); tb_username->resize( tb_username, Size(125, 22) ); /* 将部件添加至相应的容器中 */ Widget_Container_Add( area, text[0] ); Widget_Container_Add( area, text[1] ); Widget_Container_Add( area, login_btn ); Widget_Container_Add( back_pb, fore_pb ); Widget_Container_Add( area, tb_username ); Widget_Container_Add( area, tb_password ); Window_Client_Area_Add( window, back_pb ); Window_Client_Area_Add( window, area ); /* 设置部件的布局 */ area->set_align( area, ALIGN_MIDDLE_CENTER, Pos(0,60) ); login_btn->set_align( login_btn, ALIGN_MIDDLE_RIGHT, Pos(0,0) ); back_pb->set_align( fore_pb, ALIGN_MIDDLE_CENTER, Pos(-2,-2) ); back_pb->set_align( back_pb, ALIGN_MIDDLE_CENTER, Pos(0,-35) ); text[0]->set_align( text[0], ALIGN_MIDDLE_LEFT, Pos(0,-12) ); text[1]->set_align( text[1], ALIGN_MIDDLE_LEFT, Pos(0,12) ); tb_username->set_align( tb_username, ALIGN_MIDDLE_LEFT, Pos(35,-12) ); tb_password->set_align( tb_password, ALIGN_MIDDLE_LEFT, Pos(35,12) ); /* 设置边框 */ Set_Widget_Border( fore_pb, RGB(120,120,120), Border(1,1,1,1) ); /* 显示这些部件 */ Show_Widget( back_pb ); Show_Widget( fore_pb ); Show_Widget( login_btn ); Show_Widget( area ); tb_password->show( tb_password ); tb_username->show( tb_username ); text[0]->show( text[0] ); text[1]->show( text[1] ); window->show( window ); /* 进入主循环 */ return LCUI_Main(); }
static void widgets_configure( void ) { /* 设定标题栏显示的文本 */ Window_SetTitleText( window, TEXT_WND_TITLE ); Window_SetTitleIcon( window, &icon ); Widget_Resize( window, WND_SIZE ); /* 将部件加入至相应的容器 */ Widget_Container_Add( btn_area, btn_s ); Widget_Container_Add( btn_area, btn_j ); Widget_Container_Add( btn_area, btn_b ); Widget_Container_Add( btn_area, btn_next ); Window_ClientArea_Add( window, label ); Window_ClientArea_Add( window, l_vs ); Window_ClientArea_Add( window, me_pic_box ); Window_ClientArea_Add( window, cpu_pic_box ); Window_ClientArea_Add( window, btn_area ); /* 设定label部件显示的文本内容 */ Label_Text( label, TEXT_TIP ); /* 设定label部件中的字体大小为55像素,颜色为红色 */ Label_Text( l_vs, TEXT_VS ); /* 禁用按钮的自动尺寸调整 */ Widget_SetAutoSize( btn_b, FALSE, 0 ); Widget_SetAutoSize( btn_s, FALSE, 0 ); Widget_SetAutoSize( btn_j, FALSE, 0 ); Widget_SetAutoSize( btn_next, FALSE, 0 ); /* 调整这些部件的大小 */ Widget_SetSize( btn_b, "78px", "30px" ); Widget_SetSize( btn_s, "77px", "30px" ); Widget_SetSize( btn_j, "77px", "30px" ); Widget_SetSize( btn_next, "78px", "30px" ); Widget_SetSize( btn_area, NULL, "30px" ); Widget_SetDock( btn_area, DOCK_TYPE_BOTTOM ); Widget_Resize( me_pic_box, Size(110, 140) ); Widget_Resize( cpu_pic_box, Size(110, 140) ); /* 自定义这四个按钮的风格 */ Button_CustomStyle( btn_b, &btn_normal, &btn_over, &btn_down, &btn_focus, NULL); Button_CustomStyle( btn_s, &btn_normal, &btn_over, &btn_down, &btn_focus, NULL); Button_CustomStyle( btn_j, &btn_normal, &btn_over, &btn_down, &btn_focus, NULL); Button_CustomStyle( btn_next, &btn_normal, &btn_over, &btn_down, &btn_focus, NULL); /* 设定部件的定位类型 */ Widget_SetPosType( btn_s, POS_TYPE_STATIC ); Widget_SetPosType( btn_j, POS_TYPE_STATIC ); Widget_SetPosType( btn_b, POS_TYPE_STATIC ); Widget_SetPosType( btn_next, POS_TYPE_STATIC ); /* 设定布局 */ Widget_SetAlign(me_pic_box, ALIGN_MIDDLE_LEFT, Pos(5, -5)); Widget_SetAlign(cpu_pic_box, ALIGN_MIDDLE_RIGHT, Pos(-5, -5)); Widget_SetAlign(label, ALIGN_TOP_CENTER, Pos(0, 3)); Widget_SetAlign(l_vs, ALIGN_MIDDLE_CENTER, Pos(0, 0)); /* 设定部件的边框及颜色 */ Widget_SetBorder(me_pic_box, Border(1, BORDER_STYLE_SOLID, RGB(0,0,0))); Widget_SetBorder(cpu_pic_box, Border(1, BORDER_STYLE_SOLID, RGB(0,0,0))); /* 关联这些按钮的单击事件 */ Widget_Event_Connect(btn_s, EVENT_CLICKED, select_stone ); Widget_Event_Connect(btn_j, EVENT_CLICKED, select_knife ); Widget_Event_Connect(btn_b, EVENT_CLICKED, select_cloth ); Widget_Event_Connect(btn_next, EVENT_CLICKED, next ); Widget_Event_Connect(Window_GetCloseButton(window), EVENT_CLICKED, destroy); }