diff --git a/examples/basic/example.c b/examples/basic/example.c
index a4be2ff..1a38297 100644
--- a/examples/basic/example.c
+++ b/examples/basic/example.c
@@ -11,6 +11,16 @@ void handler(MwWidget handle, void* user_data, void* call_data) {
printf("hello world!\n");
}
+int toggle = 0;
+void handler_dark(MwWidget handle, void* user_data, void* call_data) {
+ (void)handle;
+ (void)user_data;
+ (void)call_data;
+
+ toggle = toggle ? 0 : 1;
+ MwToggleDarkTheme(window, toggle);
+}
+
void resize(MwWidget handle, void* user_data, void* call_data) {
unsigned int w, h, mh;
@@ -53,23 +63,26 @@ int main() {
NULL);
menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0);
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 300, 125,
- MwNtext, "lorem ipsum",
+ MwNtext, "toggle dark theme",
NULL);
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
MwNtext, "lorem ipsum",
MwNbackground, "#f66",
+ MwNforeground, "#000",
NULL);
button3 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
MwNtext, "lorem ipsum",
MwNbackground, "#6f6",
+ MwNforeground, "#000",
NULL);
button4 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
MwNtext, "lorem ipsum",
MwNbackground, "#66f",
+ MwNforeground, "#000",
NULL);
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
- MwAddUserHandler(button, MwNactivateHandler, handler, NULL);
+ MwAddUserHandler(button, MwNactivateHandler, handler_dark, NULL);
MwAddUserHandler(button2, MwNactivateHandler, handler, NULL);
MwAddUserHandler(button3, MwNactivateHandler, handler, NULL);
MwAddUserHandler(button4, MwNactivateHandler, handler, NULL);
diff --git a/examples/color_picker.c b/examples/color_picker.c
index 2f7e2fd..c7ae9da 100644
--- a/examples/color_picker.c
+++ b/examples/color_picker.c
@@ -6,9 +6,9 @@ MwWidget vp;
#define WIN_SIZE 512
#define PICKER_SIZE 360
#define IMG_POS ((WIN_SIZE - PICKER_SIZE) / 2)
-#define SCROLL_BAR_WIDTH (PICKER_SIZE / 32)
+#define SCROLL_BAR_WIDTH 12
#define MARGIN (PICKER_SIZE / 32)
-#define COLOR_DISPLAY_HEIGHT (PICKER_SIZE / 4)
+#define COLOR_DISPLAY_HEIGHT 12
typedef struct {
double r; // a fraction between 0 and 1
diff --git a/include/Mw/Core.h b/include/Mw/Core.h
index 96daf29..e55864c 100644
--- a/include/Mw/Core.h
+++ b/include/Mw/Core.h
@@ -272,6 +272,13 @@ MWDECL void MwGrabPointer(MwWidget handle, int toggle);
*/
MWDECL void MwHideCursor(MwWidget handle);
+/*!
+ * %param Toggles the dark theme
+ * %param handle Widget
+ * %param toggle Toggle
+ */
+MWDECL void MwToggleDarkTheme(MwWidget handle, int toggle);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/Mw/Default.h b/include/Mw/Default.h
index a0341a8..4fad75f 100644
--- a/include/Mw/Default.h
+++ b/include/Mw/Default.h
@@ -23,6 +23,16 @@ MWDECL const char* MwDefaultBackground;
*/
MWDECL const char* MwDefaultForeground;
+/*!
+ * %brief Default dark theme background color
+ */
+MWDECL const char* MwDefaultDarkBackground;
+
+/*!
+ * %brief Default dark theme foreground color
+ */
+MWDECL const char* MwDefaultDarkForeground;
+
/*!
* %brief Gets default border width
* %param handle Widget
diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h
index ee49a6e..ecea50f 100644
--- a/include/Mw/TypeDefs.h
+++ b/include/Mw/TypeDefs.h
@@ -90,6 +90,7 @@ struct _MwVoidKeyValue {
struct _MwWidget {
char* name;
MwLLColor bgcolor;
+ int dark_theme;
MwLL lowlevel;
MwWidget parent;
diff --git a/milsko.xml b/milsko.xml
index 5e818bb..0ef7df1 100644
--- a/milsko.xml
+++ b/milsko.xml
@@ -303,6 +303,12 @@
+
+
+
+
+
+
diff --git a/src/core.c b/src/core.c
index 90f99f0..ba3b86e 100644
--- a/src/core.c
+++ b/src/core.c
@@ -127,6 +127,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
h->draw_inject = NULL;
h->tick_list = NULL;
h->destroyed = 0;
+ h->dark_theme = 0;
if(parent == NULL) arrput(h->tick_list, h);
@@ -369,6 +370,25 @@ int MwGetInteger(MwWidget handle, const char* key) {
}
const char* MwGetText(MwWidget handle, const char* key) {
+ if(shgeti(handle->text, key) == -1 && (strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0)) {
+ const char* v = NULL;
+ MwWidget h = handle->parent;
+ while(h != NULL) {
+ if((v = MwGetText(h, key)) != NULL) break;
+ h = h->parent;
+ }
+ if(v == NULL) {
+ if(handle->dark_theme) {
+ if(strcmp(key, MwNbackground) == 0) return MwDefaultDarkBackground;
+ if(strcmp(key, MwNforeground) == 0) return MwDefaultDarkForeground;
+ } else {
+ if(strcmp(key, MwNbackground) == 0) return MwDefaultBackground;
+ if(strcmp(key, MwNforeground) == 0) return MwDefaultForeground;
+ }
+ }
+ return v;
+ }
+
return shget(handle->text, key);
}
@@ -408,19 +428,6 @@ void MwVaListApply(MwWidget handle, va_list va) {
}
}
-static void inherit_text(MwWidget handle, const char* key, const char* default_value) {
- const char* text;
- MwWidget h = handle;
- while(h != NULL) {
- if((text = MwGetText(h, key)) != NULL) {
- MwSetText(handle, key, text);
- return;
- }
- h = h->parent;
- }
- MwSetText(handle, key, default_value);
-}
-
static void inherit_integer(MwWidget handle, const char* key, int default_value) {
int n;
MwWidget h = handle;
@@ -467,8 +474,6 @@ static void set_boldfont(MwWidget handle) {
void MwSetDefault(MwWidget handle) {
MwLLSetCursor(handle->lowlevel, &MwCursorDefault, &MwCursorDefaultMask);
- inherit_text(handle, MwNbackground, MwDefaultBackground);
- inherit_text(handle, MwNforeground, MwDefaultForeground);
#ifdef MW_CLASSIC_THEME
inherit_integer(handle, MwNmodernLook, 0);
#else
@@ -552,3 +557,20 @@ void MwGrabPointer(MwWidget handle, int toggle) {
if(toggle) MwFocus(handle);
MwLLGrabPointer(handle->lowlevel, toggle);
}
+
+static void force_render_all(MwWidget handle) {
+ int i;
+ for(i = 0; i < arrlen(handle->children); i++) {
+ force_render_all(handle->children[i]);
+ }
+ MwForceRender(handle);
+}
+
+void MwToggleDarkTheme(MwWidget handle, int toggle) {
+ int old = handle->dark_theme;
+ if(old != toggle) {
+ handle->dark_theme = toggle;
+
+ force_render_all(handle);
+ }
+}
diff --git a/src/default.c b/src/default.c
index 882b86a..6ddd673 100644
--- a/src/default.c
+++ b/src/default.c
@@ -4,6 +4,9 @@
const char* MwDefaultBackground = "#ddd";
const char* MwDefaultForeground = "#000";
+const char* MwDefaultDarkBackground = "#333";
+const char* MwDefaultDarkForeground = "#ddd";
+
int MwGetDefaultBorderWidth(MwWidget handle) {
if(MwGetInteger(handle, MwNmodernLook)) {
return 1;