Skip to content

Commit

Permalink
Rename user Fonts and build won't synchronize to ui_font_xxx.c ,cause…
Browse files Browse the repository at this point in the history
… compile error! #608
  • Loading branch information
mvladic committed Oct 31, 2024
1 parent 81e1dc7 commit 27245b9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
36 changes: 33 additions & 3 deletions packages/project-editor/features/font/font.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,36 @@ export class Font extends EezObject {
return undefined;
}
},
icon: "material:font_download"
icon: "material:font_download",

updateObjectValueHook: (font: Font, values: Partial<Font>) => {
const projectStore = getProjectStore(font);
if (
projectStore.projectTypeTraits.isLVGL &&
values.name != undefined &&
font.name != values.name
) {
projectStore.undoManager.postponeSetCombineCommandsFalse = true;

setTimeout(async () => {
projectStore.undoManager.postponeSetCombineCommandsFalse =
false;

try {
await font.rebuildLvglFont(
projectStore,
projectStore.project.settings.general.lvglVersion,
projectStore.project.settings.build.lvglInclude,
values.name
);
} catch (err) {
console.error(err);
}

projectStore.undoManager.setCombineCommands(false);
});
}
}
};

get glyphsMap() {
Expand Down Expand Up @@ -1682,14 +1711,15 @@ export class Font extends EezObject {
async rebuildLvglFont(
projectStore: ProjectStore,
lvglVersion: string,
lvglInclude: string
lvglInclude: string,
name?: string
) {
if (!this.embeddedFontFile) {
return;
}

const fontProperties = await extractFont({
name: this.name,
name: name || this.name,
absoluteFilePath: projectStore.getAbsoluteFilePath(
this.source!.filePath
),
Expand Down
6 changes: 6 additions & 0 deletions packages/project-editor/store/undo-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class UndoManager {
private selectionBeforeFirstCommand: any;
public combineCommands: boolean = false;

postponeSetCombineCommandsFalse: boolean = false;

constructor(public projectStore: ProjectStore) {
makeObservable(this, {
undoStack: observable,
Expand Down Expand Up @@ -61,6 +63,10 @@ export class UndoManager {
}

setCombineCommands(value: boolean) {
if (value == false && this.postponeSetCombineCommandsFalse) {
return;
}

this.pushToUndoStack();
this.combineCommands = value;

Expand Down

0 comments on commit 27245b9

Please sign in to comment.