mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-08 18:33:30 +00:00
dark theme
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@494 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
52
src/core.c
52
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user