misc theme changes

This commit is contained in:
nakst 2021-10-08 14:01:01 +01:00
parent 5564a7f2e2
commit 5256335b45
11 changed files with 101 additions and 51 deletions

View File

@ -153,7 +153,25 @@ void InitialiseInstance(EsInstance *instance) {
EsButtonCreate(panel, ES_BUTTON_CHECKBOX, 0, "Checkbox");
EsButtonOnCommand(EsButtonCreate(panel, ES_FLAGS_DEFAULT, 0, "Alert 1"), [] (EsInstance *, EsElement *element, EsCommand *) {
EsDialogShow(element->window, "Title", -1, "Content.", -1, ES_ICON_DIALOG_WARNING, ES_DIALOG_ALERT_OK_BUTTON);
EsDialog *dialog = EsDialogShow(element->window, "Rename multiple items", -1,
"Choose the format for the new names.", -1, ES_ICON_DOCUMENT_EDIT, ES_FLAGS_DEFAULT);
EsElement *contentArea = EsDialogGetContentArea(dialog);
EsPanel *table = EsPanelCreate(contentArea, ES_PANEL_HORIZONTAL | ES_PANEL_TABLE, ES_STYLE_PANEL_FORM_TABLE);
EsPanelSetBands(table, 2);
EsTextDisplayCreate(table, ES_CELL_H_RIGHT, ES_STYLE_TEXT_LABEL, "Prefix:");
EsTextboxInsert(EsTextboxCreate(table), "file ");
EsTextDisplayCreate(table, ES_CELL_H_RIGHT | ES_CELL_V_TOP, ES_STYLE_TEXT_RADIO_GROUP_LABEL, "Content:");
EsPanel *radioGroup = EsPanelCreate(table, ES_PANEL_RADIO_GROUP | ES_CELL_H_EXPAND);
EsButton *button = EsButtonCreate(radioGroup, ES_BUTTON_RADIOBOX | ES_CELL_H_EXPAND, 0, "Counter");
EsButtonSetCheck(button, ES_CHECK_CHECKED);
EsButtonCreate(radioGroup, ES_BUTTON_RADIOBOX | ES_CELL_H_EXPAND, 0, "Original name");
EsButtonCreate(radioGroup, ES_BUTTON_RADIOBOX | ES_CELL_H_EXPAND, 0, "Date modified");
EsTextDisplayCreate(table, ES_CELL_H_RIGHT, ES_STYLE_TEXT_LABEL, "Suffix:");
EsTextboxCreate(table);
EsTextDisplayCreate(contentArea, ES_CELL_H_EXPAND, ES_STYLE_TEXT_PARAGRAPH, "Example: file 1.txt");
EsDialogAddButton(dialog, ES_FLAGS_DEFAULT, 0, "Cancel");
EsDialogAddButton(dialog, ES_BUTTON_DEFAULT, 0, "Rename all");
});
EsPanel *table = EsPanelCreate(panel, ES_CELL_H_FILL | ES_PANEL_TABLE | ES_PANEL_HORIZONTAL | ES_PANEL_TABLE_H_JUSTIFY);

View File

@ -1277,7 +1277,7 @@ void ShutdownModalCreate() {
ES_CELL_H_FILL, ES_STYLE_TEXT_PARAGRAPH, INTERFACE_STRING(DesktopConfirmShutdown))->cName = "dialog contents";
EsPanel *buttonArea = EsPanelCreate(dialog, ES_PANEL_HORIZONTAL | ES_PANEL_REVERSE | ES_CELL_H_FILL, ES_STYLE_DIALOG_BUTTON_AREA);
EsButton *cancelButton = EsButtonCreate(buttonArea, ES_BUTTON_DEFAULT | ES_BUTTON_CANCEL, 0, INTERFACE_STRING(CommonCancel));
EsButton *restartButton = EsButtonCreate(buttonArea, ES_FLAGS_DEFAULT, 0, INTERFACE_STRING(DesktopRestartAction));
EsButton *restartButton = EsButtonCreate(buttonArea, ES_FLAGS_DEFAULT, ES_STYLE_PUSH_BUTTON_DANGEROUS, INTERFACE_STRING(DesktopRestartAction));
EsButton *shutdownButton = EsButtonCreate(buttonArea, ES_FLAGS_DEFAULT, ES_STYLE_PUSH_BUTTON_DANGEROUS, INTERFACE_STRING(DesktopShutdownAction));
EsElementFocus(cancelButton);

View File

@ -3723,6 +3723,10 @@ EsButton *EsDialogAddButton(EsDialog *dialog, uint64_t flags, const EsStyle *sty
return button;
}
EsElement *EsDialogGetContentArea(EsDialog *dialog) {
return dialog->contentArea;
}
// --------------------------------- Canvas panes.
struct EsCanvasPane : EsElement {

View File

@ -2427,10 +2427,11 @@ function void EsMenuClose(EsMenu *menu);
function void EsMenuCloseAll();
function void EsMenuAddCommandsFromToolbar(EsMenu *menu, EsElement *element);
function void EsDialogClose(EsDialog *dialog);
function EsDialog *EsDialogShow(EsWindow *window, STRING title, STRING content, uint32_t iconID, uint32_t flags = ES_FLAGS_DEFAULT);
function EsButton *EsDialogAddButton(EsDialog *dialog, uint64_t flags = ES_FLAGS_DEFAULT, const EsStyle *style = ES_NULL,
STRING label = BLANK_STRING, EsCommandCallback callback = ES_NULL);
function void EsDialogClose(EsDialog *dialog);
function EsElement *EsDialogGetContentArea(EsDialog *dialog);
function void EsFileMenuAddToToolbar(EsElement *toolbar, const EsFileMenuSettings *settings = ES_NULL);
function void EsFileMenuCreate(ES_INSTANCE_TYPE *instance, EsElement *parent, uint64_t flags = ES_FLAGS_DEFAULT);

View File

@ -51,18 +51,27 @@ const EsStyle styleSettingsGroupContainer2 = {
},
};
const uint32_t windowColors[] = {
0xFF0032,
0xFF6042,
0xFF7F24, // TODO Hue shift looks bad.
0xFFFF24, // TODO Hue shift looks bad.
0x67EFC4,
0x54ACE5,
0x448CF5,
0x044CF5,
0xAC00FF,
0xE8ECF9,
0xB7BBC5, // TODO Make this look better when deactivated.
const uint32_t windowColors[][7] = {
// TODO Improve these!
// Preview Active 1 Active 2 Active 3 Inactive 1 Inactive 2 Inactive 3
#if 0
{ 0xFFE7E2EA, 0xFFE7E2EA, 0xFFD2CBD5, 0xFFAFA4B9, 0xFFD2D0F2, 0xFFCDCCFA, 0xFFB5BEDF },
{ 0xFF83B8F7, 0xFF83B8F7, 0xFF6D9CDF, 0xFF4166B5, 0xFFD2D0F2, 0xFFCDCCFA, 0xFFB5BEDF },
{ 0xFFE0E0E0, 0xFFE4E5E7, 0xFFCCCDCF, 0xFF909193, 0xFFD2D0F2, 0xFFCDCCFA, 0xFFB5BEDF },
#else
{ 0xFFFF0032, 0xFFF78399, 0xFFDF6D83, 0xFFB54157, 0xFFF2D0D6, 0xFFFACCD5, 0xFFDFB5BD },
{ 0xFFFF6042, 0xFFF7AEA1, 0xFFDF978A, 0xFFB56C5F, 0xFFF2DCD8, 0xFFFADDD7, 0xFFDFC4BF },
{ 0xFFFF7F24, 0xFFF7BC93, 0xFFDFA57D, 0xFFB57A51, 0xFFF2E0D4, 0xFFFAE2D2, 0xFFDFC9BA },
{ 0xFFFFFF24, 0xFFF7F793, 0xFFDFDF7D, 0xFFB5B551, 0xFFF2F2D4, 0xFFFAFAD2, 0xFFDFDFBA },
{ 0xFF67EFC4, 0xFFA9E7D3, 0xFF94D1BD, 0xFF6BA996, 0xFFD0E2DD, 0xFFD1EAE2, 0xFFBAD1C9 },
{ 0xFF54ACE5, 0xFF9BC3DD, 0xFF87AEC8, 0xFF6088A2, 0xFFC5D1D9, 0xFFC6D6E0, 0xFFB0BEC8 },
{ 0xFF448CF5, 0xFF9CBDED, 0xFF87A7D6, 0xFF5D7EAD, 0xFFD0DAE8, 0xFFD0DDF0, 0xFFB9C4D6 },
{ 0xFF044CF5, 0xFF7FA0ED, 0xFF6A8AD6, 0xFF4061AD, 0xFFC8D1E8, 0xFFC4D1F0, 0xFFAEBAD6 },
{ 0xFFAC00FF, 0xFFD183F7, 0xFFB96DDF, 0xFF8F41B5, 0xFFE6D0F2, 0xFFEBCCFA, 0xFFD1B5DF },
{ 0xFFE8ECF9, 0xFFE9EBF1, 0xFFD2D3D9, 0xFFA9AAB0, 0xFFEAEAEC, 0xFFF1F1F4, 0xFFD6D7D9 },
{ 0xFFB7BBC5, 0xFFB8BABE, 0xFFA6A7AC, 0xFF85878B, 0xFFB9B9BA, 0xFFBEBFC1, 0xFFA9AAAC },
#endif
};
const EsStyle styleSettingsGroupContainer3 = {
@ -619,7 +628,7 @@ int SettingsColorButtonMessage(EsElement *element, EsMessage *message) {
uint32_t cornerRadii[4] = { cornerRadius, cornerRadius, cornerRadius, cornerRadius };
int32_t borderSize = 1 * EsElementGetScaleFactor(element);
uint32_t color = EsColorBlend(windowColors[element->userData.u] | 0xFF000000, 0x20FFFFFF, false);
uint32_t color = EsColorBlend(windowColors[element->userData.u][0], 0x20FFFFFF, false);
if (element->window->pressed == element) color = EsColorBlend(color, 0x40000000, false);
EsDrawRoundedRectangle(message->painter, bounds, color, EsColorBlend(color, 0x40000000, false), ES_RECT_1(borderSize), cornerRadii);
@ -642,13 +651,7 @@ void SettingsWindowColorUpdated() {
index = 0;
}
EsColorConvertToHSV(windowColors[index], &theming.systemHue, &theming.systemSaturation, &theming.systemValue);
if (theming.systemHue > 0.3f && theming.systemHue < 3.3f) {
theming.systemHueShift = -1.5f;
} else {
theming.systemHueShift = 1.0f;
}
EsMemoryCopy(theming.windowColors, &windowColors[index][1], sizeof(theming.windowColors));
for (uintptr_t i = 0; i < gui.allWindows.Length(); i++) {
if (gui.allWindows[i]->windowStyle == ES_WINDOW_CONTAINER) {

View File

@ -101,12 +101,14 @@ typedef struct ThemePaintSolid {
typedef struct ThemeGradientStop {
uint32_t color;
int8_t position;
uint8_t windowColorIndex;
uint16_t _unused1;
} ThemeGradientStop;
typedef struct ThemePaintLinearGradient {
float transform[3];
uint8_t stopCount;
int8_t useGammaInterpolation : 1, useDithering : 1, useSystemColor : 1;
int8_t useGammaInterpolation : 1, useDithering : 1;
uint8_t repeatMode;
uint8_t _unused0;
// Followed by gradient stops.
@ -352,7 +354,7 @@ struct {
EsPaintTarget cursors;
float scale;
HashStore<UIStyleKey, struct UIStyle *> loadedStyles;
float systemHue, systemSaturation, systemValue, systemHueShift;
uint32_t windowColors[6];
} theming;
#endif
@ -584,6 +586,27 @@ void ThemeFillBlurCorner(EsPainter *painter, EsRectangle bounds, int cx, int cy,
}
}
uint32_t WindowColorCalculate(uint8_t index) {
#ifdef IN_DESIGNER
uint32_t windowColors[6] = {
0xFF83B8F7, 0xFF6D9CDF, 0xFF4166B5, // Active container window gradient stops.
0xFFD2D0F2, 0xFFCDCCFA, 0xFFB5BEDF, // Inactive container window gradient stops.
};
#else
uint32_t *windowColors = theming.windowColors;
#endif
if (index >= 30 && index < 60) {
return EsColorInterpolate(windowColors[0], windowColors[3], (index - 30) / 29.0f);
} else if (index >= 60 && index < 90) {
return EsColorInterpolate(windowColors[1], windowColors[4], (index - 60) / 29.0f);
} else if (index >= 90 && index < 120) {
return EsColorInterpolate(windowColors[2], windowColors[5], (index - 90) / 29.0f);
} else {
return 0;
}
}
ES_FUNCTION_OPTIMISE_O2
void GradientCacheSetup(GradientCache *cache, const ThemePaintLinearGradient *gradient, int width, int height, EsBuffer *data) {
if (!gradient) {
@ -615,16 +638,8 @@ void GradientCacheSetup(GradientCache *cache, const ThemePaintLinearGradient *gr
uint32_t color0 = stop0->color;
uint32_t color1 = stop1->color;
#ifndef IN_DESIGNER
if (gradient->useSystemColor) {
float h, h2, s, v;
EsColorConvertToHSV(color0, &h, &s, &v);
color0 = (color0 & 0xFF000000) | EsColorConvertToRGB(theming.systemHue, s * theming.systemSaturation, v * theming.systemValue);
EsColorConvertToHSV(color1, &h2, &s, &v);
color1 = (color1 & 0xFF000000) | EsColorConvertToRGB(theming.systemHue + (h2 - h) * theming.systemHueShift,
s * theming.systemSaturation, v * theming.systemValue);
}
#endif
if (stop0->windowColorIndex) color0 = WindowColorCalculate(stop0->windowColorIndex);
if (stop1->windowColorIndex) color1 = WindowColorCalculate(stop1->windowColorIndex);
float fa = ((color0 >> 24) & 0xFF) / 255.0f;
float fb = ((color0 >> 16) & 0xFF) / 255.0f;
@ -1345,20 +1360,23 @@ void ThemeAnimationDestroy(ThemeAnimation *animation) {
ThemeVariant ThemeAnimatingPropertyInterpolate(ThemeAnimatingProperty *property, UIStyle *destination, uint8_t *layerData) {
uint32_t dataOffset = property->offset;
EsAssert(dataOffset <= destination->layerDataByteCount - sizeof(ThemeVariant));
float position = (float) property->elapsed / property->duration;
position = SmoothAnimationTime(position);
if (property->type == THEME_OVERRIDE_I8) {
EsAssert(dataOffset <= destination->layerDataByteCount - sizeof(uint8_t));
int8_t to = *(int8_t *) (layerData + dataOffset);
return (ThemeVariant) { .i8 = (int8_t ) LinearInterpolate(property->from.i8, to, position) };
} else if (property->type == THEME_OVERRIDE_I16) {
EsAssert(dataOffset <= destination->layerDataByteCount - sizeof(uint16_t));
int16_t to = *(int16_t *) (layerData + dataOffset);
return (ThemeVariant) { .i16 = (int16_t) LinearInterpolate(property->from.i16, to, position) };
} else if (property->type == THEME_OVERRIDE_F32) {
EsAssert(dataOffset <= destination->layerDataByteCount - sizeof(float));
float to = *(float *) (layerData + dataOffset);
return (ThemeVariant) { .f32 = (float) LinearInterpolate(property->from.f32, to, position) };
} else if (property->type == THEME_OVERRIDE_COLOR) {
EsAssert(dataOffset <= destination->layerDataByteCount - sizeof(uint32_t));
uint32_t to = *(uint32_t *) (layerData + dataOffset);
return (ThemeVariant) { .u32 = EsColorInterpolate(property->from.u32, to, position) };
} else {
@ -1413,7 +1431,11 @@ void _ThemeAnimationBuildAddProperties(ThemeAnimation *animation, UIStyle *style
}
uintptr_t key = themeOverride->offset + layerCumulativeDataOffset;
EsAssert(key <= (uintptr_t) style->layerDataByteCount - sizeof(ThemeVariant));
if (themeOverride->type == THEME_OVERRIDE_I8) EsAssert(key <= (uintptr_t) style->layerDataByteCount - sizeof(uint8_t));
if (themeOverride->type == THEME_OVERRIDE_I16) EsAssert(key <= (uintptr_t) style->layerDataByteCount - sizeof(uint16_t));
if (themeOverride->type == THEME_OVERRIDE_F32) EsAssert(key <= (uintptr_t) style->layerDataByteCount - sizeof(float));
if (themeOverride->type == THEME_OVERRIDE_COLOR) EsAssert(key <= (uintptr_t) style->layerDataByteCount - sizeof(uint32_t));
uintptr_t point;
bool alreadyInList;

Binary file not shown.

Binary file not shown.

View File

@ -125,15 +125,7 @@ double SmoothAnimationTimeSharp(double progress) {
return 1 + progressSquared * progressSquared * progress;
}
#endif
#ifdef SHARED_MATH_WANT_ALL
EsRectangle EsRectangleLinearInterpolate(EsRectangle from, EsRectangle to, float progress) {
return ES_RECT_4(LinearInterpolate(from.l, to.l, progress), LinearInterpolate(from.r, to.r, progress),
LinearInterpolate(from.t, to.t, progress), LinearInterpolate(from.b, to.b, progress));
}
#ifndef EsColorInterpolate
uint32_t EsColorInterpolate(uint32_t from, uint32_t to, float progress) {
float fa = ((from >> 24) & 0xFF) / 255.0f;
float fb = ((from >> 16) & 0xFF) / 255.0f;
@ -152,6 +144,14 @@ uint32_t EsColorInterpolate(uint32_t from, uint32_t to, float progress) {
| (uint32_t) (LinearInterpolate(fb, tb, progress) * 255.0f) << 16
| (uint32_t) (LinearInterpolate(fa, ta, progress) * 255.0f) << 24;
}
#endif
#ifndef EsRectangleLinearInterpolate
EsRectangle EsRectangleLinearInterpolate(EsRectangle from, EsRectangle to, float progress) {
return ES_RECT_4(LinearInterpolate(from.l, to.l, progress), LinearInterpolate(from.r, to.r, progress),
LinearInterpolate(from.t, to.t, progress), LinearInterpolate(from.b, to.b, progress));
}
#endif
#endif

View File

@ -488,3 +488,4 @@ EsScrollViewSetFixedViewport=486
EsScrollViewIsBarEnabled=487
EsScrollViewIsInDragScroll=488
_EsOpenDocumentEnumerate=489
EsDialogGetContentArea=490

View File

@ -64,6 +64,8 @@
#define ES_FONT_SERIF (0xFFFE)
#define ES_FONT_MONOSPACED (0xFFFD)
#define ES_RECT_4(a, b, c, d) UI_RECT_4((int32_t) (a), (int32_t) (b), (int32_t) (c), (int32_t) (d))
#define ES_FUNCTION_OPTIMISE_O2 __attribute__((optimize("-O2")))
#define ES_FUNCTION_OPTIMISE_O3 __attribute__((optimize("-O3")))
@ -1773,10 +1775,6 @@ void InspectorPopulate() {
InspectorAddBooleanToggle(object, "Use gamma interpolation", "useGammaInterpolation");
if (object->type == OBJ_PAINT_LINEAR_GRADIENT) {
InspectorAddBooleanToggle(object, "Use window tint color", "useSystemColor");
}
int32_t stopCount = PropertyReadInt32(object, "stops_count");
if (stopCount < 0) stopCount = 0;
if (stopCount > 100) stopCount = 100;
@ -1794,6 +1792,8 @@ void InspectorPopulate() {
InspectorAddLink(object, "Color:", cPropertyName);
sprintf(cPropertyName, "stops_%d_position", i);
InspectorAddInteger(object, "Position (%):", cPropertyName);
sprintf(cPropertyName, "stops_%d_wci", i);
InspectorAddInteger(object, "Window color index:", cPropertyName);
UIParentPop();
if (i != stopCount - 1) {
@ -2030,6 +2030,8 @@ void ExportGradientStopArray(Object *object, ExportContext *data, size_t stopCou
ExportColor(data, stop, color, object, cPropertyName);
sprintf(cPropertyName, "stops_%d_position", (int32_t) i);
ExportI8(data, stop, position, object, cPropertyName);
sprintf(cPropertyName, "stops_%d_wci", (int32_t) i);
ExportI8(data, stop, windowColorIndex, object, cPropertyName);
ExportWrite(data, &stop, sizeof(stop));
}
}
@ -2060,7 +2062,6 @@ int8_t ExportPaint(Object *parentObject, const char *cPropertyNameInParent, Expo
ExportF32(data, paint, transform[2], object, "transformStart");
paint.stopCount = PropertyFindOrInheritReadInt32(object, "stops_count");
paint.useGammaInterpolation = !!PropertyFindOrInheritReadInt32(object, "useGammaInterpolation");
paint.useSystemColor = !!PropertyFindOrInheritReadInt32(object, "useSystemColor");
paint.repeatMode = PropertyFindOrInheritReadInt32(object, "repeatMode");
ExportWrite(data, &paint, sizeof(paint));
ExportGradientStopArray(object, data, paint.stopCount);