PHPackages                             toknot/php-libui - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. toknot/php-libui

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

toknot/php-libui
================

PHP bindings to the libui C library.

0.2.4(1y ago)72548BSD-3-ClausePHPPHP &gt;=8.1.0

Since Sep 13Pushed 1y ago5 watchersCompare

[ Source](https://github.com/chopins/php-libui)[ Packagist](https://packagist.org/packages/toknot/php-libui)[ Docs](http://toknot.com)[ RSS](/packages/toknot-php-libui/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)DependenciesVersions (4)Used By (0)

[中文说明](README_zh.md)
====================

[](#中文说明)

php-libui
=========

[](#php-libui)

PHP bindings to the [libui](https://github.com/andlabs/libui) C library.

libui is a lightweight, portable GUI library that uses the native GUI technologies of each platform it supports.

### Requirements

[](#requirements)

- PHP &gt;= 8.1
- PHP FFI extension available
- libui latest version

### A Simple Example

[](#a-simple-example)

see

first download libui dynamic library from  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();
```

Note: When Call libui C function need remove `ui` prefix of name, then to lower case first char
-----------------------------------------------------------------------------------------------

[](#note-when-call-libui-c-function-need-remove-ui-prefix-of-name-then-to-lower-case-first-char)

Use UIBuild create UI
=====================

[](#use-uibuild-create-ui)

Basic Usage:
------------

[](#basic-usage)

```
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 structure
----------------------

[](#build-config-structure)

- build config is xml file, see `tests/uibuild.xml`
- **In xml file, all event attribute name must be prefix `on`**, `onclick`,`onchange`,`ondraw`, value is callable name, it is not Event instance, callable name support php variable and php callable:`$var`,`func_name`,`CLASS::method`, do not support array callable. variable is GLOBALS
- attr value support GLOBALS variable and constant, prefix `$``@` as `$var` or `@CONST`
- also build config support 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' => []
    ]
]
```

```

```

window attribute key list:
--------------------------

[](#window-attribute-key-list)

attrtypeDescriptionDefault Vlauetitlestringwindow titleNo Win Titlewidthintwindow width800heightintwindow height640borderintwindow border0marginintwindow margin0fullscreenintwindow margin0quit\\UI\\Eventquit callbacknullclose\\UI\\Eventclose callbacknullresize\\UI\\Eventresize callbacknullmenu array
----------

[](#menu-array)

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:**

attrtypeDescriptionrequiretitlestringmenu titleyestypestringmenu type, value is `text`,`quit`,`about`,`preferences` or `checkbox`, default is `text`noclick\\UI\\Eventclick callbacknochildsarraychild menu listnobody array
----------

[](#body-array)

every element key of `body` array is control config, `widget` element is control name and `attr` element is control attr. see `examples/table.php` **Build UI** current only support the following control:

1. `button`, Button control,contain the following attr:

    attrtypeDescriptionrequiretypestringcontrol type, smiliar HTML `` tag of `type` 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 valueyestitlestringbutton label nameyesclick\\UI\\Eventwhen click callback, when type `file` and `save` is after select file callnochange\\UI\\Eventonly when `color` and `font` available, select color or font be callnoidstringno
2. `box` box layout,the following attr:

    attrtypeDescriptionrequiredirstringlayout direction, Specify one of `h` is horizontal and default value, `v` is verticalyespaddedintpadding value, default is `0`nochild\_fitintWhether to automatically adaptnochildsarraysub control listnoidstringno
3. `group` group layout, have `title` and `margin`, `child`,`id` attr
4. `label` text control, only has `title` and `id` attr
5. `hr` horizontal separator, no attr
6. `vr` vertical separator, no attr
7. `input` input control, the following attr:

    attrtypeDescriptionrequiretypestringmiliar HTML `` tag of `type` 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`yesreadonlyboolwhether readonlynowrapboolonly `textarea` is available, `false` is non wrapping textareanooptionarray`radio` and `select` available, element value is option title, key is natural order numbernochange\\UI\\Eventexclude `checkbox` and `radio`notitlestring`checkbox` availableyesclick\\UI\\Eventonly `radio` and `checkbox` availablenominint`number` and `slider` availableyesmaxint`number` and `slider` availableyesidstringnoeditablebool`select` availableno
8. `form` form layout, has `padded`, `childs`,`id` attr, child widget has label attr
9. `grid` grid layout, the following attr:

    attrtypeDescriptionrequirepaddedintnochild\_leftintnochild\_topintnochild\_widthintnochild\_heightintnochild\_hexpandintnochild\_halignintnochild\_vexpandintnochild\_valignintnochildsarraynoidstringno
10. `table` table control, table cell has change event, it is following sub key :

    attrtypeDescriptionrequiretharrayevery 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 of `button`, `image`, `imgtext`, `progress`, `checkbox`, `checkboxtext`, `color`, `text`
    5. widget has `change` attr, for row column change callbackyestbodyarraythe table row value list, every element is one row value, when row of column is array has the following attr:
    1. `image` type, has `src` `width` `height`
    2. `color` type has `r`,`g`,`b`
    3. `rowBgcolor`yesidstringno
11. `tab` tab control, has `page` sub array, `page` array every element value is page child control and key is page title
12. `img` image control, has flowing attr:

    attrtypeDescriptionrequiresrcarrayis image paths list, every element value is image file path, key is natural order numberyeswidthintthe image control width, default is `src` first element image widthnoheightintthe image control heigth, default is `src` first element image widthnoidstringno
13. `datetime` datetime control

    attrtypedescriptionrequiretypestringspecify one of value `time`,`date`,`datetime`yeschange\\UI\\Eventnoidstringno
14. `progress`, has `id` attr
15. `area`,`canvas` create `Area`
16. `attribute` create `Attribute`
17. `drawtext` create `TextLayout`
18. `string` create a `AttributeString`
19. unsupport control must call libui C function by `UI\UI`
20. `UI\Event`, all event callback class, The signature of the callback is as follows:

```
/**
 * @param UI\Event $callable   The object instance of current event
 *
 * */
function (UI\Event $callable) {}
```

Control common method:
----------------------

[](#control-common-method)

- show()
- hide()
- enable()
- disable()
- destroy()
- parent()
- setParent($parent)
- isVisible()
- isEnabled()

specify control see class statement in control directory

UI method
---------

[](#ui-method)

see `UI.php`

UIBuild method
--------------

[](#uibuild-method)

see `UIBuild.php`

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~683 days

Total

3

Last Release

704d ago

PHP version history (2 changes)v0.1.x-devPHP &gt;=7.4.0

0.2.1PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3683f29364f9fba39ebd7e90377b67c28ca2497e01cefc19ebb40df6cda72ddb?d=identicon)[szopen](/maintainers/szopen)

---

Top Contributors

[![chopins](https://avatars.githubusercontent.com/u/1539465?v=4)](https://github.com/chopins "chopins (101 commits)")[![Yurunsoft](https://avatars.githubusercontent.com/u/20104656?v=4)](https://github.com/Yurunsoft "Yurunsoft (1 commits)")

---

Tags

ffiguilibuiphpuiphpuiffilibui

### Embed Badge

![Health badge](/badges/toknot-php-libui/health.svg)

```
[![Health](https://phpackages.com/badges/toknot-php-libui/health.svg)](https://phpackages.com/packages/toknot-php-libui)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
