{"id":26856706,"url":"https://github.com/huaiminnotsleepyet/nwidget2","last_synced_at":"2025-05-05T22:53:49.346Z","repository":{"id":285267781,"uuid":"957156574","full_name":"HuaiminNotSleepYet/nwidget2","owner":"HuaiminNotSleepYet","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-29T13:15:26.000Z","size":567,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-05T22:53:45.015Z","etag":null,"topics":["declarative-ui","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,"zenodo":null}},"created_at":"2025-03-29T17:30:04.000Z","updated_at":"2025-05-01T16:38:26.000Z","dependencies_parsed_at":"2025-03-30T18:24:18.685Z","dependency_job_id":"111e125d-9235-40a9-96c5-ec107a4776a1","html_url":"https://github.com/HuaiminNotSleepYet/nwidget2","commit_stats":null,"previous_names":["huaiminnotsleepyet/nwidget2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuaiminNotSleepYet%2Fnwidget2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuaiminNotSleepYet%2Fnwidget2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuaiminNotSleepYet%2Fnwidget2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuaiminNotSleepYet%2Fnwidget2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HuaiminNotSleepYet","download_url":"https://codeload.github.com/HuaiminNotSleepYet/nwidget2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252590533,"owners_count":21772935,"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-ui","gui","qt","qwidget"],"created_at":"2025-03-31T00:23:14.123Z","updated_at":"2025-05-05T22:53:49.338Z","avatar_url":"https://github.com/HuaiminNotSleepYet.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nwidget2\n\nnwidget is a `header-only` library that provides `property binding`, `animation`, `declarative syntax` extension for QWidget.\n\n## Template Meta-Object System\n\n```cpp\n#include \u003cnwidget/metaobjects.h\u003e\n\nusing namespace nwidget;\n\nusing MetaObj  = MetaObject\u003cQWidget\u003e;\nusing MetaProp = decltype(MetaObj().fullScreen());\n\nusing Class      = MetaObj::Class;        // QWidget\nusing SuperClass = MetaObj::Super::Class; // QObject\n\nusing Type              = MetaProp::Type;       // bool\nconstexpr bool readable = MetaProp::isReadable; // true\nconstexpr bool writable = MetaProp::isWritable; // false\n```\n\n## Property Binding\n\n```cpp\n#include \u003cnwidget/binding.h\u003e\n\nusing namespace nwidget;\n\nauto label   = MetaObject\u003c\u003e::from(new QLabel);\nauto slider1 = MetaObject\u003c\u003e::from(new QSlider);\nauto slider2 = MetaObject\u003c\u003e::from(new QSlider);\n\nlabel.text() = nwidget::asprintf_(\"%d\", slider1.value() + slider2.value());\n```\n\n![](./docs/imgs/property_binding.gif)\n\n## Animation\n\n```cpp\n#include \u003cnwidget/behavior.h\u003e\n\nusing namespace nwidget;\n\nauto rect     = MetaObject\u003c\u003e::from(new QWidget);\nauto checkBox = MetaObject\u003c\u003e::from(new QCheckBox);\n\nrect.styleSheet() = \"background: #FF0000\";\n\nBehavior::on(rect.minimumWidth(),\n             new SpringAnimation\u003cint\u003e(\n                 spring{2},\n                 damping{0.2}));\n\ncond(checkBox.checked(), 300, 50).bindTo(Behavior::animated(rect.minimumWidth()));\n```\n\n![](./docs/imgs/animation.gif)\n\n## Declarative UI Syntax\n\n```cpp\n#include \u003cnwidget/builders.h\u003e\n\nusing namespace nwidget;\n\nQLayout* layout = FormLayout{\n    {\"Label 0\", LineEdit().text(\"Hello\")},\n    {\"Label 1\", Slider(Qt::Horizontal).range(0, 100).value(25)},\n    {GridLayout{\n        {0, 0,       PushButton(\"Button 0\")},\n        {1, 0,       PushButton(\"Button 1\")},\n        {0, 1, 2, 1, PushButton(\"Button 2\").sizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding),\n        },\n    }}};\n```\n\n![](./docs/imgs/declarative_ui_syntax.png)\n\n## Header Files\n\n| Header File   | Description                                                      |\n| ------------- | ---------------------------------------------------------------- |\n| behavior.h    | Animation and Behavior                                           |\n| binding.h     | Property Binding                                                 |\n| builder.h     | Declarative UI Syntax Builder                                    |\n| builders.h    | Builder specialization for Qt classes, include after Qt headers  |\n| metaobject.h  | Template Meta-Object System                                      |\n| metaobjects.h | Template specialization for Qt classes, include after Qt headers |\n\n## Examples\n\n[MCDayNightSwitchButton](./examples/MCDayNightSwitchButton)\n\n![](./docs/imgs/MCDayNightSwitchButton.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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuaiminnotsleepyet%2Fnwidget2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuaiminnotsleepyet%2Fnwidget2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuaiminnotsleepyet%2Fnwidget2/lists"}