mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2025-12-31 06:30:52 +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:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -90,6 +90,7 @@ struct _MwVoidKeyValue {
|
||||
struct _MwWidget {
|
||||
char* name;
|
||||
MwLLColor bgcolor;
|
||||
int dark_theme;
|
||||
|
||||
MwLL lowlevel;
|
||||
MwWidget parent;
|
||||
|
||||
@@ -303,6 +303,12 @@
|
||||
<widget name="handle" />
|
||||
</arguments>
|
||||
</function>
|
||||
<function name="MwToggleDarkTheme">
|
||||
<arguments>
|
||||
<widget name="handle" />
|
||||
<integer name="toggle" />
|
||||
</arguments>
|
||||
</function>
|
||||
</functions>
|
||||
</header>
|
||||
<header name="Error">
|
||||
|
||||
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