Skip to content

Commit 765b648

Browse files
committed
Extend welcome screen button click area to labels
Closes #738
1 parent 45a1e14 commit 765b648

File tree

10 files changed

+78
-47
lines changed

10 files changed

+78
-47
lines changed

editor/src/messages/layout/utility_types/widgets/button_widgets.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub struct PopoverButton {
4141
pub struct TextButton {
4242
pub label: String,
4343

44+
pub icon: Option<String>,
45+
4446
pub emphasized: bool,
4547

4648
#[serde(rename = "minWidth")]

frontend/src/components/floating-menus/MenuList.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
}
106106
107107
.user-input-label {
108-
margin: 0;
109108
margin-left: 16px;
110109
}
111110

frontend/src/components/widgets/buttons/TextButton.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface TextButtonWidget {
77
props: {
88
kind: "TextButton";
99
label: string;
10+
icon?: string;
1011
emphasized?: boolean;
1112
minWidth?: number;
1213
disabled?: boolean;

frontend/src/components/widgets/buttons/TextButton.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
:style="minWidth > 0 ? `min-width: ${minWidth}px` : ''"
99
@click="(e: MouseEvent) => action(e)"
1010
>
11+
<IconLabel v-if="icon" :icon="icon" />
1112
<TextLabel>{{ label }}</TextLabel>
1213
</button>
1314
</template>
1415

1516
<style lang="scss">
1617
.text-button {
18+
display: flex;
1719
justify-content: center;
1820
align-items: center;
1921
flex: 0 0 auto;
@@ -52,24 +54,36 @@
5254
& + .text-button {
5355
margin-left: 8px;
5456
}
57+
58+
.icon-label {
59+
position: relative;
60+
left: -4px;
61+
}
5562
}
5663
</style>
5764

5865
<script lang="ts">
5966
import { defineComponent, PropType } from "vue";
6067
68+
import { IconName } from "@/utility-functions/icons";
69+
70+
import IconLabel from "@/components/widgets/labels/IconLabel.vue";
6171
import TextLabel from "@/components/widgets/labels/TextLabel.vue";
6272
6373
export default defineComponent({
6474
props: {
6575
label: { type: String as PropType<string>, required: true },
76+
icon: { type: String as PropType<IconName | undefined>, required: false },
6677
emphasized: { type: Boolean as PropType<boolean>, default: false },
6778
minWidth: { type: Number as PropType<number>, default: 0 },
6879
disabled: { type: Boolean as PropType<boolean>, default: false },
6980
7081
// Callbacks
7182
action: { type: Function as PropType<(e: MouseEvent) => void>, required: true },
7283
},
73-
components: { TextLabel },
84+
components: {
85+
IconLabel,
86+
TextLabel,
87+
},
7488
});
7589
</script>

frontend/src/components/widgets/inputs/MenuBarInput.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,18 @@
7272
<script lang="ts">
7373
import { defineComponent } from "vue";
7474
75+
import { operatingSystemIsMac } from "@/utility-functions/platform";
7576
import { MenuEntry, UpdateMenuBarLayout, MenuListEntry } from "@/wasm-communication/messages";
7677
7778
import MenuList from "@/components/floating-menus/MenuList.vue";
7879
import IconLabel from "@/components/widgets/labels/IconLabel.vue";
7980
81+
// 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
82+
const controlOrCommand = operatingSystemIsMac() ? "KeyCommand" : "KeyControl";
8083
const LOCK_REQUIRING_SHORTCUTS = [
81-
["KeyControl", "KeyN"],
82-
["KeyControl", "KeyShift", "KeyT"],
83-
["KeyControl", "KeyW"],
84+
[controlOrCommand, "KeyN"],
85+
[controlOrCommand, "KeyShift", "KeyT"],
86+
[controlOrCommand, "KeyW"],
8487
];
8588
8689
type FrontendMenuColumn = {

frontend/src/components/widgets/labels/UserInputLabel.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
.user-input-label {
2424
flex: 0 0 auto;
2525
height: 100%;
26-
margin: 0 8px;
2726
align-items: center;
2827
white-space: nowrap;
2928
@@ -188,10 +187,15 @@ export default defineComponent({
188187
return Boolean(this.$slots.default);
189188
},
190189
keyboardLockInfoMessage(): string {
191-
const USE_FULLSCREEN = "This hotkey is reserved by the browser, but becomes available in fullscreen mode";
192-
const SWITCH_BROWSER = "This hotkey is reserved by the browser, but becomes available in Chrome, Edge, and Opera which support the Keyboard.lock() API";
190+
const RESERVED = "This hotkey is reserved by the browser. ";
191+
const USE_FULLSCREEN = "It is made available in fullscreen mode.";
192+
const USE_SECURE_CTX = "It is made available in fullscreen mode when this website is served from a secure context (https or localhost).";
193+
const SWITCH_BROWSER = "Use a Chromium-based browser (like Chrome or Edge) in fullscreen mode to directly use the shortcut.";
193194
194-
return this.fullscreen.keyboardLockApiSupported ? USE_FULLSCREEN : SWITCH_BROWSER;
195+
if (this.fullscreen.keyboardLockApiSupported) return `${RESERVED} ${USE_FULLSCREEN}`;
196+
if (!("chrome" in window)) return `${RESERVED} ${SWITCH_BROWSER}`;
197+
if (!window.isSecureContext) return `${RESERVED} ${USE_SECURE_CTX}`;
198+
return RESERVED;
195199
},
196200
displayKeyboardLockNotice(): boolean {
197201
return this.requiresLock && !this.fullscreen.state.keyboardLocked;

frontend/src/components/window/status-bar/StatusBar.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@
3434
font-weight: 700;
3535
}
3636
37-
.user-input-label + .user-input-label {
38-
margin-left: 0;
37+
.user-input-label {
38+
margin: 0 8px;
39+
40+
& + .user-input-label {
41+
margin-left: 0;
42+
}
3943
}
4044
}
4145
}

frontend/src/components/window/workspace/Panel.vue

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,24 @@
2828
<IconLabel :icon="'GraphiteLogotypeSolid'" />
2929
</LayoutRow>
3030
<LayoutRow class="actions">
31-
<LayoutCol>
32-
<IconButton :action="() => newDocument()" :icon="'File'" :size="24" />
33-
<IconButton :action="() => openDocument()" :icon="'Folder'" :size="24" />
34-
</LayoutCol>
35-
<LayoutCol>
36-
<Separator :type="'Related'" />
37-
<Separator :type="'Related'" />
38-
</LayoutCol>
39-
<LayoutCol>
40-
<TextLabel>New Document:</TextLabel>
41-
<TextLabel>Open Document:</TextLabel>
42-
</LayoutCol>
43-
<LayoutCol>
44-
<Separator :type="'Unrelated'" />
45-
<Separator :type="'Unrelated'" />
46-
</LayoutCol>
47-
<LayoutCol>
48-
<UserInputLabel :inputKeys="[[controlOrCommandKey(), 'KeyN']]" />
49-
<UserInputLabel :inputKeys="[[controlOrCommandKey(), 'KeyO']]" />
50-
</LayoutCol>
31+
<table>
32+
<tr>
33+
<td>
34+
<TextButton :label="'New Document:'" :icon="'File'" :action="() => newDocument()" />
35+
</td>
36+
<td>
37+
<UserInputLabel :inputKeys="[[...platformModifiers(true), 'KeyN']]" />
38+
</td>
39+
</tr>
40+
<tr>
41+
<td>
42+
<TextButton :label="'Open Document:'" :icon="'Folder'" :action="() => openDocument()" />
43+
</td>
44+
<td>
45+
<UserInputLabel :inputKeys="[[...platformModifiers(false), 'KeyO']]" />
46+
</td>
47+
</tr>
48+
</table>
5149
</LayoutRow>
5250
</LayoutCol>
5351
</LayoutCol>
@@ -191,19 +189,16 @@
191189
}
192190
193191
.actions {
194-
> div {
195-
gap: 8px;
192+
table {
193+
border-spacing: 8px;
194+
margin: -8px;
196195
197-
> * {
198-
height: 24px;
196+
td {
197+
padding: 0;
199198
}
200199
201-
.text-label {
202-
line-height: 24px;
203-
}
204-
205-
.user-input-label {
206-
margin: 0;
200+
.text-button:not(:hover) {
201+
background: none;
207202
}
208203
}
209204
}
@@ -226,18 +221,19 @@ import NodeGraph from "@/components/panels/NodeGraph.vue";
226221
import Properties from "@/components/panels/Properties.vue";
227222
import IconButton from "@/components/widgets/buttons/IconButton.vue";
228223
import PopoverButton from "@/components/widgets/buttons/PopoverButton.vue";
224+
import TextButton from "@/components/widgets/buttons/TextButton.vue";
229225
import IconLabel from "@/components/widgets/labels/IconLabel.vue";
230-
import Separator from "@/components/widgets/labels/Separator.vue";
231226
import TextLabel from "@/components/widgets/labels/TextLabel.vue";
232227
import UserInputLabel from "@/components/widgets/labels/UserInputLabel.vue";
233228
234229
const panelComponents = {
235230
Document,
236-
Properties,
231+
IconButton,
237232
LayerTree,
238233
NodeGraph,
239-
IconButton,
240234
PopoverButton,
235+
Properties,
236+
TextButton,
241237
};
242238
type PanelTypes = keyof typeof panelComponents;
243239
@@ -259,9 +255,14 @@ export default defineComponent({
259255
openDocument() {
260256
this.editor.instance.document_open();
261257
},
262-
controlOrCommandKey() {
258+
platformModifiers(reservedKey: boolean) {
263259
// TODO: Remove this by properly feeding these keys from a layout provided by the backend
264-
return operatingSystemIsMac() ? "KeyCommand" : "KeyControl";
260+
261+
if (operatingSystemIsMac()) {
262+
return reservedKey ? ["KeyControl", "KeyCommand"] : ["KeyCommand"]; // TODO: Change Mac from Control+Command to Alt+Command when we can read Alt+letter modifiers
263+
}
264+
265+
return reservedKey ? ["KeyControl", "KeyAlt"] : ["KeyControl"];
265266
},
266267
},
267268
components: {
@@ -270,7 +271,6 @@ export default defineComponent({
270271
IconLabel,
271272
TextLabel,
272273
UserInputLabel,
273-
Separator,
274274
...panelComponents,
275275
},
276276
});

frontend/src/wasm-communication/messages.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ export class TextAreaInput extends WidgetProps {
549549
export class TextButton extends WidgetProps {
550550
label!: string;
551551

552+
icon!: string | undefined;
553+
552554
emphasized!: boolean;
553555

554556
minWidth!: number;

frontend/wasm/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![doc = include_str!("../README.md")]
2+
13
pub mod editor_api;
24
pub mod helpers;
35

0 commit comments

Comments
 (0)