{"id":15021565,"url":"https://github.com/huaiminnotsleepyet/nwidget","last_synced_at":"2025-10-29T07:32:43.515Z","repository":{"id":251186057,"uuid":"836573154","full_name":"HuaiminNotSleepYet/nwidget","owner":"HuaiminNotSleepYet","description":"Create QWidget program UI in declerative syntax.","archived":false,"fork":false,"pushed_at":"2024-09-26T11:39:23.000Z","size":1071,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T23:41:16.402Z","etag":null,"topics":["declarative","gui","qt","qwidget"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HuaiminNotSleepYet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-01T06:15:45.000Z","updated_at":"2025-01-01T16:49:49.000Z","dependencies_parsed_at":"2024-09-14T08:16:40.769Z","dependency_job_id":"6f5fc7a8-8922-427a-a530-2ff45fc135ad","html_url":"https://github.com/HuaiminNotSleepYet/nwidget","commit_stats":{"total_commits":98,"total_committers":1,"mean_commits":98.0,"dds":0.0,"last_synced_commit":"2543f86589d5ff1e3b06c4b314f0f2478d3ece8d"},"previous_names":["huaiminnotsleepyet/nwidget"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuaiminNotSleepYet%2Fnwidget","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuaiminNotSleepYet%2Fnwidget/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuaiminNotSleepYet%2Fnwidget/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuaiminNotSleepYet%2Fnwidget/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HuaiminNotSleepYet","download_url":"https://codeload.github.com/HuaiminNotSleepYet/nwidget/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238791894,"owners_count":19531027,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["declarative","gui","qt","qwidget"],"created_at":"2024-09-24T19:56:43.699Z","updated_at":"2025-10-29T07:32:43.506Z","avatar_url":"https://github.com/HuaiminNotSleepYet.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nwidget\n\n\n\u003e [nwidget2](https://github.com/HuaiminNotSleepYet/nwidget2) is now available. It is a complete rewrite of nwidget, with a more elegant API and more features.\n\n\n[中文](./doc/zh_cn/README.md)\n\nnwidget is a `header only` library that provides `declarative syntax` and `property binding` extensions to QWidget.\n\n[Document](./doc/en/Document.md)\n\n## Features\n\n### Declarative Syntax\n\n![](./doc/img/nwidget.png)\n\nImperative:\n```cpp\nauto* lineEdit = new QLineEdit;\nlineEdit-\u003esetText(\"Hello\");\nauto* slider = new QSlider(Qt::Horizontal);\nslider-\u003esetRange(0, 100);\nslider-\u003esetValue(25);\n\nauto* button0 = new QPushButton(\"Button 0\");\nauto* button1 = new QPushButton(\"Button 1\");\nauto* button2 = new QPushButton(\"Button 2\");\nbutton2-\u003esetSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);\n\nauto* gridLayout = new QGridLayout;\ngridLayout-\u003eaddWidget(button0, 0, 0);\ngridLayout-\u003eaddWidget(button1, 1, 0);\ngridLayout-\u003eaddWidget(button2, 0, 1, 2, 1);\n\nauto* formLayout = new QFormLayout;\nformLayout-\u003eaddRow(\"Line 0\", lineEdit);\nformLayout-\u003eaddRow(\"Line 1\", slider);\nformLayout-\u003eaddRow(gridLayout);\n```\n\nDeclarative:\n```cpp\nnamespace nw = nwidget;\n\nQLayout* layout = nw::FormLayout{\n    {\"Label 0\", nw::LineEdit().text(\"Hello\")},\n    {\"Label 1\", nw::Slider(Qt::Horizontal).range(0, 100).value(25)},\n    {GridLayout{\n        {0, 0,       nw::PushButton(\"Button 0\")},\n        {1, 0,       nw::PushButton(\"Button 1\")},\n        {0, 1, 2, 1, nw::PushButton(\"Button 2\").sizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding)\n        },\n    }}};\n```\n\n### Property Binding\n\n![](./doc/img/binding.gif)\n\n```cpp\nnamespace nw = nwidget;\n\nnw::LabelId  label   = new QLabel;\nnw::SliderId slider1 = new QSlider;\nnw::SliderId slider2 = new QSlider;\n\nQLayout* layout = nw::VBoxLayout{\n    nw::Label(label)\n        .text(nw::asprintf(\"%d\", slider1.value() + slider2.value())), // create a binding\n    nw::Slider(slider1).orientation(Qt::Horizontal),\n    nw::Slider(slider2).orientation(Qt::Horizontal),\n};\n\n// A binding can also be created in one of three ways:\nlabel.text() = nw::asprintf(\"%d\", slider1.value() + slider2.value());\n\nnw::asprintf(\"%d\", slider1.value() + slider2.value())\n    .bindTo(label, \u0026QLabel::setText);\n\nnw::asprintf(\"%d\", slider1.value() + slider2.value())\n    .bindTo(label, [label](const QString\u0026 s) {label.text() = s;});\n\n```\n\n## Advantages\n\n- Intuitive\n- Easy to modify\n- Easy to maintain\n- Fun\n\n## Installing\n\n```shell\nmkdir build\ncd build\ncmake .. -DCMAKE_INSTALL_PREFIX:PATH=/installation/path\ncmake --build . --config Release --target install\n```\n\n```cmake\nfind_package(nwidget CONFIG REQUIRED)\ntarget_link_libraries(main PRIVATE nwidget::nwidget)\n```\n\n## Examples\n\n[NWidget Gallery](./examples/gallery) : [Widget Gallery](https://doc.qt.io/qt-6/qtwidgets-gallery-example.html) written with nwidget.\n\n![](./doc/img/nwidget_gallery.png)\n\n[Binding Example](./examples/binding_example)\n\n![](./doc/img/binding_example.gif)\n\n[Length Calculator](./examples/length_calculator)\n\n![](./doc/img/length_calculator.gif)\n\n## Special Thanks\n\n- [@QuadnucYard](https://github.com/QuadnucYard) for guidance on C++.\n- [@Niwik](https://github.com/niwik-dev) for suggestions on the property binding.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuaiminnotsleepyet%2Fnwidget","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuaiminnotsleepyet%2Fnwidget","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuaiminnotsleepyet%2Fnwidget/lists"}