/** 设置显示区域的尺寸,仅在窗口化、全屏模式下有效 */ void LCUIDisplay_SetSize( int width, int height ) { LCUI_Widget root; if( display.mode == LCDM_SEAMLESS ) { return; } root = LCUIWidget_GetRoot(); Widget_Resize( root, width, height ); }
int main( int argc, char **argv ) { LCUI_Widget w, root, text; LCUI_Graph desktop_image; InitConsoleWindow(); LCUI_Init(); LCUIDisplay_SetMode( LDM_WINDOWED ); LCUIDisplay_SetSize( 960, 540 ); w = LCUIWidget_New("debug-widget"); text = LCUIWidget_New("textview"); Widget_Append( w, text ); TextView_SetTextW( text, L"测试文本内容,呵呵达!\nABCDEFG,abcdefg,[color=#ff0000]color font[/color]"); Widget_Top( w ); Widget_Show( w ); Widget_Resize( w, 320, 240 ); Widget_Move( w, 200, 200 ); Widget_SetTitleW( w, L"测试" ); Graph_Init( &desktop_image ); Graph_LoadImage( "images/background-image.png", &desktop_image ); root = LCUIWidget_GetRoot(); Widget_PullStyle( root, WSS_BACKGROUND ); root->style.background.color = RGB(255,242,223); root->style.background.image = desktop_image; root->style.background.size.using_value = TRUE; root->style.background.size.value = SV_COVER; Widget_PushStyle( root, WSS_BACKGROUND ); Widget_PullStyle( w, WSS_BACKGROUND | WSS_SHADOW | WSS_BORDER ); w->style.background.color.value = 0xccffffff; w->style.background.size.w.scale = 0.50; w->style.background.size.h.px = 200; w->style.background.size.w.type = SVT_SCALE; w->style.background.size.h.type = SVT_PX; w->style.background.size.using_value = FALSE; w->style.background.position.using_value = TRUE; w->style.background.position.value = SV_BOTTOM_CENTER; w->style.shadow.color = ARGB(200,0,122,204); w->style.shadow.x = 2; w->style.shadow.y = 2; w->style.shadow.spread = 0; w->style.shadow.blur = 8; w->style.border.top.width = 1; w->style.border.right.width = 1; w->style.border.bottom.width = 1; w->style.border.left.width = 1; w->style.border.top.color = RGB(0,122,204); w->style.border.right.color = RGB(0,122,204); w->style.border.bottom.color = RGB(0,122,204); w->style.border.left.color = RGB(0,122,204); Widget_PushStyle( w, WSS_BACKGROUND | WSS_SHADOW | WSS_BORDER ); //LCUITimer_Set( 5000, onTimer, NULL, TRUE ); return LCUI_Main(); }
/** 获取屏幕高度 */ int LCUIDisplay_GetHeight( void ) { if( !display.is_working ) { return 0; } if( display.mode == LCDM_WINDOWED || display.mode == LCDM_FULLSCREEN ) { return LCUIWidget_GetRoot()->height; } return display.driver.getHeight(); }
LCUI_Surface LCUIDisplay_GetSurfaceOwner( LCUI_Widget w ) { if( LCUIDisplay_GetMode() == LCDM_SEAMLESS ) { while( w->parent ) { w = w->parent; } } else { w = LCUIWidget_GetRoot(); } return LCUIDisplay_GetBindSurface( w ); }
size_t Widget_GetInvalidArea( LCUI_Widget w, LinkedList *rects ) { LCUI_RectGroup group; if( !w || w == LCUIWidget_GetRoot() ) { LinkedList_Concat( rects, &self.rects ); return (size_t)rects->length; } group = RBTree_CustomGetData( &self.groups, w ); if( group ) { LinkedList_Concat( rects, &group->rects ); } return (size_t)rects->length; }
static LCUI_Widget create_widget( void ) { LCUI_Widget w, root; w = LCUIWidget_New( NULL ); root = LCUIWidget_GetRoot(); Widget_Append( root, w ); Widget_Resize( w, WIDGET_WIDTH, WIDGET_HEIGHT ); Widget_SetPosition( w, SV_ABSOLUTE ); Widget_SetBoxSizing( w, SV_BORDER_BOX ); Widget_SetBorder( w, 1, SV_SOLID, RGB( 100, 100, 100 ) ); Widget_SetStyle( w, key_background_color, RGB( 200, 200, 200 ), color ); return w; }
void LCUIWidget_Update(void) { int count = 0; LCUI_Widget root; /* 前两次更新需要主动刷新所有部件的样式,主要是为了省去在应用程序里手动调用 * LCUIWidget_RefreshStyle() 的麻烦 */ if (self.update_count < 2) { LCUIWidget_RefreshStyle(); self.update_count += 1; } root = LCUIWidget_GetRoot(); while (Widget_Update(root) && count++ < 5); LCUIWidget_ClearTrash(); }
void LCUIWidget_StepTask( void ) { LinkedListNode *node; self.is_timeout = FALSE; self.timeout = LCUI_GetTime() + 20; Widget_UpdateEx( LCUIWidget_GetRoot(), TRUE ); /* 删除无用部件 */ node = self.trash.head.next; while( node ) { LinkedListNode *next = node->next; LinkedList_Unlink( &self.trash, node ); Widget_ExecDestroy( node->data ); node = next; } }
static int LCUIDisplay_FullScreen( void ) { LCUI_Widget root = LCUIWidget_GetRoot(); switch( display.mode ) { case LCDM_SEAMLESS: LCUIDisplay_CleanSurfaces(); LCUIDisplay_BindSurface(root ); case LCDM_WINDOWED: default: break; case LCDM_FULLSCREEN: return 0; } display.mode = LCDM_FULLSCREEN; LCUIDisplay_SetSize( LCUIDisplay_GetWidth(), LCUIDisplay_GetHeight() ); return 0; }
int main( int argc, char **argv ) { LCUI_Widget root, pack, btn; LCUI_Init(); root = LCUIWidget_GetRoot(); pack = LCUIBuilder_LoadFile( "helloworld.xml" ); if( !pack ) { return -1; } Widget_Append( root, pack ); Widget_Unwrap( pack ); btn = LCUIWidget_GetById( "btn" ); Widget_BindEvent( btn, "click", OnBtnClick, NULL, NULL ); return LCUI_Main(); }
int main( int argc, char **argv ) { LCUI_Widget root, box; #ifdef LCUI_BUILD_IN_WIN32 InitConsoleWindow(); #endif LCUI_Init(); LCUIDisplay_SetMode( LDM_WINDOWED ); LCUIDisplay_SetSize( 960, 540 ); box = LCUIBuilder_LoadFile("hello.xml"); if( box ) { root = LCUIWidget_GetRoot(); Widget_Append( root, box ); Widget_Unwrap( &box ); } return LCUI_Main(); }
LCUI_BOOL Widget_InvalidateArea( LCUI_Widget widget, LCUI_RectF *in_rect, int box_type ) { int mode; LCUI_Rect area; LCUI_RectF rect; LCUI_Widget w = widget; LCUI_Widget root = LCUIWidget_GetRoot(); LCUI_RectGroup group; if( !w ) { w = root; } mode = LCUIDisplay_GetMode(); Widget_AdjustArea( w, in_rect, &rect, box_type ); rect.x += w->box.graph.x; rect.y += w->box.graph.y; while( w && w->parent ) { LCUIRectF_ValidateArea( &rect, w->parent->box.padding.width, w->parent->box.padding.height ); if( rect.width <= 0 || rect.height <= 0 ) { return FALSE; } if( mode != LCDM_SEAMLESS && w->parent == root ) { break; } w = w->parent; rect.x += w->box.padding.x; rect.y += w->box.padding.y; } RectFToInvalidArea( &rect, &area ); if( mode != LCDM_SEAMLESS ) { RectList_Add( &self.rects, &area ); return TRUE; } group = RBTree_CustomGetData( &self.groups, w ); if( !group ) { group = NEW( LCUI_RectGroupRec, 1 ); group->widget = w; LinkedList_Init( &group->rects ); RBTree_CustomInsert( &self.groups, w, group ); } return RectList_Add( &group->rects, &area ) == 0; }
static int LCUIDisplay_Windowed( void ) { LCUI_Widget root = LCUIWidget_GetRoot(); switch( display.mode ) { case LCDM_WINDOWED: return 0; case LCDM_FULLSCREEN: break; case LCDM_SEAMLESS: default: LCUIDisplay_CleanSurfaces(); LCUIDisplay_BindSurface( root ); break; } Widget_Show( root ); Widget_Resize( root, DEFAULT_WIDTH, DEFAULT_HEIGHT ); display.mode = LCDM_WINDOWED; return 0; }
static int LCUIDisplay_Seamless( void ) { LinkedListNode *node; LCUI_Widget root = LCUIWidget_GetRoot(); DEBUG_MSG("display.mode: %d\n", display.mode); switch( display.mode ) { case LCDM_SEAMLESS: return 0; case LCDM_FULLSCREEN: case LCDM_WINDOWED: default: LCUIDisplay_CleanSurfaces(); break; } for( LinkedList_Each( node, &root->children ) ) { LCUIDisplay_BindSurface( node->data ); } display.mode = LCDM_SEAMLESS; return 0; }
int test_widget_inline_block_layout( void ) { int ret = 0; LCUI_Widget root, pack; LCUI_Init(); TEST_LOG( "test widget inline block layout\n" ); LCUIDisplay_SetSize( SCREEN_WIDTH, SCREEN_HEIGHT ); root = LCUIWidget_GetRoot(); CHECK( pack = LCUIBuilder_LoadFile( "test_widget_inline_block_layout.xml" ) ); if( !pack ) { LCUI_Destroy(); return ret; } Widget_UpdateStyle( root, TRUE ); Widget_Append( root, pack ); Widget_Unwrap( pack ); LCUIWidget_Update(); ret += check_layout(); LCUI_Destroy(); return ret; }
int test_xml_parser( void ) { int ret = 0; LCUI_Widget root, pack; LCUI_Init(); TEST_LOG( "test widget layout\n" ); LCUIDisplay_SetSize( 960, 680 ); root = LCUIWidget_GetRoot(); CHECK( pack = LCUIBuilder_LoadFile( "test_xml_parser.xml" ) ); if( !pack ) { LCUI_Destroy(); return ret; } Widget_UpdateStyle( root, TRUE ); Widget_Append( root, pack ); Widget_Unwrap( pack ); LCUIWidget_Update(); ret += check_widget_attribute(); LCUI_Destroy(); return ret; }
void LCUIWidget_RefreshStyle(void) { LCUI_Widget root = LCUIWidget_GetRoot(); Widget_UpdateStyle(root, TRUE); Widget_AddTaskForChildren(root, LCUI_WTASK_REFRESH_STYLE); }
void Load( Platform::String^ entryPoint ); }; static void OnBtnClick( LCUI_Widget self, LCUI_WidgetEvent e, void *arg ) { wchar_t str[256]; LCUI_Widget edit = LCUIWidget_GetById( "edit" ); LCUI_Widget txt = LCUIWidget_GetById( "text-hello" ); TextEdit_GetTextW( edit, 0, 255, str ); TextView_SetTextW( txt, str ); } void App::Load( Platform::String^ entryPoint ) { LCUI_Widget btn, root, pack; root = LCUIWidget_GetRoot(); pack = LCUIBuilder_LoadFile( "helloworld.xml" ); if( !pack ) { return; } Widget_Append( root, pack ); Widget_Unwrap( pack ); btn = LCUIWidget_GetById( "btn" ); Widget_BindEvent( btn, "click", OnBtnClick, NULL, NULL ); } [Platform::MTAThread] int main( Platform::Array<Platform::String^>^ ) { App app; LCUI::Initialize();