This commit is contained in:
parent
df11b86cea
commit
6cc3925282
6 changed files with 80 additions and 34 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget window, menu, button, button2, button3, button4;
|
||||
MwWidget window, menu, button, button2, button3, button4, button5, button6;
|
||||
|
||||
void handler(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
|
|
@ -10,14 +10,34 @@ 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 handler_theme(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
toggle = toggle ? 0 : 1;
|
||||
MwSetDarkTheme(window, toggle);
|
||||
MwVaApply(window,
|
||||
MwNdarkTheme, MwGetInteger(window, MwNdarkTheme) == 0 ? 1 : 0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void handler_look(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwVaApply(window,
|
||||
MwNmodernLook, MwGetInteger(window, MwNmodernLook) == 0 ? 1 : 0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void handler_font(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwVaApply(window,
|
||||
MwNbitmapFont, MwGetInteger(window, MwNbitmapFont) == 0 ? 1 : 0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void resize(MwWidget handle, void* user_data, void* call_data) {
|
||||
|
|
@ -31,23 +51,37 @@ void resize(MwWidget handle, void* user_data, void* call_data) {
|
|||
|
||||
MwVaApply(button,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, w - 50 * 2,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button2,
|
||||
MwNx, 50 + (w - 50 * 2) / 3,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button3,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 2,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button4,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 0,
|
||||
MwNy, h - 50 - 125 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button3,
|
||||
MwVaApply(button5,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 1,
|
||||
MwNy, h - 50 - 125 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button4,
|
||||
MwVaApply(button6,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 2,
|
||||
MwNy, h - 50 - 125 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
|
|
@ -63,30 +97,38 @@ int main() {
|
|||
MwNtitle, "hello world",
|
||||
NULL);
|
||||
menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0);
|
||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 300, 125,
|
||||
MwNtext, "toggle dark theme",
|
||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 100, 125,
|
||||
MwNtext, "theme",
|
||||
NULL);
|
||||
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
|
||||
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 50, 100, 125,
|
||||
MwNtext, "look",
|
||||
NULL);
|
||||
button3 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 50, 100, 125,
|
||||
MwNtext, "font",
|
||||
NULL);
|
||||
button4 = 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,
|
||||
button5 = 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,
|
||||
button6 = 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_dark, NULL);
|
||||
MwAddUserHandler(button2, MwNactivateHandler, handler, NULL);
|
||||
MwAddUserHandler(button3, MwNactivateHandler, handler, NULL);
|
||||
MwAddUserHandler(button, MwNactivateHandler, handler_theme, NULL);
|
||||
MwAddUserHandler(button2, MwNactivateHandler, handler_look, NULL);
|
||||
MwAddUserHandler(button3, MwNactivateHandler, handler_font, NULL);
|
||||
MwAddUserHandler(button4, MwNactivateHandler, handler, NULL);
|
||||
MwAddUserHandler(button5, MwNactivateHandler, handler, NULL);
|
||||
MwAddUserHandler(button6, MwNactivateHandler, handler, NULL);
|
||||
|
||||
resize(window, NULL, NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -295,6 +295,7 @@ MWDECL void MwHideCursor(MwWidget handle);
|
|||
* @brief Toggles the dark theme
|
||||
* @param handle Widget
|
||||
* @param toggle Toggle
|
||||
* @deprecated Use MwNdarkTheme instead
|
||||
*/
|
||||
MWDECL void MwSetDarkTheme(MwWidget handle, int toggle);
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@
|
|||
#define MwNforceInverted "IforceInverted"
|
||||
#define MwNroundness "Iroundness"
|
||||
#define MwNisRounded "IisRounded"
|
||||
#define MwNdarkTheme "IdarkTheme"
|
||||
|
||||
#define MwNtitle "Stitle"
|
||||
#define MwNtext "Stext"
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ struct _MwVoidKeyValue {
|
|||
struct _MwWidget {
|
||||
char* name;
|
||||
MwLLColor bgcolor;
|
||||
int dark_theme;
|
||||
|
||||
MwLL lowlevel;
|
||||
MwWidget parent;
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@
|
|||
<integer name="forceInverted" />
|
||||
<integer name="roundness" />
|
||||
<integer name="isRounded" />
|
||||
<integer name="darkTheme" />
|
||||
|
||||
<string name="title" />
|
||||
<string name="text" />
|
||||
|
|
|
|||
36
src/core.c
36
src/core.c
|
|
@ -133,7 +133,9 @@ static void lldarkthemehandler(MwLL handle, void* data) {
|
|||
int* ptr = data;
|
||||
|
||||
if(IsFirstVisible(h)) {
|
||||
MwSetDarkTheme(h, *ptr);
|
||||
MwVaApply(h,
|
||||
MwNdarkTheme, *ptr,
|
||||
NULL);
|
||||
|
||||
MwDispatchUserHandler(h, MwNdarkThemeHandler, data);
|
||||
}
|
||||
|
|
@ -164,7 +166,6 @@ 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;
|
||||
h->bgcolor = NULL;
|
||||
h->berserk = 0;
|
||||
|
||||
|
|
@ -416,6 +417,14 @@ void MwLoop(MwWidget handle) {
|
|||
}
|
||||
}
|
||||
|
||||
static void force_render_all(MwWidget handle) {
|
||||
int i;
|
||||
for(i = 0; i < arrlen(handle->children); i++) {
|
||||
force_render_all(handle->children[i]);
|
||||
}
|
||||
if(handle->lowlevel != NULL) MwForceRender(handle);
|
||||
}
|
||||
|
||||
void MwSetInteger(MwWidget handle, const char* key, int n) {
|
||||
int xy;
|
||||
int wh = 0;
|
||||
|
|
@ -440,6 +449,9 @@ void MwSetInteger(MwWidget handle, const char* key, int n) {
|
|||
if(strcmp(key, MwNforceInverted) == 0) {
|
||||
MwForceRender(handle);
|
||||
}
|
||||
if(strcmp(key, MwNmodernLook) == 0 || strcmp(key, MwNdarkTheme) == 0 || strcmp(key, MwNbitmapFont) == 0){
|
||||
force_render_all(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void MwSetText(MwWidget handle, const char* key, const char* value) {
|
||||
|
|
@ -517,6 +529,7 @@ int MwGetInteger(MwWidget handle, const char* key) {
|
|||
if(strcmp(key, MwNmodernLook) == 0) return inherit_integer(handle, key, 1);
|
||||
#endif
|
||||
if(strcmp(key, MwNisRounded) == 0) return inherit_integer(handle, key, 1);
|
||||
if(strcmp(key, MwNdarkTheme) == 0) return inherit_integer(handle, key, 0);
|
||||
}
|
||||
return shget(handle->integer, key);
|
||||
}
|
||||
|
|
@ -531,7 +544,7 @@ const char* MwGetText(MwWidget handle, const char* key) {
|
|||
h = h->parent;
|
||||
}
|
||||
if(v == NULL) {
|
||||
if(handle->dark_theme) {
|
||||
if(MwGetInteger(handle, MwNdarkTheme)) {
|
||||
if(strcmp(key, MwNbackground) == 0) return MwDefaultDarkBackground;
|
||||
if(strcmp(key, MwNforeground) == 0) return MwDefaultDarkForeground;
|
||||
if(strcmp(key, MwNsubBackground) == 0) return MwDefaultDarkSubBackground;
|
||||
|
|
@ -747,21 +760,10 @@ void MwGrabPointer(MwWidget handle, int toggle) {
|
|||
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]);
|
||||
}
|
||||
if(handle->lowlevel != NULL) MwForceRender(handle);
|
||||
}
|
||||
|
||||
void MwSetDarkTheme(MwWidget handle, int toggle) {
|
||||
int old = handle->dark_theme;
|
||||
if(old != toggle) {
|
||||
handle->dark_theme = toggle;
|
||||
|
||||
force_render_all(handle);
|
||||
}
|
||||
MwVaApply(handle,
|
||||
MwNdarkTheme, toggle,
|
||||
NULL);
|
||||
}
|
||||
|
||||
MwWidget MwGetParent(MwWidget handle) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue