88#include < optional>
99#include < string>
1010#include < vector>
11+ #include < bit>
1112
1213EXPORT_MODULE namespace hex {
1314
@@ -22,8 +23,10 @@ EXPORT_MODULE namespace hex {
2223
2324 namespace impl {
2425
26+ struct DoNotUseThisByItselfTag {};
27+
2528 using DisplayFunction = std::function<std::string()>;
26- using EditingFunction = std::function<std::vector<u8 >(std::string, std::endian)>;
29+ using EditingFunction = std::function<std::optional<std:: vector<u8 >> (std::string& , std::endian, DoNotUseThisByItselfTag )>;
2730 using GeneratorFunction = std::function<DisplayFunction(const std::vector<u8 > &, std::endian, NumberDisplayStyle)>;
2831
2932 struct Entry {
@@ -38,6 +41,35 @@ EXPORT_MODULE namespace hex {
3841
3942 }
4043
44+ namespace EditWidget {
45+
46+ class Widget {
47+ public:
48+ using Function = std::function<std::vector<u8 >(const std::string&, std::endian)>;
49+
50+ explicit Widget (const Function &function) : m_function(function) {}
51+
52+ virtual ~Widget () = default ;
53+ virtual std::optional<std::vector<u8 >> draw (std::string &value, std::endian endian) = 0;
54+ std::optional<std::vector<u8 >> operator ()(std::string &value, std::endian endian, impl::DoNotUseThisByItselfTag) {
55+ return draw (value, endian);
56+ }
57+
58+ std::vector<u8 > getBytes (const std::string &value, std::endian endian) const {
59+ return m_function (value, endian);
60+ }
61+
62+ private:
63+ Function m_function;
64+ };
65+
66+ struct TextInput : Widget {
67+ explicit TextInput (const Function &function) : Widget(function) {}
68+ std::optional<std::vector<u8 >> draw (std::string &value, std::endian endian) override ;
69+ };
70+
71+ }
72+
4173 /* *
4274 * @brief Adds a new entry to the data inspector
4375 * @param unlocalizedName The unlocalized name of the entry
0 commit comments