Skip to content

Commit

Permalink
Implement color palette in Vue (#2047)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
huchenlei and github-actions authored Dec 26, 2024
1 parent f1eee96 commit db572a4
Show file tree
Hide file tree
Showing 29 changed files with 501 additions and 608 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('TreeExplorerTreeNode', () => {
expect(handleRenameMock).toHaveBeenCalledOnce()
expect(addToastSpy).toHaveBeenCalledWith({
severity: 'error',
summary: 'g.error',
summary: 'Error',
detail: 'Rename failed',
life: 3000
})
Expand Down
2 changes: 2 additions & 0 deletions src/components/dialog/content/SettingDialogContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<template #header>
<CurrentUserMessage v-if="tabValue === 'Comfy'" />
<FirstTimeUIMessage v-if="tabValue === 'Comfy'" />
<ColorPaletteMessage v-if="tabValue === 'Appearance'" />
</template>
<SettingsPanel :settingGroups="sortedGroups(category)" />
</PanelTemplate>
Expand Down Expand Up @@ -77,6 +78,7 @@ import PanelTemplate from './setting/PanelTemplate.vue'
import AboutPanel from './setting/AboutPanel.vue'
import FirstTimeUIMessage from './setting/FirstTimeUIMessage.vue'
import CurrentUserMessage from './setting/CurrentUserMessage.vue'
import ColorPaletteMessage from './setting/ColorPaletteMessage.vue'
import { flattenTree } from '@/utils/treeUtil'
import { isElectron } from '@/utils/envUtil'
import { normalizeI18nKey } from '@/utils/formatUtil'
Expand Down
63 changes: 63 additions & 0 deletions src/components/dialog/content/setting/ColorPaletteMessage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template>
<Message severity="info" icon="pi pi-palette" pt:text="w-full">
<div class="flex items-center justify-between">
<div>
{{ $t('settingsCategories.ColorPalette') }}
</div>
<div class="actions">
<Select
class="w-44"
v-model="activePaletteId"
:options="palettes"
optionLabel="name"
optionValue="id"
/>
<Button
icon="pi pi-download"
text
:title="$t('g.download')"
@click="colorPaletteService.exportColorPalette(activePaletteId)"
/>
<Button
icon="pi pi-upload"
text
:title="$t('g.import')"
@click="importCustomPalette"
/>
<Button
icon="pi pi-trash"
severity="danger"
text
:title="$t('g.delete')"
@click="colorPaletteService.deleteCustomColorPalette(activePaletteId)"
:disabled="!colorPaletteStore.isCustomPalette(activePaletteId)"
/>
</div>
</div>
</Message>
</template>

<script setup lang="ts">
import Button from 'primevue/button'
import Message from 'primevue/message'
import Select from 'primevue/select'
import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
import { useColorPaletteService } from '@/services/colorPaletteService'
import { storeToRefs } from 'pinia'
import { watch } from 'vue'
const colorPaletteStore = useColorPaletteStore()
const colorPaletteService = useColorPaletteService()
const { palettes, activePaletteId } = storeToRefs(colorPaletteStore)
const importCustomPalette = async () => {
const palette = await colorPaletteService.importColorPalette()
if (palette) {
colorPaletteService.loadColorPalette(palette.id)
}
}
watch(activePaletteId, () => {
colorPaletteService.loadColorPalette(activePaletteId.value)
})
</script>
15 changes: 15 additions & 0 deletions src/components/graph/GraphCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ import { ChangeTracker } from '@/scripts/changeTracker'
import { api } from '@/scripts/api'
import { useCommandStore } from '@/stores/commandStore'
import { workflowService } from '@/services/workflowService'
import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
import { useColorPaletteService } from '@/services/colorPaletteService'
const emit = defineEmits(['ready'])
const canvasRef = ref<HTMLCanvasElement | null>(null)
Expand Down Expand Up @@ -209,6 +211,13 @@ watchEffect(() => {
canvasStore.canvas.canvas.style.cursor = 'default'
})
const colorPaletteService = useColorPaletteService()
watchEffect(() => {
if (!canvasStore.canvas) return
colorPaletteService.loadColorPalette(settingStore.get('Comfy.ColorPalette'))
})
const workflowStore = useWorkflowStore()
const persistCurrentWorkflow = () => {
const workflow = JSON.stringify(comfyApp.serializeGraph())
Expand Down Expand Up @@ -315,6 +324,12 @@ onMounted(async () => {
comfyAppReady.value = true
// Load color palette
const colorPaletteStore = useColorPaletteStore()
colorPaletteStore.customPalettes = settingStore.get(
'Comfy.CustomColorPalettes'
)
// Start watching for locale change after the initial value is loaded.
watch(
() => settingStore.get('Comfy.Locale'),
Expand Down
20 changes: 7 additions & 13 deletions src/components/graph/NodeBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
<script setup lang="ts">
import { computed, onMounted, watch } from 'vue'
import { useSettingStore } from '@/stores/settingStore'
import {
defaultColorPalette,
getColorPalette
} from '@/extensions/core/colorPalette'
import { app } from '@/scripts/app'
import type { LGraphNode } from '@comfyorg/litegraph'
import { BadgePosition } from '@comfyorg/litegraph'
import { LGraphBadge } from '@comfyorg/litegraph'
import _ from 'lodash'
import { NodeBadgeMode } from '@/types/nodeSource'
import { ComfyNodeDefImpl, useNodeDefStore } from '@/stores/nodeDefStore'
import type { Palette } from '@/types/colorPaletteTypes'
import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
const settingStore = useSettingStore()
const colorPaletteStore = useColorPaletteStore()
const nodeSourceBadgeMode = computed(
() => settingStore.get('Comfy.NodeBadge.NodeSourceBadgeMode') as NodeBadgeMode
)
Expand All @@ -36,10 +34,6 @@ watch([nodeSourceBadgeMode, nodeIdBadgeMode, nodeLifeCycleBadgeMode], () => {
app.graph?.setDirtyCanvas(true, true)
})
const colorPalette = computed<Palette | undefined>(() =>
getColorPalette(settingStore.get('Comfy.ColorPalette'))
)
const nodeDefStore = useNodeDefStore()
function badgeTextVisible(
nodeDef: ComfyNodeDefImpl | null,
Expand Down Expand Up @@ -79,11 +73,11 @@ onMounted(() => {
}
),
fgColor:
colorPalette.value?.colors?.litegraph_base?.BADGE_FG_COLOR ||
defaultColorPalette.colors.litegraph_base.BADGE_FG_COLOR,
colorPaletteStore.completedActivePalette.colors.litegraph_base
.BADGE_FG_COLOR,
bgColor:
colorPalette.value?.colors?.litegraph_base?.BADGE_BG_COLOR ||
defaultColorPalette.colors.litegraph_base.BADGE_BG_COLOR
colorPaletteStore.completedActivePalette.colors.litegraph_base
.BADGE_BG_COLOR
})
})
Expand Down
16 changes: 6 additions & 10 deletions src/components/node/NodePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ https://github.com/Nuked88/ComfyUI-N-Sidebar/blob/7ae7da4a9761009fb6629bc04c6830

<script setup lang="ts">
import { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
import {
getColorPalette,
defaultColorPalette
} from '@/extensions/core/colorPalette'
import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
import _ from 'lodash'
import { useWidgetStore } from '@/stores/widgetStore'
import { computed } from 'vue'

const props = defineProps({
nodeDef: {
Expand All @@ -95,12 +93,10 @@ const props = defineProps({
}
})

// Node preview currently is recreated every time something is hovered.
// So not reactive to the color palette changes after setup is fine.
// If later we want NodePreview to be shown more persistently, then we should
// make the getColorPalette() call reactive.
const colors = getColorPalette()?.colors?.litegraph_base
const litegraphColors = colors ?? defaultColorPalette.colors.litegraph_base
const colorPaletteStore = useColorPaletteStore()
const litegraphColors = computed(
() => colorPaletteStore.completedActivePalette.colors.litegraph_base
)

const widgetStore = useWidgetStore()

Expand Down
2 changes: 2 additions & 0 deletions src/constants/coreColorPalettes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export const CORE_COLOR_PALETTES: ColorPalettes = {
nord,
github
} as const

export const DEFAULT_COLOR_PALETTE = dark
15 changes: 15 additions & 0 deletions src/constants/coreSettings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ColorPalettes } from '@/types/colorPaletteTypes'
import type { Keybinding } from '@/types/keyBindingTypes'
import { NodeBadgeMode } from '@/types/nodeSource'
import { LinkReleaseTriggerAction } from '@/types/searchBoxTypes'
Expand Down Expand Up @@ -663,5 +664,19 @@ export const CORE_SETTINGS: SettingParams[] = [
type: 'boolean',
defaultValue: true,
versionAdded: '1.5.6'
},
{
id: 'Comfy.ColorPalette',
name: 'The active color palette id',
type: 'hidden',
defaultValue: 'dark',
versionModified: '1.6.7'
},
{
id: 'Comfy.CustomColorPalettes',
name: 'Custom color palettes',
type: 'hidden',
defaultValue: {} as ColorPalettes,
versionModified: '1.6.7'
}
]
Loading

0 comments on commit db572a4

Please sign in to comment.