Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus mode #1365

Merged
merged 6 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 0 additions & 19 deletions src/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,6 @@ body {
margin: 3px 3px 3px 4px;
}

.comfy-menu-hamburger {
position: fixed;
top: 10px;
z-index: 9999;
right: 10px;
width: 30px;
display: none;
gap: 8px;
flex-direction: column;
cursor: pointer;
}

.comfy-menu-hamburger div {
height: 3px;
width: 100%;
border-radius: 20px;
background-color: white;
}

.comfy-menu {
font-size: 15px;
position: absolute;
Expand Down
46 changes: 46 additions & 0 deletions src/components/MenuHamburger.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<template>
<Button
v-show="workspaceState.focusMode"
class="comfy-menu-hamburger"
icon="pi pi-bars"
severity="secondary"
text
size="large"
@click="exitFocusMode"
/>
</template>

<script setup lang="ts">
import Button from 'primevue/button'
import { useWorkspaceStore } from '@/stores/workspaceStateStore'
import { watchEffect } from 'vue'
import { app } from '@/scripts/app'
import { useSettingStore } from '@/stores/settingStore'

const workspaceState = useWorkspaceStore()
const settingStore = useSettingStore()
const exitFocusMode = () => {
workspaceState.focusMode = false
}

watchEffect(() => {
if (settingStore.get('Comfy.UseNewMenu') !== 'Disabled') {
return
}
if (workspaceState.focusMode) {
app.ui.menuContainer.style.display = 'none'
} else {
app.ui.menuContainer.style.display = 'block'
}
})
</script>

<style scoped>
.comfy-menu-hamburger {
pointer-events: auto;
position: fixed;
top: 0px;
right: 0px;
z-index: 9999;
}
</style>
4 changes: 3 additions & 1 deletion src/components/graph/GraphCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ const workspaceStore = useWorkspaceStore()
const canvasStore = useCanvasStore()
const modelToNodeStore = useModelToNodeStore()
const betaMenuEnabled = computed(
() => settingStore.get('Comfy.UseNewMenu') !== 'Disabled'
() =>
settingStore.get('Comfy.UseNewMenu') !== 'Disabled' &&
!workspaceStore.focusMode
)
const canvasMenuEnabled = computed(() =>
settingStore.get('Comfy.Graph.CanvasMenu')
Expand Down
6 changes: 5 additions & 1 deletion src/components/topbar/TopMenubar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ import { computed, onMounted, provide, ref } from 'vue'
import { useSettingStore } from '@/stores/settingStore'
import { app } from '@/scripts/app'
import { useEventBus } from '@vueuse/core'
import { useWorkspaceStore } from '@/stores/workspaceStateStore'

const workspaceState = useWorkspaceStore()
const settingStore = useSettingStore()
const workflowTabsPosition = computed(() =>
settingStore.get('Comfy.Workflow.WorkflowTabsPosition')
)
const betaMenuEnabled = computed(
() => settingStore.get('Comfy.UseNewMenu') !== 'Disabled'
() =>
settingStore.get('Comfy.UseNewMenu') !== 'Disabled' &&
!workspaceState.focusMode
)
const teleportTarget = computed(() =>
settingStore.get('Comfy.UseNewMenu') === 'Top'
Expand Down
17 changes: 2 additions & 15 deletions src/scripts/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TaskItem } from '@/types/apiTypes'
import { showSettingsDialog } from '@/services/dialogService'
import { useSettingStore } from '@/stores/settingStore'
import { useCommandStore } from '@/stores/commandStore'
import { useWorkspaceStore } from '@/stores/workspaceStateStore'

export const ComfyDialog = _ComfyDialog

Expand Down Expand Up @@ -350,7 +351,6 @@ export class ComfyUI {
autoQueueMode: string
graphHasChanged: boolean
autoQueueEnabled: boolean
menuHamburger: HTMLDivElement
menuContainer: HTMLDivElement
queueSize: Element
restoreMenuPosition: () => void
Expand Down Expand Up @@ -421,18 +421,6 @@ export class ComfyUI {
}
})

this.menuHamburger = $el(
'div.comfy-menu-hamburger',
{
parent: containerElement,
onclick: () => {
this.menuContainer.style.display = 'block'
this.menuHamburger.style.display = 'none'
}
},
[$el('div'), $el('div'), $el('div')]
) as HTMLDivElement

this.menuContainer = $el('div.comfy-menu', { parent: containerElement }, [
$el(
'div.drag-handle.comfy-menu-header',
Expand All @@ -455,8 +443,7 @@ export class ComfyUI {
$el('button.comfy-close-menu-btn', {
textContent: '\u00d7',
onclick: () => {
this.menuContainer.style.display = 'none'
this.menuHamburger.style.display = 'flex'
useWorkspaceStore().focusMode = true
}
})
])
Expand Down
10 changes: 10 additions & 0 deletions src/stores/commandStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useWorkflowStore } from './workflowStore'
import { type KeybindingImpl, useKeybindingStore } from './keybindingStore'
import { useBottomPanelStore } from './workspace/bottomPanelStore'
import { LGraphNode } from '@comfyorg/litegraph'
import { useWorkspaceStore } from './workspaceStateStore'

export interface ComfyCommand {
id: string
Expand Down Expand Up @@ -467,6 +468,15 @@ export const useCommandStore = defineStore('command', () => {
function: () => {
useBottomPanelStore().toggleBottomPanel()
}
},
{
id: 'Workspace.ToggleFocusMode',
icon: 'pi pi-eye',
label: 'Toggle Focus Mode',
versionAdded: '1.3.27',
function: () => {
useWorkspaceStore().toggleFocusMode()
}
}
]

Expand Down
6 changes: 6 additions & 0 deletions src/stores/coreKeybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,11 @@ export const CORE_KEYBINDINGS: Keybinding[] = [
ctrl: true
},
commandId: 'Workspace.ToggleBottomPanelTab.integrated-terminal'
},
{
combo: {
key: 'f'
},
commandId: 'Workspace.ToggleFocusMode'
}
]
9 changes: 9 additions & 0 deletions src/stores/workspaceStateStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { useSettingStore } from './settingStore'
export const useWorkspaceStore = defineStore('workspace', () => {
const spinner = ref(false)
const shiftDown = ref(false)
/**
* Whether the workspace is in focus mode.
* When in focus mode, only the graph editor is visible.
*/
const focusMode = ref(false)

const toast = computed<ToastManager>(() => useToastStore())
const queueSettings = computed(() => useQueueSettingsStore())
Expand Down Expand Up @@ -52,6 +57,10 @@ export const useWorkspaceStore = defineStore('workspace', () => {
return {
spinner,
shiftDown,
focusMode,
toggleFocusMode: () => {
focusMode.value = !focusMode.value
},
toast,
queueSettings,
command,
Expand Down
3 changes: 2 additions & 1 deletion src/views/GraphView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
<GlobalToast />
<UnloadWindowConfirmDialog />
<BrowserTabTitle />
<MenuHamburger />
</template>

<script setup lang="ts">
import GraphCanvas from '@/components/graph/GraphCanvas.vue'

import MenuHamburger from '@/components/MenuHamburger.vue'
import { computed, onMounted, onBeforeUnmount, watch, watchEffect } from 'vue'
import { app } from '@/scripts/app'
import { useSettingStore } from '@/stores/settingStore'
Expand Down
4 changes: 3 additions & 1 deletion tests-ui/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ module.exports = async function () {
return {
useWorkspaceStore: () => ({
shiftDown: false,
spinner: false
spinner: false,
focusMode: false,
toggleFocusMode: jest.fn()
})
}
})
Expand Down