Extend welcome screen button click area to labels

Closes #738
This commit is contained in:
Keavon Chambers
2022-08-08 01:29:23 -07:00
parent 45a1e144a8
commit 765b648704
10 changed files with 78 additions and 47 deletions
@@ -41,6 +41,8 @@ pub struct PopoverButton {
pub struct TextButton { pub struct TextButton {
pub label: String, pub label: String,
pub icon: Option<String>,
pub emphasized: bool, pub emphasized: bool,
#[serde(rename = "minWidth")] #[serde(rename = "minWidth")]
@@ -105,7 +105,6 @@
} }
.user-input-label { .user-input-label {
margin: 0;
margin-left: 16px; margin-left: 16px;
} }
@@ -7,6 +7,7 @@ export interface TextButtonWidget {
props: { props: {
kind: "TextButton"; kind: "TextButton";
label: string; label: string;
icon?: string;
emphasized?: boolean; emphasized?: boolean;
minWidth?: number; minWidth?: number;
disabled?: boolean; disabled?: boolean;
@@ -8,12 +8,14 @@
:style="minWidth > 0 ? `min-width: ${minWidth}px` : ''" :style="minWidth > 0 ? `min-width: ${minWidth}px` : ''"
@click="(e: MouseEvent) => action(e)" @click="(e: MouseEvent) => action(e)"
> >
<IconLabel v-if="icon" :icon="icon" />
<TextLabel>{{ label }}</TextLabel> <TextLabel>{{ label }}</TextLabel>
</button> </button>
</template> </template>
<style lang="scss"> <style lang="scss">
.text-button { .text-button {
display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
flex: 0 0 auto; flex: 0 0 auto;
@@ -52,17 +54,26 @@
& + .text-button { & + .text-button {
margin-left: 8px; margin-left: 8px;
} }
.icon-label {
position: relative;
left: -4px;
}
} }
</style> </style>
<script lang="ts"> <script lang="ts">
import { defineComponent, PropType } from "vue"; import { defineComponent, PropType } from "vue";
import { IconName } from "@/utility-functions/icons";
import IconLabel from "@/components/widgets/labels/IconLabel.vue";
import TextLabel from "@/components/widgets/labels/TextLabel.vue"; import TextLabel from "@/components/widgets/labels/TextLabel.vue";
export default defineComponent({ export default defineComponent({
props: { props: {
label: { type: String as PropType<string>, required: true }, label: { type: String as PropType<string>, required: true },
icon: { type: String as PropType<IconName | undefined>, required: false },
emphasized: { type: Boolean as PropType<boolean>, default: false }, emphasized: { type: Boolean as PropType<boolean>, default: false },
minWidth: { type: Number as PropType<number>, default: 0 }, minWidth: { type: Number as PropType<number>, default: 0 },
disabled: { type: Boolean as PropType<boolean>, default: false }, disabled: { type: Boolean as PropType<boolean>, default: false },
@@ -70,6 +81,9 @@ export default defineComponent({
// Callbacks // Callbacks
action: { type: Function as PropType<(e: MouseEvent) => void>, required: true }, action: { type: Function as PropType<(e: MouseEvent) => void>, required: true },
}, },
components: { TextLabel }, components: {
IconLabel,
TextLabel,
},
}); });
</script> </script>
@@ -72,15 +72,18 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from "vue"; import { defineComponent } from "vue";
import { operatingSystemIsMac } from "@/utility-functions/platform";
import { MenuEntry, UpdateMenuBarLayout, MenuListEntry } from "@/wasm-communication/messages"; import { MenuEntry, UpdateMenuBarLayout, MenuListEntry } from "@/wasm-communication/messages";
import MenuList from "@/components/floating-menus/MenuList.vue"; import MenuList from "@/components/floating-menus/MenuList.vue";
import IconLabel from "@/components/widgets/labels/IconLabel.vue"; import IconLabel from "@/components/widgets/labels/IconLabel.vue";
// TODO: Apparently, Safari does not support the Keyboard.lock() API but does relax its authority over certain keyboard shortcuts in fullscreen mode, which we should handle correctly
const controlOrCommand = operatingSystemIsMac() ? "KeyCommand" : "KeyControl";
const LOCK_REQUIRING_SHORTCUTS = [ const LOCK_REQUIRING_SHORTCUTS = [
["KeyControl", "KeyN"], [controlOrCommand, "KeyN"],
["KeyControl", "KeyShift", "KeyT"], [controlOrCommand, "KeyShift", "KeyT"],
["KeyControl", "KeyW"], [controlOrCommand, "KeyW"],
]; ];
type FrontendMenuColumn = { type FrontendMenuColumn = {
@@ -23,7 +23,6 @@
.user-input-label { .user-input-label {
flex: 0 0 auto; flex: 0 0 auto;
height: 100%; height: 100%;
margin: 0 8px;
align-items: center; align-items: center;
white-space: nowrap; white-space: nowrap;
@@ -188,10 +187,15 @@ export default defineComponent({
return Boolean(this.$slots.default); return Boolean(this.$slots.default);
}, },
keyboardLockInfoMessage(): string { keyboardLockInfoMessage(): string {
const USE_FULLSCREEN = "This hotkey is reserved by the browser, but becomes available in fullscreen mode"; const RESERVED = "This hotkey is reserved by the browser. ";
const SWITCH_BROWSER = "This hotkey is reserved by the browser, but becomes available in Chrome, Edge, and Opera which support the Keyboard.lock() API"; const USE_FULLSCREEN = "It is made available in fullscreen mode.";
const USE_SECURE_CTX = "It is made available in fullscreen mode when this website is served from a secure context (https or localhost).";
const SWITCH_BROWSER = "Use a Chromium-based browser (like Chrome or Edge) in fullscreen mode to directly use the shortcut.";
return this.fullscreen.keyboardLockApiSupported ? USE_FULLSCREEN : SWITCH_BROWSER; if (this.fullscreen.keyboardLockApiSupported) return `${RESERVED} ${USE_FULLSCREEN}`;
if (!("chrome" in window)) return `${RESERVED} ${SWITCH_BROWSER}`;
if (!window.isSecureContext) return `${RESERVED} ${USE_SECURE_CTX}`;
return RESERVED;
}, },
displayKeyboardLockNotice(): boolean { displayKeyboardLockNotice(): boolean {
return this.requiresLock && !this.fullscreen.state.keyboardLocked; return this.requiresLock && !this.fullscreen.state.keyboardLocked;
@@ -34,8 +34,12 @@
font-weight: 700; font-weight: 700;
} }
.user-input-label + .user-input-label { .user-input-label {
margin-left: 0; margin: 0 8px;
& + .user-input-label {
margin-left: 0;
}
} }
} }
} }
@@ -28,26 +28,24 @@
<IconLabel :icon="'GraphiteLogotypeSolid'" /> <IconLabel :icon="'GraphiteLogotypeSolid'" />
</LayoutRow> </LayoutRow>
<LayoutRow class="actions"> <LayoutRow class="actions">
<LayoutCol> <table>
<IconButton :action="() => newDocument()" :icon="'File'" :size="24" /> <tr>
<IconButton :action="() => openDocument()" :icon="'Folder'" :size="24" /> <td>
</LayoutCol> <TextButton :label="'New Document:'" :icon="'File'" :action="() => newDocument()" />
<LayoutCol> </td>
<Separator :type="'Related'" /> <td>
<Separator :type="'Related'" /> <UserInputLabel :inputKeys="[[...platformModifiers(true), 'KeyN']]" />
</LayoutCol> </td>
<LayoutCol> </tr>
<TextLabel>New Document:</TextLabel> <tr>
<TextLabel>Open Document:</TextLabel> <td>
</LayoutCol> <TextButton :label="'Open Document:'" :icon="'Folder'" :action="() => openDocument()" />
<LayoutCol> </td>
<Separator :type="'Unrelated'" /> <td>
<Separator :type="'Unrelated'" /> <UserInputLabel :inputKeys="[[...platformModifiers(false), 'KeyO']]" />
</LayoutCol> </td>
<LayoutCol> </tr>
<UserInputLabel :inputKeys="[[controlOrCommandKey(), 'KeyN']]" /> </table>
<UserInputLabel :inputKeys="[[controlOrCommandKey(), 'KeyO']]" />
</LayoutCol>
</LayoutRow> </LayoutRow>
</LayoutCol> </LayoutCol>
</LayoutCol> </LayoutCol>
@@ -191,19 +189,16 @@
} }
.actions { .actions {
> div { table {
gap: 8px; border-spacing: 8px;
margin: -8px;
> * { td {
height: 24px; padding: 0;
} }
.text-label { .text-button:not(:hover) {
line-height: 24px; background: none;
}
.user-input-label {
margin: 0;
} }
} }
} }
@@ -226,18 +221,19 @@ import NodeGraph from "@/components/panels/NodeGraph.vue";
import Properties from "@/components/panels/Properties.vue"; import Properties from "@/components/panels/Properties.vue";
import IconButton from "@/components/widgets/buttons/IconButton.vue"; import IconButton from "@/components/widgets/buttons/IconButton.vue";
import PopoverButton from "@/components/widgets/buttons/PopoverButton.vue"; import PopoverButton from "@/components/widgets/buttons/PopoverButton.vue";
import TextButton from "@/components/widgets/buttons/TextButton.vue";
import IconLabel from "@/components/widgets/labels/IconLabel.vue"; import IconLabel from "@/components/widgets/labels/IconLabel.vue";
import Separator from "@/components/widgets/labels/Separator.vue";
import TextLabel from "@/components/widgets/labels/TextLabel.vue"; import TextLabel from "@/components/widgets/labels/TextLabel.vue";
import UserInputLabel from "@/components/widgets/labels/UserInputLabel.vue"; import UserInputLabel from "@/components/widgets/labels/UserInputLabel.vue";
const panelComponents = { const panelComponents = {
Document, Document,
Properties, IconButton,
LayerTree, LayerTree,
NodeGraph, NodeGraph,
IconButton,
PopoverButton, PopoverButton,
Properties,
TextButton,
}; };
type PanelTypes = keyof typeof panelComponents; type PanelTypes = keyof typeof panelComponents;
@@ -259,9 +255,14 @@ export default defineComponent({
openDocument() { openDocument() {
this.editor.instance.document_open(); this.editor.instance.document_open();
}, },
controlOrCommandKey() { platformModifiers(reservedKey: boolean) {
// TODO: Remove this by properly feeding these keys from a layout provided by the backend // TODO: Remove this by properly feeding these keys from a layout provided by the backend
return operatingSystemIsMac() ? "KeyCommand" : "KeyControl";
if (operatingSystemIsMac()) {
return reservedKey ? ["KeyControl", "KeyCommand"] : ["KeyCommand"]; // TODO: Change Mac from Control+Command to Alt+Command when we can read Alt+letter modifiers
}
return reservedKey ? ["KeyControl", "KeyAlt"] : ["KeyControl"];
}, },
}, },
components: { components: {
@@ -270,7 +271,6 @@ export default defineComponent({
IconLabel, IconLabel,
TextLabel, TextLabel,
UserInputLabel, UserInputLabel,
Separator,
...panelComponents, ...panelComponents,
}, },
}); });
@@ -549,6 +549,8 @@ export class TextAreaInput extends WidgetProps {
export class TextButton extends WidgetProps { export class TextButton extends WidgetProps {
label!: string; label!: string;
icon!: string | undefined;
emphasized!: boolean; emphasized!: boolean;
minWidth!: number; minWidth!: number;
+2
View File
@@ -1,3 +1,5 @@
#![doc = include_str!("../README.md")]
pub mod editor_api; pub mod editor_api;
pub mod helpers; pub mod helpers;