项目作者: alialib

项目描述 :
a declarative UI library for C++
高级语言: C++
项目地址: git://github.com/alialib/alia.git
创建时间: 2017-06-15T13:24:24Z
项目社区:https://github.com/alialib/alia

开源协议:MIT License

下载


alia - A Library for Interactive Applications

MSVC Build Status
GCC Build Status
Clang Build Status
Docs
HTML
Code Coverage
C++ Support
Stability

alia (pronounced uh-LEE-uh) is a modern C++ library for declaratively
developing user interfaces.

alia currently targets the web. It leverages
Emscripten and
asm-dom to allow you to write client-side
web apps in C++. The declarative core of alia, however, is independent of all
this, and the intention is to eventually target other environments, including
native desktop applications. Stay tuned…

For more info on alia, see its website.

Obligatory pretty picture and code… (Click the image for the
interactive version!)

alia/HTML Tip Calculator

  1. void
  2. tip_calculator(html::context ctx)
  3. {
  4. // Get some component-local state for the bill amount.
  5. auto bill = get_state(ctx, empty<double>());
  6. p(ctx, "How much is the bill?");
  7. // Display an input that allows the user to manipulate our bill state.
  8. input(ctx, bill);
  9. // Get some more component-local state for the tip rate.
  10. auto tip_rate = get_state(ctx, empty<double>());
  11. p(ctx, "What percentage do you want to tip?");
  12. // Users like percentages, but we want to keep the 'tip_rate' state as a
  13. // rate internally, so this input presents a scaled view of it for the user.
  14. input(ctx, scale(tip_rate, 100));
  15. // Add a few buttons that set the tip rate to common values.
  16. button(ctx, "18%", tip_rate <<= 0.18);
  17. button(ctx, "20%", tip_rate <<= 0.20);
  18. button(ctx, "25%", tip_rate <<= 0.25);
  19. // Calculate the results and display them for the user.
  20. // Note that these operations have dataflow semantics, and since `bill` and
  21. // `tip_rate` both start out empty, nothing will actually be calculated
  22. // (or displayed) until the user supplies values for them.
  23. auto tip = bill * tip_rate;
  24. auto total = bill + tip;
  25. p(ctx,
  26. printf(ctx,
  27. "You should tip %.2f, for a total of %.2f.", tip, total));
  28. // Conditionally display a message suggesting cash for small amounts.
  29. alia_if (total < 10)
  30. {
  31. p(ctx,
  32. "You should consider using cash for small amounts like this.");
  33. }
  34. alia_end
  35. }