summaryrefslogtreecommitdiff
path: root/src/user/settings/model.h
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-06-21 17:47:13 -0400
committerBenji Dial <benji6283@gmail.com>2021-06-21 17:47:13 -0400
commitf57e2eabe0a10c9732c83532e01654a499fb8dcf (patch)
treecbf91a23fcdd65e0ea7ed55b0940ca7042d59bef /src/user/settings/model.h
parent83835306d57461205a7bcfef9f4c3e06bc504006 (diff)
downloadportland-os-f57e2eabe0a10c9732c83532e01654a499fb8dcf.tar.gz
many, many changes; settings is broken
Diffstat (limited to 'src/user/settings/model.h')
-rw-r--r--src/user/settings/model.h60
1 files changed, 48 insertions, 12 deletions
diff --git a/src/user/settings/model.h b/src/user/settings/model.h
index 0c9b1d2..410121f 100644
--- a/src/user/settings/model.h
+++ b/src/user/settings/model.h
@@ -1,24 +1,60 @@
#ifndef MODEL_H
#define MODEL_H
-#include <raleigh/d/saving_window.h>
-#include <structs/alist.h>
+#include <raleigh/d/dialog.h>
+#include <raleigh/w/button.h>
+#include <raleigh/w/label.h>
+#include <raleigh/w/vbox.h>
+#include <raleigh/window.h>
+#include <structs/map.h>
+#include <knob/file.h>
-union setting_data {
- char *string;
- _pixel_t color;
+typedef void *backing_t;
+
+struct setting;
+
+struct setting_kind_info {
+ void (*write_main)(uint32_t &data_offset, file *f, const backing_t backing);
+ void (*write_data)(file *f, const backing_t backing);
+ backing_t (*read_backing)(file *f, uint32_t data_start);
+ void (*open_editor)(setting &s);
};
struct setting {
- enum {
- STRING,
- COLOR
- } kind;
- union setting_data data;
const char *name;
+ const setting_kind_info *kind;
+ void *backing;
+};
+
+class settings_model {
+public:
+ settings_model(const char *from_file);
+
+ void write_to_file(const char *to_file);
+
+ alist<setting> settings;
};
-extern alist<struct setting> settings;
-extern raleigh::saving_window *main_w;
+using namespace raleigh;
+
+template<class backing_type, class editing_widget, void (*load_into_widget)(editing_widget &ew, backing_type s), void (*save_from_widget)(editing_widget &ew, backing_type &s)>
+void do_common_editor(setting &s) {
+ dllist<widget &> widgets;
+
+ label l(s.name);
+ widgets.add_back(l);
+
+ editing_widget ew;
+ load_into_widget(ew, (backing_type)s.backing);
+ widgets.add_back(ew);
+
+ vbox box(widgets);
+
+ dialog d(box, okay_cancel);
+ d.show_modal();
+
+ if (d.result == OKAY)
+ save_from_widget(ew, (backing_type &)s.backing);
+}
#endif \ No newline at end of file