cleanup application properties; fix columns + choice list view insets

This commit is contained in:
nakst 2021-08-27 22:27:02 +01:00
parent 6bb77d889e
commit bb63553186
8 changed files with 64 additions and 38 deletions

View File

@ -55,6 +55,7 @@ struct EsListView : EsElement {
// TODO Updating these when the style changes.
UIStyle *primaryCellStyle;
UIStyle *secondaryCellStyle;
UIStyle *selectedCellStyle;
bool hasFocusedItem;
EsListViewIndex focusedItemGroup;
@ -1145,8 +1146,8 @@ struct EsListView : EsElement {
if (EsRectangleClip(drawBounds, message->painter->clip, nullptr)
&& ES_HANDLED == EsMessageSend(this, &m)) {
UIStyle *style = (flags & ES_LIST_VIEW_CHOICE_SELECT) ? ((UIStyle *) message->painter->style)
: i ? secondaryCellStyle : primaryCellStyle;
bool useSelectedCellStyle = (item->element->customStyleState & THEME_STATE_SELECTED) && (flags & ES_LIST_VIEW_CHOICE_SELECT);
UIStyle *style = useSelectedCellStyle ? selectedCellStyle : i ? secondaryCellStyle : primaryCellStyle;
uint8_t previousTextAlign = style->textAlign;
@ -1636,6 +1637,7 @@ struct EsListView : EsElement {
primaryCellStyle->CloseReference();
secondaryCellStyle->CloseReference();
selectedCellStyle->CloseReference();
fixedItems.Free();
visibleItems.Free();
groups.Free();
@ -1955,6 +1957,7 @@ EsListView *EsListViewCreate(EsElement *parent, uint64_t flags, const EsStyle *s
view->primaryCellStyle = GetStyle(MakeStyleKey(ES_STYLE_LIST_PRIMARY_CELL, 0), false);
view->secondaryCellStyle = GetStyle(MakeStyleKey(ES_STYLE_LIST_SECONDARY_CELL, 0), false);
view->selectedCellStyle = GetStyle(MakeStyleKey(ES_STYLE_LIST_SELECTED_CHOICE_CELL, 0), false); // Only used for choice list views.
view->Initialise(parent, flags | ES_ELEMENT_FOCUSABLE, ListViewProcessMessage, style ?: ES_STYLE_LIST_VIEW);
view->cName = "list view";

View File

@ -1,6 +1,5 @@
// TODO Undo button overlapped slightly when scrollbar shown.
// Maybe we should use a toolbar for these buttons?
// Need to make an animation for showing/hiding the toolbar.
// TODO We can't wait for the worker thread if we have the message mutex, or it'll cause deadlock!
// TODO Waiting for the worker thread to exit when destroying instance.
struct SettingsInstance : CommonDesktopInstance {
EsPanel *switcher;
@ -11,6 +10,7 @@ struct SettingsInstance : CommonDesktopInstance {
// Applications page:
EsHandle workerThread;
EsListView *applicationsList;
EsPanel *applicationInspector;
volatile bool workerStop;
};
@ -129,12 +129,18 @@ const EsStyle styleSliderRow = {
},
};
const EsStyle styleApplicationsList = {
.inherit = ES_STYLE_LIST_CHOICE_BORDERED,
const EsStyle styleSettingsApplicationsPage = {
.metrics = {
.mask = ES_THEME_METRICS_PREFERRED_HEIGHT,
.preferredHeight = 0,
.mask = ES_THEME_METRICS_INSETS | ES_THEME_METRICS_GAP_MAJOR,
.insets = ES_RECT_1(10),
.gapMajor = 10,
},
};
const EsStyle styleSettingsApplicationsPage2 = {
.metrics = {
.mask = ES_THEME_METRICS_GAP_MAJOR,
.gapMajor = 10,
},
};
@ -236,7 +242,10 @@ void SettingsPageUnimplemented(EsElement *element, SettingsPage *page) {
EsPanel *content = EsPanelCreate(element, ES_CELL_FILL | ES_PANEL_V_SCROLL_AUTO, &styleNewTabContent);
EsPanel *container = EsPanelCreate(content, ES_PANEL_VERTICAL | ES_CELL_H_SHRINK, &styleSettingsGroupContainer2);
SettingsAddTitle(container, page);
EsTextDisplayCreate(container, ES_CELL_H_CENTER, 0, "Work in progress" ELLIPSIS);
EsPanel *warningRow = EsPanelCreate(container, ES_CELL_H_CENTER | ES_PANEL_HORIZONTAL, &styleSettingsTable);
EsIconDisplayCreate(warningRow, ES_FLAGS_DEFAULT, 0, ES_ICON_DIALOG_WARNING);
EsTextDisplayCreate(warningRow, ES_FLAGS_DEFAULT, 0, "Work in progress" ELLIPSIS);
}
void SettingsCheckboxCommand(EsInstance *_instance, EsElement *element, EsCommand *) {
@ -469,6 +478,10 @@ void SettingsPageKeyboard(EsElement *element, SettingsPage *page) {
EsPanel *container = EsPanelCreate(content, ES_PANEL_VERTICAL | ES_CELL_H_SHRINK, &styleSettingsGroupContainer2);
SettingsAddTitle(container, page);
EsPanel *warningRow = EsPanelCreate(container, ES_CELL_H_CENTER | ES_PANEL_HORIZONTAL, &styleSettingsTable);
EsIconDisplayCreate(warningRow, ES_FLAGS_DEFAULT, 0, ES_ICON_DIALOG_WARNING);
EsTextDisplayCreate(warningRow, ES_FLAGS_DEFAULT, 0, "Work in progress" ELLIPSIS);
EsPanel *table = EsPanelCreate(container, ES_CELL_H_FILL | ES_PANEL_TABLE | ES_PANEL_HORIZONTAL, &styleSettingsTable);
EsPanelSetBands(table, 2);
@ -498,6 +511,11 @@ void SettingsPageKeyboard(EsElement *element, SettingsPage *page) {
EsTextboxCreate(testBox, ES_CELL_H_LEFT)->accessKey = 'T';
}
void SettingsPageApplicationsRefresh(SettingsInstance *instance) {
EsElementDestroyContents(instance->applicationInspector);
EsTextDisplayCreate(instance->applicationInspector, ES_CELL_H_FILL, 0, INTERFACE_STRING(DesktopSettingsApplicationSelectItem));
}
void SettingsPageApplicationsWorkerThread(EsGeneric context) {
SettingsInstance *instance = (SettingsInstance *) context.p;
EsListViewIndex index;
@ -540,21 +558,24 @@ void SettingsPageApplicationsWorkerThread(EsGeneric context) {
if (EsListViewFixedItemFindIndex(instance->applicationsList, application, &index)) {
EsListViewFixedItemAddString(instance->applicationsList, index, buffer, EsStringFormat(buffer, sizeof(buffer), "%D", application->totalSize));
EsGeneric selected;
if (EsListViewFixedItemGetSelected(instance->applicationsList, &selected) && selected.p == application) {
SettingsPageApplicationsRefresh(instance);
}
}
EsMessageMutexRelease();
}
}
void SettingsPageApplications(EsElement *element, SettingsPage *page) {
void SettingsPageApplications(EsElement *element, SettingsPage *) {
SettingsInstance *instance = (SettingsInstance *) element->instance;
EsPanel *content = EsPanelCreate(element, ES_CELL_FILL | ES_PANEL_V_SCROLL_AUTO, &styleNewTabContent);
EsPanel *container = EsPanelCreate(content, ES_PANEL_VERTICAL | ES_CELL_H_SHRINK, &styleSettingsGroupContainer3);
SettingsAddTitle(container, page);
EsPanel *content = EsPanelCreate(element, ES_CELL_FILL | ES_PANEL_HORIZONTAL, &styleSettingsApplicationsPage);
EsTextDisplayCreate(container, ES_CELL_H_FILL, 0, INTERFACE_STRING(DesktopSettingsApplicationSelectItem));
uint64_t listFlags = ES_CELL_H_FILL | ES_LIST_VIEW_CHOICE_SELECT | ES_LIST_VIEW_FIXED_ITEMS | ES_LIST_VIEW_COLUMNS;
EsListView *list = EsListViewCreate(container, listFlags, &styleApplicationsList);
uint64_t listFlags = ES_CELL_FILL | ES_LIST_VIEW_CHOICE_SELECT | ES_LIST_VIEW_FIXED_ITEMS | ES_LIST_VIEW_COLUMNS;
EsListView *list = EsListViewCreate(content, listFlags, ES_STYLE_LIST_CHOICE_BORDERED);
instance->applicationsList = list;
EsListViewSetColumns(list, settingsApplicationListColumns, sizeof(settingsApplicationListColumns) / sizeof(settingsApplicationListColumns[0]));
list->accessKey = 'L';
@ -580,6 +601,18 @@ void SettingsPageApplications(EsElement *element, SettingsPage *page) {
EsThreadInformation thread;
EsThreadCreate(SettingsPageApplicationsWorkerThread, &thread, instance);
instance->workerThread = thread.handle;
list->messageUser = [] (EsElement *element, EsMessage *message) {
if (message->type == ES_MSG_LIST_VIEW_SELECT) {
SettingsInstance *instance = (SettingsInstance *) element->instance;
SettingsPageApplicationsRefresh(instance);
}
return 0;
};
instance->applicationInspector = EsPanelCreate(content, ES_CELL_FILL | ES_PANEL_V_SCROLL_AUTO, &styleSettingsApplicationsPage2);
SettingsPageApplicationsRefresh(instance);
}
SettingsPage settingsPages[] = {

View File

@ -39,6 +39,7 @@ define ES_STYLE_LIST_ITEM_GROUP_HEADER (ES_STYLE_CAST(1283))
define ES_STYLE_LIST_ITEM_TILE (ES_STYLE_CAST(1285))
define_private ES_STYLE_LIST_PRIMARY_CELL (ES_STYLE_CAST(1287))
define_private ES_STYLE_LIST_SECONDARY_CELL (ES_STYLE_CAST(1289))
define_private ES_STYLE_LIST_SELECTED_CHOICE_CELL (ES_STYLE_CAST(1621))
define_private ES_STYLE_LIST_SELECTION_BOX (ES_STYLE_CAST(1291))
define ES_STYLE_LIST_VIEW (ES_STYLE_CAST(1293))
define ES_STYLE_LIST_VIEW_BORDERED (ES_STYLE_CAST(1295))

Binary file not shown.

Binary file not shown.

View File

@ -124,7 +124,7 @@ DEFINE_INTERFACE_STRING(DesktopSettingsMouseSpeedFast, "Fast");
DEFINE_INTERFACE_STRING(DesktopSettingsMouseCursorTrailsNone, "None");
DEFINE_INTERFACE_STRING(DesktopSettingsMouseCursorTrailsMany, "Many");
DEFINE_INTERFACE_STRING(DesktopSettingsApplicationSelectItem, "Select an application:");
DEFINE_INTERFACE_STRING(DesktopSettingsApplicationSelectItem, "Select an application to view its information or manage it.");
// File operations.

View File

@ -513,10 +513,8 @@ typedef struct DependencyFile {
typedef struct Application {
const char *name;
const char *icon;
const char **permissions;
EsINIState *properties;
int id;
bool useSingleProcess, hidden;
FileType *fileTypes;
Handler *handlers;
@ -691,15 +689,8 @@ void ParseApplicationManifest(const char *manifestPath) {
INI_READ_STRING_PTR(require, require);
} else if (0 == strcmp(s.section, "general")) {
INI_READ_STRING_PTR(name, application.name);
INI_READ_STRING_PTR(icon, application.icon);
INI_READ_BOOL(use_single_process, application.useSingleProcess);
INI_READ_BOOL(hidden, application.hidden);
INI_READ_STRING_PTR(name, application.name);
INI_READ_BOOL(disabled, disabled);
if (0 == memcmp("permission_", s.key, 11) && atoi(s.value)) {
arrput(application.permissions, s.key);
}
else INI_READ_BOOL(disabled, disabled);
else if (s.keyBytes && s.valueBytes) arrput(application.properties, s);
} else if (0 == strcmp(s.sectionClass, "handler")) {
if (!s.keyBytes) {
Handler _handler = {};
@ -807,14 +798,11 @@ void OutputSystemConfiguration() {
FilePrintFormat(file, "\n[@application %d]\n", applications[i].id);
FilePrintFormat(file, "name=%s\n", applications[i].name);
FilePrintFormat(file, "icon=%s\n", applications[i].icon);
FilePrintFormat(file, "use_single_process=%d\n", applications[i].useSingleProcess);
FilePrintFormat(file, "hidden=%d\n", applications[i].hidden);
FilePrintFormat(file, "executable=0:/Applications/%s.esx\n", applications[i].name);
FilePrintFormat(file, "is_file_manager=%d\n", 0 == strcmp(applications[i].name, "File Manager") ? 1 : 0);
for (uintptr_t j = 0; j < arrlenu(applications[i].permissions); j++) {
FilePrintFormat(file, "%s=1\n", applications[i].permissions[j]);
for (uintptr_t j = 0; j < arrlenu(applications[i].properties); j++) {
FilePrintFormat(file, "%s=%s\n", applications[i].properties[j].key, applications[i].properties[j].value);
}
for (uintptr_t j = 0; j < arrlenu(applications[i].fileTypes); j++) {

View File

@ -3655,7 +3655,8 @@ int StylesTableMessage(UIElement *element, UIMessage message, int di, void *dp)
}
}
SetSelectedItems(MOD_CONTEXT(stylesInList[index], keepExistingLayer ? selected.layer : NULL, NULL, NULL));
SetSelectedItems(MOD_CONTEXT(stylesInList[index], keepExistingLayer ? selected.layer
: LayerLookup(stylesInList[index]->layers[0]), NULL, NULL));
UIElementRefresh(&stylesTable->e);
}
}