+++ /dev/null
-#ifndef MBUOY_ATTR_DIMENSIONS_HPP
-#define MBUOY_ATTR_DIMENSIONS_HPP
-
-namespace mbuoy {
-
-struct dimensions
-{
- int width, height;
-};
-
-} // namespace mbuoy
-
-#endif // MBUOY_ATTR_DIMENSIONS_HPP
-
+++ /dev/null
-#ifndef MBUOY_ATTR_ONDRAW_HPP
-#define MBUOY_ATTR_ONDRAW_HPP
-
-#include "position.hpp"
-#include "dimensions.hpp"
-
-namespace mbuoy {
-
-struct ondraw
-{
- void (*func)(const position&, const dimensions&);
-
- void operator()(const position& pos, const dimensions& dim) const noexcept {
- func(pos, dim);
- }
-};
-
-} // namespace mbuoy
-
-#endif // MBUOY_ATTR_ONDRAW_HPP
-
+++ /dev/null
-#ifndef MBUOY_ATTR_POSITION_HPP
-#define MBUOY_ATTR_POSITION_HPP
-
-namespace mbuoy {
-
-struct position
-{
- int x, y;
-};
-
-} // namespace mbuoy
-
-#endif // MBUOY_ATTR_POSITION_HPP
-
+++ /dev/null
-#ifndef MBUOY_ATTR_STRING_HPP
-#define MBUOY_ATTR_STRING_HPP
-
-namespace mbuoy {
-
-template<int N>
-struct string
-{
- consteval string(const char (&s_)[N]) {
- for (int i = 0; i < N; ++i)
- s[i] = s_[i];
- }
-
- consteval operator const char *() const {
- return s;
- }
-
- char s[N];
-};
-
-} // namespace mbuoy
-
-#endif // MBUOY_ATTR_STRING_HPP
-
+++ /dev/null
-#ifndef MBUOY_FIND_HPP
-#define MBUOY_FIND_HPP
-
-#include <optional>
-#include <type_traits>
-
-namespace mbuoy {
-
-template<typename T, typename U>
-concept can_static_cast = requires(U u) {
- static_cast<T>(u);
-};
-
-template<typename T>
-consteval std::optional<T> find(T val)
-{
- return val;
-}
-
-template<typename T, typename U>
- requires (!std::is_same_v<T, U> && can_static_cast<T, U>)
-consteval std::optional<U> find(U val)
-{
- return val;
-}
-
-template<typename T, typename U>
- requires (!std::is_same_v<T, U> && !can_static_cast<T, U>)
-consteval std::optional<T> find(U val)
-{
- return {};
-}
-
-template<typename T>
-consteval std::optional<T> find(T val, auto... vals)
-{
- return val;
-}
-
-template<typename T, typename U>
- requires (!std::is_same_v<T, U> && can_static_cast<T, U>)
-consteval std::optional<U> find(U val, auto... vals)
-{
- return val;
-}
-
-template<typename T, typename U>
- requires (!std::is_same_v<T, U> && !can_static_cast<T, U>)
-consteval auto find(U val, auto... vals)
-{
- return find<T>(vals...);
-}
-
-} // namespace mbuoy
-
-#endif // MBUOY_FIND_HPP
-
-#include "view.hpp"
-#include "ui/button.hpp"
-#include "ui/label.hpp"
+#include "mbuoy/view.hpp"
+#include "mbuoy/ui/button.hpp"
+#include "mbuoy/ui/label.hpp"
+
+#include <cstdio>
void drawButton(const mbuoy::position& pos, const mbuoy::dimensions& dim)
{
mbuoy::dimensions(40, 40),
mbuoy::ondraw(drawButton)>{}
>;
+
test.render();
}
--- /dev/null
+#ifndef MBUOY_ATTR_DIMENSIONS_HPP
+#define MBUOY_ATTR_DIMENSIONS_HPP
+
+namespace mbuoy {
+
+struct dimensions
+{
+ int width, height;
+};
+
+} // namespace mbuoy
+
+#endif // MBUOY_ATTR_DIMENSIONS_HPP
+
--- /dev/null
+#ifndef MBUOY_ATTR_ONDRAW_HPP
+#define MBUOY_ATTR_ONDRAW_HPP
+
+#include "position.hpp"
+#include "dimensions.hpp"
+
+namespace mbuoy {
+
+struct ondraw
+{
+ void (*func)(const position&, const dimensions&);
+
+ void operator()(const position& pos, const dimensions& dim) const noexcept {
+ func(pos, dim);
+ }
+};
+
+} // namespace mbuoy
+
+#endif // MBUOY_ATTR_ONDRAW_HPP
+
--- /dev/null
+#ifndef MBUOY_ATTR_POSITION_HPP
+#define MBUOY_ATTR_POSITION_HPP
+
+namespace mbuoy {
+
+struct position
+{
+ int x, y;
+};
+
+} // namespace mbuoy
+
+#endif // MBUOY_ATTR_POSITION_HPP
+
--- /dev/null
+#ifndef MBUOY_ATTR_STRING_HPP
+#define MBUOY_ATTR_STRING_HPP
+
+namespace mbuoy {
+
+template<int N>
+struct string
+{
+ consteval string(const char (&s_)[N]) {
+ for (int i = 0; i < N; ++i)
+ s[i] = s_[i];
+ }
+
+ consteval operator const char *() const {
+ return s;
+ }
+
+ char s[N];
+};
+
+} // namespace mbuoy
+
+#endif // MBUOY_ATTR_STRING_HPP
+
--- /dev/null
+#ifndef MBUOY_FIND_HPP
+#define MBUOY_FIND_HPP
+
+#include <optional>
+#include <type_traits>
+
+namespace mbuoy {
+
+template<typename T, typename U>
+concept can_static_cast = requires(U u) {
+ static_cast<T>(u);
+};
+
+template<typename T>
+consteval std::optional<T> find(T val)
+{
+ return val;
+}
+
+template<typename T, typename U>
+ requires (!std::is_same_v<T, U> && can_static_cast<T, U>)
+consteval std::optional<U> find(U val)
+{
+ return val;
+}
+
+template<typename T, typename U>
+ requires (!std::is_same_v<T, U> && !can_static_cast<T, U>)
+consteval std::optional<T> find(U val)
+{
+ return {};
+}
+
+template<typename T>
+consteval std::optional<T> find(T val, auto... vals)
+{
+ return val;
+}
+
+template<typename T, typename U>
+ requires (!std::is_same_v<T, U> && can_static_cast<T, U>)
+consteval std::optional<U> find(U val, auto... vals)
+{
+ return val;
+}
+
+template<typename T, typename U>
+ requires (!std::is_same_v<T, U> && !can_static_cast<T, U>)
+consteval auto find(U val, auto... vals)
+{
+ return find<T>(vals...);
+}
+
+} // namespace mbuoy
+
+#endif // MBUOY_FIND_HPP
+
--- /dev/null
+#ifndef MBUOY_PORT_HPP
+#define MBUOY_PORT_HPP
+
+#include <cstdio>
+
+namespace mbuoy {
+namespace port {
+
+inline void puts(int x, int y, const char *s)
+{
+ std::printf("[%d, %d]: %s\n", x, y, s);
+}
+
+} // namespace port
+} // namespace mbuoy
+
+#endif // MBUOY_PORT_HPP
+
--- /dev/null
+#ifndef MBUOY_UI_BUTTON_HPP
+#define MBUOY_UI_BUTTON_HPP
+
+#include "../attr/dimensions.hpp"
+#include "../attr/ondraw.hpp"
+#include "../attr/position.hpp"
+#include "../attr/string.hpp"
+#include "../find.hpp"
+#include "../port.hpp"
+
+namespace mbuoy {
+
+template<auto... Attr>
+struct button
+{
+ static constexpr auto point = find<position>(Attr...);
+ static constexpr auto dims = find<dimensions>(Attr...);
+ static constexpr auto text = find<const char *>(Attr...);
+ static constexpr auto draw = find<ondraw>(Attr...);
+
+ static consteval void init(unsigned char *(&ptr)) {
+ *ptr++ = 0; // pressed?
+ }
+
+ static void render() {
+ (*draw)(*point, *dims);
+ }
+
+ static consteval int size() {
+ return 1;
+ }
+};
+
+} // namespace mbuoy
+
+#endif // MBUOY_UI_BUTTON_HPP
+
--- /dev/null
+#ifndef MBUOY_UI_LABEL_HPP
+#define MBUOY_UI_LABEL_HPP
+
+#include "../attr/position.hpp"
+#include "../attr/string.hpp"
+#include "../find.hpp"
+#include "../port.hpp"
+
+namespace mbuoy {
+
+template<auto... Attr>
+struct label
+{
+ static constexpr auto point = find<position>(Attr...);
+ static constexpr auto text = find<const char *>(Attr...);
+
+ static consteval void init(unsigned char *(&ptr)) {
+ }
+
+ static void render() {
+ port::puts(point->x, point->y, *text);
+ }
+
+ static consteval int size() {
+ return 0;
+ }
+};
+
+} // namespace mbuoy
+
+#endif // MBUOY_UI_LABEL_HPP
+
--- /dev/null
+#ifndef MBUOY_VIEW_HPP
+#define MBUOY_VIEW_HPP
+
+namespace mbuoy {
+
+template<auto... Objs>
+class view_t
+{
+public:
+ consteval view_t() {
+ auto ptr = data;
+ (Objs.init(ptr), ...);
+ }
+
+ void render() {
+ (Objs.render(), ...);
+ }
+
+private:
+ unsigned char data[(0 + ... + Objs.size())] = {};
+};
+
+template<auto... Objs>
+constinit auto view = view_t<Objs...>();
+
+} // namespace mbuoy
+
+#endif // MBUOY_VIEW_HPP
+
+++ /dev/null
-#ifndef MBUOY_PORT_HPP
-#define MBUOY_PORT_HPP
-
-#include <cstdio>
-
-namespace mbuoy {
-namespace port {
-
-inline void puts(int x, int y, const char *s)
-{
- std::printf("[%d, %d]: %s\n", x, y, s);
-}
-
-} // namespace port
-} // namespace mbuoy
-
-#endif // MBUOY_PORT_HPP
-
+++ /dev/null
-#ifndef MBUOY_UI_BUTTON_HPP
-#define MBUOY_UI_BUTTON_HPP
-
-#include "attr/dimensions.hpp"
-#include "attr/ondraw.hpp"
-#include "attr/position.hpp"
-#include "attr/string.hpp"
-#include "find.hpp"
-#include "port.hpp"
-
-namespace mbuoy {
-
-template<auto... Attr>
-struct button
-{
- static constexpr auto point = find<position>(Attr...);
- static constexpr auto dims = find<dimensions>(Attr...);
- static constexpr auto text = find<const char *>(Attr...);
- static constexpr auto draw = find<ondraw>(Attr...);
-
- static consteval void init(unsigned char *(&ptr)) {
- *ptr++ = 0; // pressed?
- }
-
- static void render() {
- (*draw)(*point, *dims);
- }
-
- static consteval int size() {
- return 1;
- }
-};
-
-} // namespace mbuoy
-
-#endif // MBUOY_UI_BUTTON_HPP
-
+++ /dev/null
-#ifndef MBUOY_UI_LABEL_HPP
-#define MBUOY_UI_LABEL_HPP
-
-#include "attr/position.hpp"
-#include "attr/string.hpp"
-#include "find.hpp"
-#include "port.hpp"
-
-namespace mbuoy {
-
-template<auto... Attr>
-struct label
-{
- static constexpr auto point = find<position>(Attr...);
- static constexpr auto text = find<const char *>(Attr...);
-
- static consteval void init(unsigned char *(&ptr)) {
- }
-
- static void render() {
- port::puts(point->x, point->y, *text);
- }
-
- static consteval int size() {
- return 0;
- }
-};
-
-} // namespace mbuoy
-
-#endif // MBUOY_UI_LABEL_HPP
-
+++ /dev/null
-#ifndef MBUOY_VIEW_HPP
-#define MBUOY_VIEW_HPP
-
-namespace mbuoy {
-
-template<auto... Objs>
-class view_t
-{
-public:
- consteval view_t() {
- auto ptr = data;
- (Objs.init(ptr), ...);
- }
-
- void render() {
- (Objs.render(), ...);
- }
-
-private:
- unsigned char data[(0 + ... + Objs.size())] = {};
-};
-
-template<auto... Objs>
-constinit auto view = view_t<Objs...>();
-
-} // namespace mbuoy
-
-#endif // MBUOY_VIEW_HPP
-