定制 toknot/php-libui 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

toknot/php-libui

Composer 安装命令:

composer require toknot/php-libui

包简介

PHP bindings to the libui C library.

README 文档

README

php-libui

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.

Requirements

  • PHP >= 8.1
  • PHP FFI extension available
  • libui latest version

A Simple Example

see https://github.com/chopins/http-request

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();

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

Use UIBuild create UI

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 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' => []
    ]
]
<?xml version="1.0" encoding="UTF-8"?>
<window title="window title name" width="600" height="800" fullscreen="0" onclose="HTTP::quit">
<menu>
    </menu>
<body>
</body>
</window>

window attribute key list:

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
fullscreen int window margin 0
quit \UI\Event quit callback null
close \UI\Event close callback null
resize \UI\Event resize callback null

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:

attr type Description require
title string menu title yes
type string menu type, value is text,quit,about,preferences or checkbox, default is text no
click \UI\Event click callback no
childs array child menu list no

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:

    attr type Description require
    type string control type, smiliar HTML <button> 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 value
    yes
    title string button label name yes
    click \UI\Event when click callback, when type file and save is after select file call no
    change \UI\Event only when color and font available, select color or font be call no
    id string no
  2. 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 vertical yes
    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
  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:

    attr type Description require
    type string miliar HTML <input> 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
    yes
    readonly bool whether readonly no
    wrap bool only textarea is available, false is non wrapping textarea no
    option array radio and select available, element value is option title, key is natural order number no
    change \UI\Event exclude checkbox and radio no
    title string checkbox available yes
    click \UI\Event only radio and checkbox available no
    min int number and slider available yes
    max int number and slider available yes
    id string no
    editable bool select available no
  8. form form layout, has padded, childs,id attr, child widget has label attr

  9. 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_halign int no
    child_vexpand int no
    child_valign int no
    childs array no
    id string no
  10. table table control, table cell has change event, it is 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 of button, image, imgtext, progress, checkbox, checkboxtext, color, text
    5. widget has change attr, for row column change callback
    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, has src width height
    2. color type has r,g,b
    3. rowBgcolor
    yes
    id string no
  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:

    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 width no
    height int the image control heigth, default is src first element image width no
    id string no
  13. datetime datetime control

    attr type description require
    type string specify one of value time,date,datetime yes
    change \UI\Event no
    id string no
  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:

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

specify control see class statement in control directory

UI method

see UI.php

UIBuild method

see UIBuild.php

toknot/php-libui 适用场景与选型建议

toknot/php-libui 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54 次下载、GitHub Stars 达 72, 最近一次更新时间为 2019 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「ui」 「ffi」 「libui」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 toknot/php-libui 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 toknot/php-libui 我们能提供哪些服务?
定制开发 / 二次开发

基于 toknot/php-libui 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 54
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 72
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 72
  • Watchers: 5
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-09-21