15 #ifndef SCENE_LAB_FLATBUFFER_EDITOR_H_
16 #define SCENE_LAB_FLATBUFFER_EDITOR_H_
20 #include <unordered_map>
22 #include "flatbuffer_editor_config_generated.h"
23 #include "flatbuffers/flatbuffers.h"
24 #include "flatbuffers/reflection.h"
25 #include "flatbuffers/util.h"
26 #include "flatui/flatui.h"
27 #include "fplbase/fpl_common.h"
28 #include "mathfu/glsl_mappings.h"
57 const reflection::Schema& schema,
58 const reflection::Object& table_def,
59 const void* flatbuffer_data);
67 if (flatbuffer_data !=
nullptr) {
68 CopyTable(flatbuffer_data, &flatbuffer_);
148 return config_allow_adding_fields_;
154 config_allow_adding_fields_ = b;
199 const std::string&
root_id()
const {
return root_id_; }
201 MATHFU_DEFINE_CLASS_SIMD_AWARE_NEW_DELETE
224 enum Button { kNone, kCommit, kRevert };
227 void CopyTable(
const void* src, std::vector<uint8_t>* dest);
230 void ClearEditFields() {
231 edit_fields_.clear();
232 edit_fields_modified_ =
false;
233 error_fields_.clear();
241 void CommitEditsToFlatbuffer();
258 bool VisitField(VisitMode mode,
const std::string& name,
259 const std::string& value,
const std::string& type,
260 const std::string& comment,
const std::string&
id);
267 bool VisitSubtable(VisitMode mode,
const std::string& field,
268 const std::string& type,
const std::string& comment,
269 const std::string&
id,
const reflection::Schema& schema,
270 const reflection::Object& subobjdef,
271 flatbuffers::Table& subtable);
277 bool VisitFlatbufferField(VisitMode mode,
const reflection::Schema& schema,
278 const reflection::Field& fielddef,
279 const reflection::Object& objectdef,
280 flatbuffers::Table& table,
const std::string&
id);
285 bool VisitFlatbufferScalar(VisitMode mode,
const reflection::Schema& schema,
286 const reflection::Field& fielddef,
287 flatbuffers::Table& table,
const std::string&
id);
292 bool VisitFlatbufferTable(VisitMode mode,
const reflection::Schema& schema,
293 const reflection::Object& objectdef,
294 flatbuffers::Table& table,
const std::string&
id);
299 bool VisitFlatbufferVector(VisitMode mode,
const reflection::Schema& schema,
300 const reflection::Field& fielddef,
301 flatbuffers::Table& table,
const std::string&
id);
306 bool VisitFlatbufferUnion(VisitMode mode,
const reflection::Schema& schema,
307 const reflection::Field& fielddef,
308 const reflection::Object& objectdef,
309 flatbuffers::Table& table,
const std::string&
id);
314 bool VisitFlatbufferStruct(VisitMode mode,
const reflection::Schema& schema,
315 const reflection::Field& fielddef,
316 const reflection::Object& objectdef,
317 flatbuffers::Struct& fbstruct,
318 const std::string&
id);
323 bool VisitFlatbufferString(VisitMode mode,
const reflection::Schema& schema,
324 const reflection::Field& fielddef,
325 flatbuffers::Table& table,
const std::string&
id);
333 static std::string StructToString(
const reflection::Schema& schema,
334 const reflection::Object& objectdef,
335 const flatbuffers::Struct& struct_ptr,
336 bool field_names_only);
343 static bool ParseStringIntoStruct(
const std::string&
string,
344 const reflection::Schema& schema,
345 const reflection::Object& objectdef,
346 flatbuffers::Struct* struct_ptr);
354 static std::string ExtractInlineStructDef(
const std::string& str);
358 static std::string GetEnumTypeAndValue(
const reflection::Schema& schema,
359 const reflection::Field& fielddef,
360 const std::string& value,
362 std::string* value_name);
367 std::string FormatFieldName(
const std::string& name,
const std::string& type);
372 flatui::Event TextButton(
const char* text,
const char*
id,
float size);
378 bool AddFieldButton(VisitMode mode,
const std::string& name,
379 const std::string& type_str,
const std::string&
id);
382 void set_keyboard_in_use(
bool b) { keyboard_in_use_ = b; }
385 static bool IsDraw(VisitMode mode) {
386 return (mode == kDrawEditAuto || mode == kDrawEditManual ||
387 mode == kDrawReadOnly);
392 static bool IsDrawEdit(VisitMode mode) {
393 return (mode == kDrawEditAuto || mode == kDrawEditManual);
398 const reflection::Schema& schema_;
399 const reflection::Object& table_def_;
400 std::unordered_map<std::string, std::string> edit_fields_;
402 std::set<std::string> expanded_subtables_;
406 std::set<std::string> committed_fields_;
409 std::set<std::string> error_fields_;
411 std::vector<uint8_t> flatbuffer_;
413 std::string root_id_;
414 std::string currently_editing_field_;
415 std::string force_commit_field_;
419 Button button_pressed_;
423 float blank_field_width_;
424 bool keyboard_in_use_;
428 bool config_read_only_;
429 bool config_auto_commit_;
430 bool config_allow_resize_;
432 bool config_allow_adding_fields_;
435 bool edit_fields_modified_;
436 bool flatbuffer_modified_;
440 mathfu::vec4 bg_button_color_;
441 mathfu::vec4 bg_button_hover_color_;
442 mathfu::vec4 bg_button_click_color_;
444 mathfu::vec4 text_button_color_;
445 mathfu::vec4 text_normal_color_;
446 mathfu::vec4 text_comment_color_;
447 mathfu::vec4 text_disabled_color_;
448 mathfu::vec4 text_editable_color_;
449 mathfu::vec4 text_editing_color_;
450 mathfu::vec4 text_modified_color_;
451 mathfu::vec4 text_committed_color_;
452 mathfu::vec4 text_error_color_;
457 #endif // SCENE_LAB_FLATBUFFER_EDITOR_H_
bool expand_all() const
Expand all subtables in the Flatbuffer table?
Definition: flatbuffer_editor.h:185
void set_blank_field_width(float w)
Set the blank field width. See blank_filed_width().
Definition: flatbuffer_editor.h:176
void set_config_allow_adding_fields(bool b)
Set the "Allow adding fields" config value.
Definition: flatbuffer_editor.h:153
void set_show_types(bool b)
See show_types().
Definition: flatbuffer_editor.h:182
bool show_types() const
Show the type of each subtable / struct in the Flatbuffer table?
Definition: flatbuffer_editor.h:179
void set_root_id(const std::string &id)
Set a unique root ID for all edit fields, required by FlatUI.
Definition: flatbuffer_editor.h:196
void SetFlatbufferData(const void *flatbuffer_data)
Override the current Flatbuffer data with this new one.
Definition: flatbuffer_editor.h:64
FlatbufferEditor(const FlatbufferEditorConfig *config, const reflection::Schema &schema, const reflection::Object &table_def, const void *flatbuffer_data)
Construct a FlatbufferEditor for a given schema and table definition, and optionally initialize it wi...
void set_expand_all(bool b)
See expand_all().
Definition: flatbuffer_editor.h:188
void set_config_allow_resize(bool b)
Set the "Allow resizing" config value.
Definition: flatbuffer_editor.h:135
bool config_allow_resize() const
Allow resizing of the Flatbuffer.
Definition: flatbuffer_editor.h:131
bool config_allow_adding_fields() const
Allow adding fields to the Flatbuffer.
Definition: flatbuffer_editor.h:147
bool config_auto_commit() const
Get the Auto-commit mode: If true, then whenever the user edits the Flatbuffer fields, automatically update the Flatbuffer contents after the user finishes editing (presses Enter or clicks on another field).
Definition: flatbuffer_editor.h:122
bool HasFlatbufferData() const
Does this FlatbufferEditor have any Flatbuffer data?
Definition: flatbuffer_editor.h:79
float ui_spacing() const
Get the spacing of all the UI elements passed to FlatUI.
Definition: flatbuffer_editor.h:166
float ui_size() const
Get the size of all the UI elements passed to FlatUI.
Definition: flatbuffer_editor.h:159
void set_ui_size(float s)
Set the UI size. See ui_size().
Definition: flatbuffer_editor.h:162
bool config_read_only() const
Check if we are in Read-only mode: If true, draw the Flatbuffer using FlatUI's Label fields instead o...
Definition: flatbuffer_editor.h:112
bool keyboard_in_use() const
Is the keyboard in use? A field is being edited? You probably want to check this to make sure you don...
Definition: flatbuffer_editor.h:192
bool flatbuffer_modified() const
Has the Flatbuffer data been modified? If so, you probably want to reload whatever is using it...
Definition: flatbuffer_editor.h:100
void set_config_auto_commit(bool b)
Set the Auto-commit mode. See config_auto_commit().
Definition: flatbuffer_editor.h:125
const void * flatbuffer()
Get a pointer to the Flatbuffer we are working with, in case you want to manually copy it out...
Definition: flatbuffer_editor.h:107
float blank_field_width() const
When an editable text field is blank, we force the width of the gui Edit field to this value so that ...
Definition: flatbuffer_editor.h:173
void ClearFlatbufferModifiedFlag()
Once you have reloaded the Flatbuffer into whatever you are using it for, call this to reset the "mod...
void set_ui_spacing(float s)
Set the UI spacing. See ui_spacing().
Definition: flatbuffer_editor.h:169
void Update()
Update the internal state.
const std::string & root_id() const
See set_root_id().
Definition: flatbuffer_editor.h:199
std::unique_ptr< uint8_t > GetFlatbufferCopy()
Copy the modified Flatbuffer into a generic buffer and get a pointer.
void set_config_read_only(bool b)
Set Read-only mode. See config_read_only() for more information.
Definition: flatbuffer_editor.h:115
void Draw()
Draw the Flatbuffer edit fields. Call this INSIDE a gui::Run context.
Definition: flatbuffer_editor.h:43