core.hpp 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. #include <nall/platform.hpp>
  2. #include <nall/any.hpp>
  3. #include <nall/chrono.hpp>
  4. #include <nall/directory.hpp>
  5. #include <nall/function.hpp>
  6. #include <nall/image.hpp>
  7. #include <nall/locale.hpp>
  8. #include <nall/maybe.hpp>
  9. #include <nall/path.hpp>
  10. #include <nall/range.hpp>
  11. #include <nall/run.hpp>
  12. #include <nall/set.hpp>
  13. #include <nall/shared-pointer.hpp>
  14. #include <nall/stdint.hpp>
  15. #include <nall/string.hpp>
  16. #include <nall/traits.hpp>
  17. #include <nall/unique-pointer.hpp>
  18. #include <nall/utility.hpp>
  19. #include <nall/vector.hpp>
  20. using nall::any;
  21. using nall::function;
  22. using nall::image;
  23. using nall::Locale;
  24. using nall::maybe;
  25. using nall::nothing;
  26. using nall::set;
  27. using nall::shared_pointer;
  28. using nall::shared_pointer_weak;
  29. using nall::string;
  30. using nall::unique_pointer;
  31. using nall::vector;
  32. namespace hiro {
  33. struct Font;
  34. struct Keyboard;
  35. #define Declare(Name) \
  36. struct Name; \
  37. struct m##Name; \
  38. struct p##Name; \
  39. using s##Name = shared_pointer<m##Name>; \
  40. using w##Name = shared_pointer_weak<m##Name>; \
  41. Declare(Object)
  42. Declare(Group)
  43. Declare(Timer)
  44. Declare(Window)
  45. Declare(StatusBar)
  46. Declare(MenuBar)
  47. Declare(PopupMenu)
  48. Declare(Action)
  49. Declare(Menu)
  50. Declare(MenuSeparator)
  51. Declare(MenuItem)
  52. Declare(MenuCheckItem)
  53. Declare(MenuRadioItem)
  54. Declare(Sizable)
  55. Declare(Widget)
  56. Declare(Button)
  57. Declare(Canvas)
  58. Declare(CheckButton)
  59. Declare(CheckLabel)
  60. Declare(ComboButton)
  61. Declare(ComboButtonItem)
  62. Declare(ComboEdit)
  63. Declare(ComboEditItem)
  64. Declare(Console)
  65. Declare(Frame)
  66. Declare(HexEdit)
  67. Declare(HorizontalScrollBar)
  68. Declare(HorizontalSlider)
  69. Declare(IconView)
  70. Declare(IconViewItem)
  71. Declare(Label)
  72. Declare(LineEdit)
  73. Declare(ProgressBar)
  74. Declare(RadioButton)
  75. Declare(RadioLabel)
  76. Declare(SourceEdit)
  77. Declare(TabFrame)
  78. Declare(TabFrameItem)
  79. Declare(TableView)
  80. Declare(TableViewHeader)
  81. Declare(TableViewColumn)
  82. Declare(TableViewItem)
  83. Declare(TableViewCell)
  84. Declare(TextEdit)
  85. Declare(TreeView)
  86. Declare(TreeViewItem)
  87. Declare(VerticalScrollBar)
  88. Declare(VerticalSlider)
  89. Declare(Viewport)
  90. #undef Declare
  91. enum class Orientation : uint { Horizontal, Vertical };
  92. enum class Navigation : uint { Top, Bottom, Left, Right };
  93. enum class Sort : uint { None, Ascending, Descending };
  94. #if defined(Hiro_Color)
  95. struct Color {
  96. using type = Color;
  97. Color();
  98. Color(int red, int green, int blue, int alpha = 255);
  99. explicit operator bool() const;
  100. auto operator==(const Color& source) const -> bool;
  101. auto operator!=(const Color& source) const -> bool;
  102. auto alpha() const -> uint8_t;
  103. auto blue() const -> uint8_t;
  104. auto green() const -> uint8_t;
  105. auto red() const -> uint8_t;
  106. auto reset() -> type&;
  107. auto setAlpha(int alpha) -> type&;
  108. auto setBlue(int blue) -> type&;
  109. auto setColor(Color color = {}) -> type&;
  110. auto setColor(int red, int green, int blue, int alpha = 255) -> type&;
  111. auto setGreen(int green) -> type&;
  112. auto setRed(int red) -> type&;
  113. auto setValue(uint32_t value) -> type&;
  114. auto value() const -> uint32_t;
  115. //private:
  116. struct State {
  117. uint8_t red;
  118. uint8_t green;
  119. uint8_t blue;
  120. uint8_t alpha;
  121. } state;
  122. };
  123. #endif
  124. #if defined(Hiro_Gradient)
  125. struct Gradient {
  126. using type = Gradient;
  127. Gradient();
  128. explicit operator bool() const;
  129. auto operator==(const Gradient& source) const -> bool;
  130. auto operator!=(const Gradient& source) const -> bool;
  131. auto setBilinear(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight) -> type&;
  132. auto setHorizontal(Color left, Color right) -> type&;
  133. auto setVertical(Color top, Color bottom) -> type&;
  134. //private:
  135. struct State {
  136. vector<Color> colors;
  137. } state;
  138. };
  139. #endif
  140. #if defined(Hiro_Alignment)
  141. struct Alignment {
  142. using type = Alignment;
  143. static const Alignment Center;
  144. Alignment();
  145. Alignment(float horizontal, float vertical = 0.5);
  146. explicit operator bool() const;
  147. auto operator==(const Alignment& source) const -> bool;
  148. auto operator!=(const Alignment& source) const -> bool;
  149. auto horizontal() const -> float;
  150. auto reset() -> type&;
  151. auto setAlignment(float horizontal = -1.0, float vertical = 0.5) -> type&;
  152. auto setHorizontal(float horizontal) -> type&;
  153. auto setVertical(float vertical) -> type&;
  154. auto vertical() const -> float;
  155. //private:
  156. struct State {
  157. float horizontal;
  158. float vertical;
  159. } state;
  160. };
  161. #endif
  162. #include "text-cursor.hpp"
  163. #if defined(Hiro_Position)
  164. struct Position {
  165. using type = Position;
  166. Position();
  167. Position(float x, float y);
  168. template<typename X, typename Y>
  169. Position(X x, Y y) : Position((float)x, (float)y) {}
  170. explicit operator bool() const;
  171. auto operator==(const Position& source) const -> bool;
  172. auto operator!=(const Position& source) const -> bool;
  173. auto reset() -> type&;
  174. auto setPosition(Position position = {}) -> type&;
  175. auto setPosition(float x, float y) -> type&;
  176. auto setX(float x) -> type&;
  177. auto setY(float y) -> type&;
  178. auto x() const -> float;
  179. auto y() const -> float;
  180. //private:
  181. struct State {
  182. float x;
  183. float y;
  184. } state;
  185. };
  186. #endif
  187. #if defined(Hiro_Size)
  188. struct Size {
  189. using type = Size;
  190. Size();
  191. Size(float width, float height);
  192. template<typename W, typename H>
  193. Size(W width, H height) : Size((float)width, (float)height) {}
  194. explicit operator bool() const;
  195. auto operator==(const Size& source) const -> bool;
  196. auto operator!=(const Size& source) const -> bool;
  197. auto height() const -> float;
  198. auto reset() -> type&;
  199. auto setHeight(float height) -> type&;
  200. auto setSize(Size source = {}) -> type&;
  201. auto setSize(float width, float height) -> type&;
  202. auto setWidth(float width) -> type&;
  203. auto width() const -> float;
  204. static constexpr float Maximum = -1.0;
  205. static constexpr float Minimum = +0.0;
  206. //private:
  207. struct State {
  208. float width;
  209. float height;
  210. } state;
  211. };
  212. #endif
  213. #if defined(Hiro_Geometry)
  214. struct Geometry {
  215. using type = Geometry;
  216. Geometry();
  217. Geometry(Position position, Size size);
  218. Geometry(float x, float y, float width, float height);
  219. template<typename X, typename Y, typename W, typename H>
  220. Geometry(X x, Y y, W width, H height) : Geometry((float)x, (float)y, (float)width, (float)height) {}
  221. explicit operator bool() const;
  222. auto operator==(const Geometry& source) const -> bool;
  223. auto operator!=(const Geometry& source) const -> bool;
  224. auto height() const -> float;
  225. auto position() const -> Position;
  226. auto reset() -> type&;
  227. auto setGeometry(Geometry geometry = {}) -> type&;
  228. auto setGeometry(Position position, Size size) -> type&;
  229. auto setGeometry(float x, float y, float width, float height) -> type&;
  230. auto setHeight(float height) -> type&;
  231. auto setPosition(Position position = {}) -> type&;
  232. auto setPosition(float x, float y) -> type&;
  233. auto setSize(Size size = {}) -> type&;
  234. auto setSize(float width, float height) -> type&;
  235. auto setWidth(float width) -> type&;
  236. auto setX(float x) -> type&;
  237. auto setY(float y) -> type&;
  238. auto size() const -> Size;
  239. auto width() const -> float;
  240. auto x() const -> float;
  241. auto y() const -> float;
  242. //private:
  243. struct State {
  244. float x;
  245. float y;
  246. float width;
  247. float height;
  248. } state;
  249. };
  250. #endif
  251. #include "font.hpp"
  252. #include "mouse-cursor.hpp"
  253. #if defined(Hiro_Hotkey)
  254. struct Hotkey {
  255. using type = Hotkey;
  256. Hotkey();
  257. Hotkey(const string& sequence);
  258. explicit operator bool() const;
  259. auto operator==(const Hotkey& source) const -> bool;
  260. auto operator!=(const Hotkey& source) const -> bool;
  261. auto doPress() const -> void;
  262. auto doRelease() const -> void;
  263. auto onPress(const function<void ()>& callback = {}) -> type&;
  264. auto onRelease(const function<void ()>& callback = {}) -> type&;
  265. auto reset() -> type&;
  266. auto sequence() const -> string;
  267. auto setSequence(const string& sequence = "") -> type&;
  268. //private:
  269. struct State {
  270. bool active = false;
  271. vector<uint> keys;
  272. function<void ()> onPress;
  273. function<void ()> onRelease;
  274. string sequence;
  275. };
  276. shared_pointer<State> state;
  277. };
  278. #endif
  279. #include "application.hpp"
  280. #include "desktop.hpp"
  281. #include "monitor.hpp"
  282. #if defined(Hiro_Keyboard)
  283. struct Keyboard {
  284. Keyboard() = delete;
  285. static auto append(Hotkey hotkey) -> void;
  286. static auto hotkey(uint position) -> Hotkey;
  287. static auto hotkeyCount() -> uint;
  288. static auto hotkeys() -> vector<Hotkey>;
  289. static auto poll() -> vector<bool>;
  290. static auto pressed(const string& key) -> bool;
  291. static auto released(const string& key) -> bool;
  292. static auto remove(Hotkey hotkey) -> void;
  293. static const vector<string> keys;
  294. //private:
  295. struct State {
  296. vector<Hotkey> hotkeys;
  297. };
  298. static State state;
  299. };
  300. #endif
  301. #if defined(Hiro_Mouse)
  302. struct Mouse {
  303. enum class Button : uint { Left, Middle, Right };
  304. enum class Click : uint { Single, Double };
  305. Mouse() = delete;
  306. static auto position() -> Position;
  307. static auto pressed(Button) -> bool;
  308. static auto released(Button) -> bool;
  309. };
  310. #endif
  311. #if defined(Hiro_BrowserWindow)
  312. struct BrowserWindow {
  313. using type = BrowserWindow;
  314. auto directory() -> string;
  315. auto open() -> string;
  316. auto save() -> string;
  317. auto setFilters(const vector<string>& filters = {"*"}) -> type&;
  318. auto setParent(sWindow parent) -> type&;
  319. auto setPath(const string& path = "") -> type&;
  320. auto setTitle(const string& title = "") -> type&;
  321. //private:
  322. struct State {
  323. vector<string> filters;
  324. sWindow parent;
  325. string path;
  326. string title;
  327. } state;
  328. };
  329. #endif
  330. #if defined(Hiro_MessageWindow)
  331. struct MessageWindow {
  332. enum class Buttons : uint { Ok, OkCancel, YesNo, YesNoCancel };
  333. enum class Response : uint { Ok, Cancel, Yes, No };
  334. using type = MessageWindow;
  335. MessageWindow(const string& text = "");
  336. auto error(Buttons = Buttons::Ok) -> Response;
  337. auto information(Buttons = Buttons::Ok) -> Response;
  338. auto question(Buttons = Buttons::YesNo) -> Response;
  339. auto setParent(sWindow parent) -> type&;
  340. auto setText(const string& text = "") -> type&;
  341. auto setTitle(const string& title = "") -> type&;
  342. auto warning(Buttons = Buttons::Ok) -> Response;
  343. //private:
  344. struct State {
  345. MessageWindow::Buttons buttons = MessageWindow::Buttons::Ok;
  346. sWindow parent;
  347. string text;
  348. string title;
  349. } state;
  350. };
  351. #endif
  352. #include "attribute.hpp"
  353. #define Declare(Name) \
  354. using type = m##Name; \
  355. operator s##Name() const { return instance; } \
  356. auto self() -> p##Name* { return (p##Name*)delegate; } \
  357. auto self() const -> const p##Name* { return (const p##Name*)delegate; } \
  358. auto bind(const s##Name& instance) -> void { \
  359. this->instance = instance; \
  360. setGroup(); \
  361. if(!abstract()) construct(); \
  362. } \
  363. auto unbind() -> void { \
  364. reset(); \
  365. destruct(); \
  366. instance.reset(); \
  367. } \
  368. virtual auto allocate() -> pObject*; \
  369. #include "object.hpp"
  370. #include "group.hpp"
  371. #include "timer.hpp"
  372. #include "window.hpp"
  373. #if defined(Hiro_StatusBar)
  374. struct mStatusBar : mObject {
  375. Declare(StatusBar)
  376. auto remove() -> type& override;
  377. auto setText(const string& text = "") -> type&;
  378. auto text() const -> string;
  379. //private:
  380. struct State {
  381. string text;
  382. } state;
  383. };
  384. #endif
  385. #if defined(Hiro_MenuBar)
  386. struct mMenuBar : mObject {
  387. Declare(MenuBar)
  388. auto append(sMenu menu) -> type&;
  389. auto menu(uint position) const -> Menu;
  390. auto menuCount() const -> uint;
  391. auto menus() const -> vector<Menu>;
  392. auto remove() -> type& override;
  393. auto remove(sMenu menu) -> type&;
  394. auto reset() -> type&;
  395. auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override;
  396. //private:
  397. struct State {
  398. vector<sMenu> menus;
  399. } state;
  400. auto destruct() -> void override;
  401. };
  402. #endif
  403. #if defined(Hiro_PopupMenu)
  404. struct mPopupMenu : mObject {
  405. Declare(PopupMenu)
  406. using mObject::remove;
  407. auto action(uint position) const -> Action;
  408. auto actionCount() const -> uint;
  409. auto actions() const -> vector<Action>;
  410. auto append(sAction action) -> type&;
  411. auto remove(sAction action) -> type&;
  412. auto reset() -> type&;
  413. auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override;
  414. auto setVisible(bool visible = true) -> type& override;
  415. //private:
  416. struct State {
  417. vector<sAction> actions;
  418. } state;
  419. auto destruct() -> void override;
  420. };
  421. #endif
  422. #if defined(Hiro_Action)
  423. struct mAction : mObject {
  424. Declare(Action)
  425. auto remove() -> type& override;
  426. //private:
  427. struct State {
  428. } state;
  429. };
  430. #endif
  431. #if defined(Hiro_Menu)
  432. struct mMenu : mAction {
  433. Declare(Menu)
  434. using mObject::remove;
  435. auto action(uint position) const -> Action;
  436. auto actionCount() const -> uint;
  437. auto actions() const -> vector<Action>;
  438. auto append(sAction action) -> type&;
  439. auto icon() const -> image;
  440. auto remove(sAction action) -> type&;
  441. auto reset() -> type&;
  442. auto setIcon(const image& icon = {}) -> type&;
  443. auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override;
  444. auto setText(const string& text = "") -> type&;
  445. auto text() const -> string;
  446. //private:
  447. struct State {
  448. vector<sAction> actions;
  449. image icon;
  450. string text;
  451. } state;
  452. auto destruct() -> void override;
  453. };
  454. #endif
  455. #if defined(Hiro_MenuSeparator)
  456. struct mMenuSeparator : mAction {
  457. Declare(MenuSeparator)
  458. //private:
  459. struct State {
  460. } state;
  461. };
  462. #endif
  463. #if defined(Hiro_MenuItem)
  464. struct mMenuItem : mAction {
  465. Declare(MenuItem)
  466. auto doActivate() const -> void;
  467. auto icon() const -> image;
  468. auto onActivate(const function<void ()>& callback = {}) -> type&;
  469. auto setIcon(const image& icon = {}) -> type&;
  470. auto setText(const string& text = "") -> type&;
  471. auto text() const -> string;
  472. //private:
  473. struct State {
  474. image icon;
  475. function<void ()> onActivate;
  476. string text;
  477. } state;
  478. };
  479. #endif
  480. #if defined(Hiro_MenuCheckItem)
  481. struct mMenuCheckItem : mAction {
  482. Declare(MenuCheckItem)
  483. auto checked() const -> bool;
  484. auto doToggle() const -> void;
  485. auto onToggle(const function<void ()>& callback = {}) -> type&;
  486. auto setChecked(bool checked = true) -> type&;
  487. auto setText(const string& text = "") -> type&;
  488. auto text() const -> string;
  489. //private:
  490. struct State {
  491. bool checked = false;
  492. function<void ()> onToggle;
  493. string text;
  494. } state;
  495. };
  496. #endif
  497. #if defined(Hiro_MenuRadioItem)
  498. struct mMenuRadioItem : mAction {
  499. Declare(MenuRadioItem)
  500. auto checked() const -> bool;
  501. auto doActivate() const -> void;
  502. auto group() const -> Group override;
  503. auto onActivate(const function<void ()>& callback = {}) -> type&;
  504. auto setChecked() -> type&;
  505. auto setGroup(sGroup group = {}) -> type& override;
  506. auto setText(const string& text = "") -> type&;
  507. auto text() const -> string;
  508. //private:
  509. struct State {
  510. bool checked = false;
  511. sGroup group;
  512. function<void ()> onActivate;
  513. string text;
  514. } state;
  515. };
  516. #endif
  517. #include "sizable.hpp"
  518. #include "widget/widget.hpp"
  519. #if defined(Hiro_Button)
  520. struct mButton : mWidget {
  521. Declare(Button)
  522. auto bordered() const -> bool;
  523. auto doActivate() const -> void;
  524. auto icon() const -> image;
  525. auto onActivate(const function<void ()>& callback = {}) -> type&;
  526. auto orientation() const -> Orientation;
  527. auto setBordered(bool bordered = true) -> type&;
  528. auto setIcon(const image& icon = {}) -> type&;
  529. auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&;
  530. auto setText(const string& text = "") -> type&;
  531. auto text() const -> string;
  532. //private:
  533. struct State {
  534. bool bordered = true;
  535. image icon;
  536. function<void ()> onActivate;
  537. Orientation orientation = Orientation::Horizontal;
  538. string text;
  539. } state;
  540. };
  541. #endif
  542. #include "widget/canvas.hpp"
  543. #if defined(Hiro_CheckButton)
  544. struct mCheckButton : mWidget {
  545. Declare(CheckButton)
  546. auto bordered() const -> bool;
  547. auto checked() const -> bool;
  548. auto doToggle() const -> void;
  549. auto icon() const -> image;
  550. auto onToggle(const function<void ()>& callback = {}) -> type&;
  551. auto orientation() const -> Orientation;
  552. auto setBordered(bool bordered = true) -> type&;
  553. auto setChecked(bool checked = true) -> type&;
  554. auto setIcon(const image& icon = {}) -> type&;
  555. auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&;
  556. auto setText(const string& text = "") -> type&;
  557. auto text() const -> string;
  558. //private:
  559. struct State {
  560. bool bordered = true;
  561. bool checked = false;
  562. image icon;
  563. function<void ()> onToggle;
  564. Orientation orientation = Orientation::Horizontal;
  565. string text;
  566. } state;
  567. };
  568. #endif
  569. #if defined(Hiro_CheckLabel)
  570. struct mCheckLabel : mWidget {
  571. Declare(CheckLabel)
  572. auto checked() const -> bool;
  573. auto doToggle() const -> void;
  574. auto onToggle(const function<void ()>& callback = {}) -> type&;
  575. auto setChecked(bool checked = true) -> type&;
  576. auto setText(const string& text = "") -> type&;
  577. auto text() const -> string;
  578. //private:
  579. struct State {
  580. bool checked = false;
  581. function<void ()> onToggle;
  582. string text;
  583. } state;
  584. };
  585. #endif
  586. #if defined(Hiro_ComboButton)
  587. struct mComboButton : mWidget {
  588. Declare(ComboButton)
  589. using mObject::remove;
  590. auto append(sComboButtonItem item) -> type&;
  591. auto doChange() const -> void;
  592. auto item(uint position) const -> ComboButtonItem;
  593. auto itemCount() const -> uint;
  594. auto items() const -> vector<ComboButtonItem>;
  595. auto onChange(const function<void ()>& callback = {}) -> type&;
  596. auto remove(sComboButtonItem item) -> type&;
  597. auto reset() -> type&;
  598. auto selected() const -> ComboButtonItem;
  599. auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override;
  600. //private:
  601. struct State {
  602. vector<sComboButtonItem> items;
  603. function<void ()> onChange;
  604. } state;
  605. auto destruct() -> void override;
  606. };
  607. #endif
  608. #if defined(Hiro_ComboButton)
  609. struct mComboButtonItem : mObject {
  610. Declare(ComboButtonItem)
  611. auto icon() const -> image;
  612. auto remove() -> type& override;
  613. auto selected() const -> bool;
  614. auto setIcon(const image& icon = {}) -> type&;
  615. auto setSelected() -> type&;
  616. auto setText(const string& text = "") -> type&;
  617. auto text() const -> string;
  618. //private:
  619. struct State {
  620. image icon;
  621. bool selected = false;
  622. string text;
  623. } state;
  624. };
  625. #endif
  626. #if defined(Hiro_ComboEdit)
  627. struct mComboEdit : mWidget {
  628. Declare(ComboEdit)
  629. using mObject::remove;
  630. auto append(sComboEditItem item) -> type&;
  631. auto backgroundColor() const -> Color;
  632. auto doActivate() const -> void;
  633. auto doChange() const -> void;
  634. auto editable() const -> bool;
  635. auto foregroundColor() const -> Color;
  636. auto item(uint position) const -> ComboEditItem;
  637. auto itemCount() const -> uint;
  638. auto items() const -> vector<ComboEditItem>;
  639. auto onActivate(const function<void ()>& callback = {}) -> type&;
  640. auto onChange(const function<void ()>& callback = {}) -> type&;
  641. auto remove(sComboEditItem item) -> type&;
  642. auto reset() -> type&;
  643. auto setBackgroundColor(Color color = {}) -> type&;
  644. auto setEditable(bool editable = true) -> type&;
  645. auto setForegroundColor(Color color = {}) -> type&;
  646. auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override;
  647. auto setText(const string& text = "") -> type&;
  648. auto text() const -> string;
  649. //private:
  650. struct State {
  651. Color backgroundColor;
  652. bool editable = true;
  653. Color foregroundColor;
  654. vector<sComboEditItem> items;
  655. function<void ()> onActivate;
  656. function<void ()> onChange;
  657. string text;
  658. } state;
  659. auto destruct() -> void override;
  660. };
  661. #endif
  662. #if defined(Hiro_ComboEdit)
  663. struct mComboEditItem : mObject {
  664. Declare(ComboEditItem)
  665. auto icon() const -> image;
  666. auto remove() -> type& override;
  667. auto setIcon(const image& icon = {}) -> type&;
  668. auto setText(const string& text = "") -> type&;
  669. auto text() const -> string;
  670. //private:
  671. struct State {
  672. image icon;
  673. string text;
  674. } state;
  675. };
  676. #endif
  677. #if defined(Hiro_Console)
  678. struct mConsole : mWidget {
  679. Declare(Console)
  680. auto backgroundColor() const -> Color;
  681. auto doActivate(string) const -> void;
  682. auto foregroundColor() const -> Color;
  683. auto onActivate(const function<void (string)>& callback = {}) -> type&;
  684. auto print(const string& text) -> type&;
  685. auto prompt() const -> string;
  686. auto reset() -> type&;
  687. auto setBackgroundColor(Color color = {}) -> type&;
  688. auto setForegroundColor(Color color = {}) -> type&;
  689. auto setPrompt(const string& prompt = "") -> type&;
  690. //private:
  691. struct State {
  692. Color backgroundColor;
  693. Color foregroundColor;
  694. function<void (string)> onActivate;
  695. string prompt;
  696. } state;
  697. };
  698. #endif
  699. #if defined(Hiro_Frame)
  700. struct mFrame : mWidget {
  701. Declare(Frame)
  702. using mObject::remove;
  703. auto append(sSizable sizable) -> type&;
  704. auto remove(sSizable sizable) -> type&;
  705. auto reset() -> type&;
  706. auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override;
  707. auto setText(const string& text = "") -> type&;
  708. auto sizable() const -> Sizable;
  709. auto text() const -> string;
  710. //private:
  711. struct State {
  712. sSizable sizable;
  713. string text;
  714. } state;
  715. auto destruct() -> void override;
  716. };
  717. #endif
  718. #if defined(Hiro_HexEdit)
  719. struct mHexEdit : mWidget {
  720. Declare(HexEdit)
  721. auto address() const -> uint;
  722. auto backgroundColor() const -> Color;
  723. auto columns() const -> uint;
  724. auto doRead(uint offset) const -> uint8_t;
  725. auto doWrite(uint offset, uint8_t data) const -> void;
  726. auto foregroundColor() const -> Color;
  727. auto length() const -> uint;
  728. auto onRead(const function<uint8_t (uint)>& callback = {}) -> type&;
  729. auto onWrite(const function<void (uint, uint8_t)>& callback = {}) -> type&;
  730. auto rows() const -> uint;
  731. auto setAddress(uint address = 0) -> type&;
  732. auto setBackgroundColor(Color color = {}) -> type&;
  733. auto setColumns(uint columns = 16) -> type&;
  734. auto setForegroundColor(Color color = {}) -> type&;
  735. auto setLength(uint length) -> type&;
  736. auto setRows(uint rows = 16) -> type&;
  737. auto update() -> type&;
  738. //private:
  739. struct State {
  740. uint address = 0;
  741. Color backgroundColor;
  742. uint columns = 16;
  743. Color foregroundColor;
  744. uint length = 0;
  745. function<uint8_t (uint)> onRead;
  746. function<void (uint, uint8_t)> onWrite;
  747. uint rows = 16;
  748. } state;
  749. };
  750. #endif
  751. #if defined(Hiro_HorizontalScrollBar)
  752. struct mHorizontalScrollBar : mWidget {
  753. Declare(HorizontalScrollBar)
  754. auto doChange() const -> void;
  755. auto length() const -> uint;
  756. auto onChange(const function<void ()>& callback = {}) -> type&;
  757. auto position() const -> uint;
  758. auto setLength(uint length = 101) -> type&;
  759. auto setPosition(uint position = 0) -> type&;
  760. //private:
  761. struct State {
  762. uint length = 101;
  763. function<void ()> onChange;
  764. uint position = 0;
  765. } state;
  766. };
  767. #endif
  768. #if defined(Hiro_HorizontalSlider)
  769. struct mHorizontalSlider : mWidget {
  770. Declare(HorizontalSlider)
  771. auto doChange() const -> void;
  772. auto length() const -> uint;
  773. auto onChange(const function<void ()>& callback = {}) -> type&;
  774. auto position() const -> uint;
  775. auto setLength(uint length = 101) -> type&;
  776. auto setPosition(uint position = 0) -> type&;
  777. //private:
  778. struct State {
  779. uint length = 101;
  780. function<void ()> onChange;
  781. uint position = 0;
  782. } state;
  783. };
  784. #endif
  785. #if defined(Hiro_IconView)
  786. struct mIconView : mWidget {
  787. Declare(IconView)
  788. using mObject::remove;
  789. auto append(sIconViewItem item) -> type&;
  790. auto backgroundColor() const -> Color;
  791. auto batchable() const -> bool;
  792. auto batched() const -> vector<IconViewItem>;
  793. auto doActivate() const -> void;
  794. auto doChange() const -> void;
  795. auto doContext() const -> void;
  796. auto flow() const -> Orientation;
  797. auto foregroundColor() const -> Color;
  798. auto item(uint position) const -> IconViewItem;
  799. auto itemCount() const -> uint;
  800. auto items() const -> vector<IconViewItem>;
  801. auto onActivate(const function<void ()>& callback = {}) -> type&;
  802. auto onChange(const function<void ()>& callback = {}) -> type&;
  803. auto onContext(const function<void ()>& callback = {}) -> type&;
  804. auto orientation() const -> Orientation;
  805. auto remove(sIconViewItem item) -> type&;
  806. auto reset() -> type&;
  807. auto selected() const -> IconViewItem;
  808. auto setBackgroundColor(Color color = {}) -> type&;
  809. auto setBatchable(bool batchable = true) -> type&;
  810. auto setFlow(Orientation flow = Orientation::Vertical) -> type&;
  811. auto setForegroundColor(Color color = {}) -> type&;
  812. auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&;
  813. auto setParent(mObject* object = nullptr, int offset = -1) -> type& override;
  814. auto setSelected(const vector<int>& selections) -> type&;
  815. //private:
  816. struct State {
  817. Color backgroundColor;
  818. bool batchable = false;
  819. Color foregroundColor;
  820. Orientation flow = Orientation::Vertical;
  821. vector<sIconViewItem> items;
  822. function<void ()> onActivate;
  823. function<void ()> onChange;
  824. function<void ()> onContext;
  825. Orientation orientation = Orientation::Horizontal;
  826. } state;
  827. auto destruct() -> void override;
  828. };
  829. #endif
  830. #if defined(Hiro_IconView)
  831. struct mIconViewItem : mObject {
  832. Declare(IconViewItem)
  833. auto icon() const -> image;
  834. auto remove() -> type& override;
  835. auto selected() const -> bool;
  836. auto setIcon(const image& icon = {}) -> type&;
  837. auto setSelected(bool selected = true) -> type&;
  838. auto setText(const string& text = "") -> type&;
  839. auto text() const -> string;
  840. //private:
  841. struct State {
  842. image icon;
  843. bool selected = false;
  844. string text;
  845. } state;
  846. };
  847. #endif
  848. #include "widget/label.hpp"
  849. #if defined(Hiro_LineEdit)
  850. struct mLineEdit : mWidget {
  851. Declare(LineEdit)
  852. auto backgroundColor() const -> Color;
  853. auto doActivate() const -> void;
  854. auto doChange() const -> void;
  855. auto editable() const -> bool;
  856. auto foregroundColor() const -> Color;
  857. auto onActivate(const function<void ()>& callback = {}) -> type&;
  858. auto onChange(const function<void ()>& callback = {}) -> type&;
  859. auto setBackgroundColor(Color color = {}) -> type&;
  860. auto setEditable(bool editable = true) -> type&;
  861. auto setForegroundColor(Color color = {}) -> type&;
  862. auto setText(const string& text = "") -> type&;
  863. auto text() const -> string;
  864. //private:
  865. struct State {
  866. Color backgroundColor;
  867. bool editable = true;
  868. Color foregroundColor;
  869. function<void ()> onActivate;
  870. function<void ()> onChange;
  871. string text;
  872. } state;
  873. };
  874. #endif
  875. #if defined(Hiro_ProgressBar)
  876. struct mProgressBar : mWidget {
  877. Declare(ProgressBar)
  878. auto position() const -> uint;
  879. auto setPosition(uint position) -> type&;
  880. //private:
  881. struct State {
  882. uint position = 0;
  883. } state;
  884. };
  885. #endif
  886. #if defined(Hiro_RadioButton)
  887. struct mRadioButton : mWidget {
  888. Declare(RadioButton)
  889. auto bordered() const -> bool;
  890. auto checked() const -> bool;
  891. auto doActivate() const -> void;
  892. auto group() const -> Group override;
  893. auto icon() const -> image;
  894. auto onActivate(const function<void ()>& callback = {}) -> type&;
  895. auto orientation() const -> Orientation;
  896. auto setBordered(bool bordered = true) -> type&;
  897. auto setChecked() -> type&;
  898. auto setGroup(sGroup group = {}) -> type& override;
  899. auto setIcon(const image& icon = {}) -> type&;
  900. auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&;
  901. auto setText(const string& text = "") -> type&;
  902. auto text() const -> string;
  903. //private:
  904. struct State {
  905. bool bordered = true;
  906. bool checked = false;
  907. sGroup group;
  908. image icon;
  909. function<void ()> onActivate;
  910. Orientation orientation = Orientation::Horizontal;
  911. string text;
  912. } state;
  913. };
  914. #endif
  915. #if defined(Hiro_RadioLabel)
  916. struct mRadioLabel : mWidget {
  917. Declare(RadioLabel)
  918. auto checked() const -> bool;
  919. auto doActivate() const -> void;
  920. auto group() const -> Group override;
  921. auto onActivate(const function<void ()>& callback = {}) -> type&;
  922. auto setChecked() -> type&;
  923. auto setGroup(sGroup group = {}) -> type& override;
  924. auto setText(const string& text = "") -> type&;
  925. auto text() const -> string;
  926. //private:
  927. struct State {
  928. bool checked = false;
  929. sGroup group;
  930. function<void ()> onActivate;
  931. string text;
  932. } state;
  933. };
  934. #endif
  935. #include "widget/source-edit.hpp"
  936. #include "widget/tab-frame.hpp"
  937. #include "widget/tab-frame-item.hpp"
  938. #include "widget/table-view.hpp"
  939. #include "widget/table-view-column.hpp"
  940. #include "widget/table-view-item.hpp"
  941. #include "widget/table-view-cell.hpp"
  942. #include "widget/text-edit.hpp"
  943. #include "widget/tree-view.hpp"
  944. #include "widget/tree-view-item.hpp"
  945. #if defined(Hiro_VerticalScrollBar)
  946. struct mVerticalScrollBar : mWidget {
  947. Declare(VerticalScrollBar)
  948. auto doChange() const -> void;
  949. auto length() const -> uint;
  950. auto onChange(const function<void ()>& callback = {}) -> type&;
  951. auto position() const -> uint;
  952. auto setLength(uint length = 101) -> type&;
  953. auto setPosition(uint position = 0) -> type&;
  954. //private:
  955. struct State {
  956. uint length = 101;
  957. function<void ()> onChange;
  958. uint position = 0;
  959. } state;
  960. };
  961. #endif
  962. #if defined(Hiro_VerticalSlider)
  963. struct mVerticalSlider : mWidget {
  964. Declare(VerticalSlider)
  965. auto doChange() const -> void;
  966. auto length() const -> uint;
  967. auto onChange(const function<void ()>& callback = {}) -> type&;
  968. auto position() const -> uint;
  969. auto setLength(uint length = 101) -> type&;
  970. auto setPosition(uint position = 0) -> type&;
  971. //private:
  972. struct State {
  973. uint length = 101;
  974. function<void ()> onChange;
  975. uint position = 0;
  976. } state;
  977. };
  978. #endif
  979. #include "widget/viewport.hpp"
  980. #undef Declare
  981. #include "lock.hpp"
  982. #include "shared.hpp"
  983. }