示例#1
0
/*
 * 创建一个部件,作为滚动条的容器
 * 再创建一个部件,作为滚动条
 * 限制滚动条的移动范围
 * */
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 );
}
示例#2
0
文件: LCUI_Window.c 项目: dwdcth/LCUI
static void Window_Init(LCUI_Widget *win_p)
/*
 * 功能:初始化窗口
 * 说明:类似于构造函数
 **/
{
    LCUI_Widget *titlebar;
    LCUI_Widget *client_area;
    LCUI_Widget *btn_close;
    LCUI_Window *win;

    win = (LCUI_Window*)Widget_Create_PrivData(win_p, sizeof(LCUI_Window));

    win->hide_style	= NONE;
    win->show_style	= NONE;
    win->count	= 0;
    win->init_align	= ALIGN_MIDDLE_CENTER;

    /* 创建一个标题栏部件 */
    titlebar = Create_Widget("titlebar");
    /* 再创建一个客户区部件 */
    client_area = Create_Widget(NULL);
    btn_close = Create_Widget("button");

    static LCUI_Graph btn_highlight, btn_normal, btn_down;
    Graph_Init(&btn_down);
    Graph_Init(&btn_highlight);
    Graph_Init(&btn_normal);
    /* 载入默认图形 */
    Load_Graph_Default_TitleBar_CloseBox_Normal(&btn_normal);
    Load_Graph_Default_TitleBar_CloseBox_Down(&btn_down);
    Load_Graph_Default_TitleBar_CloseBox_HighLight(&btn_highlight);
    /* 显示在左上角 */
    Set_Widget_Align(btn_close, ALIGN_TOP_RIGHT, Pos(0, -2));
    /* 将尺寸改成和图片一样 */
    Resize_Widget(btn_close, Size(btn_normal.width, btn_normal.height));
    Custom_Button_Style(btn_close, &btn_normal, &btn_highlight,
                        &btn_down, NULL, NULL);
    /* 关联按钮的点击事件,当按钮被点击后,调用Quit_Window函数 */
    Widget_Clicked_Event_Connect(btn_close, Quit_Parent_Window, NULL);
    Graph_Free(&btn_highlight);
    Graph_Free(&btn_down);
    Graph_Free(&btn_normal);

    win->client_area = client_area;
    win->titlebar = titlebar;
    win->btn_close = btn_close;
    /* 没有背景图就填充背景色 */
    Set_Widget_BG_Mode(win_p, BG_MODE_FILL_BACKCOLOR);
    Set_Widget_Border_Style(win_p, BORDER_STYLE_STANDARD);
    /* 放入至容器 */
    Widget_Container_Add(titlebar, btn_close);
    Widget_Container_Add(win_p, titlebar);
    Widget_Container_Add(win_p, client_area);
    Resize_Widget(win_p, Size(50, 50));
    Show_Widget(btn_close);

    Widget_Drag_Event_Connect(titlebar, Move_Window);
}
示例#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 );
}