azul
1.0.0
Azul 是一個適用於 Rust、C 和 C++ 的免費、實用、反應式 GUI 框架,使用 WebRender 渲染引擎和類似 CSS / HTML 的文檔物件模型構建,用於快速開發美觀的本機桌面應用程式
Azul 使用 webrender(Firefox 背後的渲染引擎)來渲染您的 UI,因此它支援許多常見的 CSS 功能,例如:
有關詳細信息,請參閱支援的 CSS 鍵/值的列表。
最重要的是,Azul 具有...
* 靜態連結尚未可用
** C++ 綁定和 Python 尚未穩定,可能無法運作,這取決於您使用的分支。它們將在發布前穩定下來。
from azul import *
class DataModel :
def __init__ ( self , counter ):
self . counter = counter
def render_dom ( data , info ):
label = Dom . text ( "{}" . format ( data . counter ))
label . set_inline_style ( "font-size: 50px;" )
button = Button ( "Increment counter" )
button . set_on_click ( data , increment_counter )
dom = Dom . body ()
dom . add_child ( label )
dom . add_child ( button . dom ())
return dom . style ( Css . empty ())
def increment_counter ( data , info ):
data . counter += 1 ;
return Update . RefreshDom
app = App ( DataModel ( 5 ), AppConfig ( LayoutSolver . Default ))
app . run ( WindowCreateOptions ( render_dom ))
use azul :: prelude :: * ;
use azul :: widgets :: { button :: Button , label :: Label } ;
struct DataModel {
counter : usize ,
}
extern "C"
fn render_dom ( data : & mut RefAny , _ : & mut LayoutInfo ) -> StyledDom {
let data = data . downcast_ref :: < DataModel > ( ) ? ;
let label = Dom :: text ( format ! ( "{}" , data . counter ) )
. with_inline_style ( "font-size: 50px;" ) ;
let button = Button :: new ( "Increment counter" )
. onmouseup ( increment_counter , data . clone ( ) ) ;
Dom :: body ( )
. with_child ( label )
. with_child ( button . dom ( ) )
. style ( Css :: empty ( ) )
}
extern "C"
fn increment_counter ( data : & mut RefAny , _ : & mut CallbackInfo ) -> Update {
let mut data = data . downcast_mut :: < DataModel > ( ) ? ;
data . counter += 1 ;
Update :: RefreshDom // call render_dom() again
}
fn main ( ) {
let initial_data = RefAny :: new ( DataModel { counter : 0 } ) ;
let app = App :: new ( initial_data , AppConfig :: default ( ) ) ;
app . run ( WindowCreateOptions :: new ( render_dom ) ) ;
}
#include "azul.h"
typedef struct {
uint32_t counter ;
} DataModel ;
void DataModel_delete ( DataModel * restrict A ) { }
AZ_REFLECT ( DataModel , DataModel_delete );
AzStyledDom render_dom ( AzRefAny * data , AzLayoutInfo * info ) {
DataModelRef d = DataModelRef_create ( data );
if !( DataModel_downcastRef ( data , & d )) {
return AzStyledDom_empty ();
}
char buffer [ 20 ];
int written = snprintf ( buffer , 20 , "%d" , d -> counter );
AzString const labelstring = AzString_copyFromBytes ( & buffer , 0 , written );
AzDom label = AzDom_text ( labelstring );
AzString const inline_css = AzString_fromConstStr ( "font-size: 50px;" );
AzDom_setInlineStyle ( & label , inline_css );
AzString const buttontext = AzString_fromConstStr ( "Increment counter" );
AzButton button = AzButton_new ( buttontext , AzRefAny_clone ( data ));
AzButton_setOnClick ( & button , incrementCounter );
AzDom body = Dom_body ();
AzDom_addChild ( body , AzButton_dom ( & button ));
AzDom_addChild ( body , label );
AzCss global_css = AzCss_empty ();
return AzDom_style ( body , global_css );
}
Update incrementCounter ( RefAny * data , CallbackInfo * event ) {
DataModelRefMut d = DataModelRefMut_create ( data );
if !( DataModel_downcastRefMut ( data , & d )) {
return Update_DoNothing ;
}
d -> ptr . counter += 1 ;
DataModelRefMut_delete ( & d );
return Update_RefreshDom ;
}
int main () {
DataModel model = { . counter = 5 };
AzApp app = AzApp_new ( DataModel_upcast ( model ), AzAppConfig_default ());
AzApp_run ( app , AzWindowCreateOptions_new ( render_dom ));
return 0 ;
}
Azul 根據 MPL-2.0 獲得許可。這意味著,是的,您可以使用 azul 建立專有應用程序,而無需發布程式碼:您只需發布對庫本身所做的更改。
版權所有 2017 - 現任 Felix Schütt