PHP bindings to the libui C library.
libui is a lightweight, portable GUI library that uses the native GUI technologies of each platform it supports.
- PHP >= 7.4
- PHP FFI extension available
- libui latest version
first download libui dynamic library from https://github.com/andlabs/libui/releases or checkout source for self-build, then load in php code use following code
include '/src/UI.php';
$ui = new \UI\UI('/usr/lib64/libui.so'); //load libui dynamic library
$ui->init();
$mainwin = $ui->newWindow("libui Control Gallery", 640, 480,1);
$ui->controlShow($mainwin);
$ui->main();
include '/src/UI.php';
$ui = new \UI\UI('/usr/lib64/libui.so');
$config = ['title' => 'test', 'width' => 600,'height' => 450];
$build = $ui->build($config);
$build->show();
build config is array, main key contain body
,menu
and window attribute key; in config array, element key is attr name, element value is attr value,similar the following:
[
'title' => 'window title name',
'width' => 600,
'menu' => [],
'body' => [
'name' => 'box'
'childs' => []
]
]
attr | type | Description | Default Vlaue |
---|---|---|---|
title | string | window title | No Win Title |
width | int | window width | 800 |
height | int | window height | 640 |
border | int | window border | 0 |
margin | int | window margin | 0 |
quit | \UI\Event | quit callback | null |
close | \UI\Event | close callback | null |
resize | \UI\Event | resize callback | null |
The array level 1 of item element is one menu, similar:
[
[
'title' => 'File',
'id' => 'menu_id_1',
'childs' => [
['title' => 'New File'],
['title' => 'Open File'],
]
],
[
'title' => 'Edit',
'id' => 'menu_id_1',
'childs' => [
['title' => 'Undo'],
['title' => 'Copy'],
]
],
]
Top menu only contain title
, id
, childs
, the title
value will display in window, every element of childs
array is submenu that display in drop-down menu. if element is string and equral hr
will display a separator
current Build UI Config of submenu only contain the following attr:
attr | type | Description | require |
---|---|---|---|
title | string | menu title | yes |
type | string | menu type, value is text or checkbox , default is text |
no |
click | \UI\Event | click callback | no |
childs | array | child menu list | no |
every element key of body
array is control config, name
element is control name and attr
element is control attr, Build UI current only support the following control:
-
button
, Button control,contain the following attr:attr type Description require type string control type, smiliar HTML <button>
tag oftype
attr, potential value is following:
1.file
, open file button
2.save
, save file button
3.font
, select font button
4.color
, select color button
5.button
, is default valueyes title string button label name yes click \UI\Event when click callback, when type file
andsave
is after select file callno change \UI\Event only when color
andfont
available, select color or font be callno id string no -
box
box layout,the following attr:attr type Description require dir string layout direction, Specify one of h
is horizontal and default value,v
is verticalyes padded int padding value, default is 0
no child_fit int Whether to automatically adapt no childs array sub control list no id string no -
group
group layout, havetitle
andmargin
,child
,id
attr -
label
text control, only hastitle
andid
attr -
hr
horizontal separator, no attr -
vr
vertical separator, no attr -
input
input control, the following attr:attr type Description require type string miliar HTML <input>
tag oftype
attr, specify one of the following value:
1.password
password entry control
2.search
search entry control
3.textarea
multiline entry control
4.radio
radio
5.select
select
6.checkbox
checkbox
7.text
, is default value
8.number
is Spinbox
9.slider
yes readonly bool whether readonly no wrap bool only textarea
is available,false
is non wrapping textareano option array radio
andselect
available, element value is option title, key is natural order numberno change \UI\Event exclude checkbox
andradio
no title string checkbox
availableyes click \UI\Event only radio
andcheckbox
availableno min int number
andslider
availableyes max int number
andslider
availableyes id string no editable bool select
availableno -
form
form layout, haspadded
,childs
,id
attr -
grid
grid layout, the following attr:attr type Description require padded int no child_left int no child_top int no child_width int no child_height int no child_hexpand int no child_haligin int no child_vexpand int no child_valign int no childs array no id string no -
table
table control, has following sub key :attr type Description require th array every element of value is array, key is id, has the following attr:
1.editable
,bool
type, the column is whether editable
2.textColor
3.title
4.type
, specify value ofbutton
,image
,imgtext
,progress
,checkbox
,checkboxtext
,color
,text
yes tbody array the table row value list, every element is one row value, when row of column is array has the following attr:
1.image
type, hassrc
width
height
2.color
type hasr
,g
,b
3.rowBgcolor
4.change
isarray
, every element is one row change callback list, column iscallable
yes id string no -
tab
tab control, haspage
sub array,page
array every element value is page child control and key is page title -
img
image control, has flowing attr:attr type Description require src array is image paths list, every element value is image file path, key is natural order number yes width int the image control width, default is src
first element image widthno height int the image control heigth, default is src
first element image widthno id string no -
datetime
datetime controlattr type description require type string specify one of value time
,date
,datetime
yes change \UI\Event no id string no -
progress
, hasid
attr -
unsupport control must call libui C function by
UI\UI
- show()
- hide()
- enable()
- disbale()
- destroy()
- parent()
- setParent($parent)
- isVisible()
- isEnabled()
specify control see class statement in control directory
see UI.php
see UIBuild.php