/* * 创建一个部件,作为滚动条的容器 * 再创建一个部件,作为滚动条 * 限制滚动条的移动范围 * */ 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 ); }
static void ProgressBar_Init(LCUI_Widget *widget) /* 功能:初始化进度条的数据结构体 */ { LCUI_ProgressBar *pb = (LCUI_ProgressBar*) Widget_Create_PrivData (widget, sizeof(LCUI_ProgressBar)); pb->thread = 0; Graph_Init(&pb->fore_graph); Graph_Init(&pb->flash_image); pb->img_move_speed = 200; pb->sleep_time = 100000; pb->max_value = 1; pb->value = 0; LCUI_Widget *f_pb, *img_pb; f_pb = Create_Widget("picture_box"); img_pb = Create_Widget("picture_box"); /* 以自己为容器,将这些部件放进去 */ Widget_Container_Add(f_pb, img_pb); Widget_Container_Add(widget, f_pb); /* 没有背景图时就填充背景色 */ Set_Widget_BG_Mode(widget, BG_MODE_FILL_BACKCOLOR); Set_Widget_Border(widget, RGB(50,50,50), Border(1,1,1,1)); Set_Widget_Style(widget, "classic"); /* 进度条为经典风格 */ Set_PictureBox_Size_Mode(f_pb, SIZE_MODE_STRETCH); Show_Widget(f_pb); Show_Widget(img_pb); pb->fore_pic_box = f_pb; pb->img_pic_box = img_pb; }
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(); }
void Window_Widget_Auto_Size(LCUI_Widget *win_p) /* 功能:在窗口尺寸改变时自动改变标题栏和客户区的尺寸 */ { int x, y, width, height; LCUI_Widget *titlebar; LCUI_Widget *client_area; titlebar = Get_Window_TitleBar(win_p); client_area = Get_Window_Client_Area(win_p); /* 按不同的风格来处理 */ switch(Get_Widget_Border_Style(win_p)) { case BORDER_STYLE_NONE: /* 没有边框 */ /* 先计算坐标和尺寸 */ x = win_p->border.left; y = win_p->border.top; width = win_p->size.w - x - win_p->border.right; height = win_p->size.h - y - win_p->border.bottom; Move_Widget( client_area, Pos(x, y) );/* 调整位置 */ Resize_Widget( client_area, Size(width, height) );/* 调整大小 */ Hide_Widget( titlebar );/* 隐藏标题栏 */ Show_Widget( client_area );/* 客户区需要显示 */ break; case BORDER_STYLE_LINE_BORDER: /* 线条边框 */ Move_Widget( client_area, Pos(0, 0) ); Resize_Widget( client_area, Size(win_p->size.w, win_p->size.h) ); Hide_Widget( titlebar); Show_Widget( client_area); break; case BORDER_STYLE_STANDARD: /* 标准边框 */ /* * 说明:由于用户区的尺寸和位置的调整,需要确定标题栏的尺寸,因此, * 调用Exec_Resize_Widget()函数立刻调整标题栏尺寸,如果是调用 * Resize_Widget()函数,那么,确定的尺寸会有误,因为标题栏的尺 * 寸还是以前的尺寸。 * */ Set_Widget_Border(win_p, RGB(50,50,50), Border(1,1,1,1)); /* 先计算坐标和尺寸 */ x = win_p->border.left; y = win_p->border.top; width = win_p->size.w - x - win_p->border.right; height = win_p->size.h - y - win_p->border.bottom; Move_Widget(titlebar, Pos(x, y) ); Resize_Widget(titlebar, Size(width, 25)); Set_Widget_Align(client_area, ALIGN_BOTTOM_CENTER, Pos(0, y)); Resize_Widget(client_area, Size(width, height - 23)); /* 标题栏和客户区都需要显示 */ Show_Widget(titlebar); Show_Widget(client_area); break; default: // break; } }
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(); }