Skip to content

Commit 9885439

Browse files
ert78gbmondalaci
authored andcommitted
feat(ui): macro ui improvement (#473)
* Remove the "Input the text you want to type with this macro action." sentence from the type text macro action. * Move pointer and Scroll enhancement * remove the extra vertical space above the mouse buttons * macro delay enhancement * not allow user select on a few elements * fill the macro, keymap name the all space in the header
1 parent bd49e26 commit 9885439

17 files changed

+139
-46
lines changed

.stylelintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
"unit-case": "lower",
2828
"unit-no-unknown": true,
29-
"unit-whitelist": ["px", "%", "deg", "ms", "em", "rem", "vh", "vv", "s"],
29+
"unit-whitelist": ["px", "%", "deg", "ms", "em", "rem", "vh", "vv", "s", "ch"],
3030

3131
"value-list-comma-space-after": "always-single-line",
3232
"value-list-comma-space-before": "never",

packages/uhk-web/src/app/components/keymap/header/keymap-header.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ <h1 class="col-xs-12 pane-title">
77
type="text"
88
(change)="editKeymapName($event.target.value)"
99
(keyup.enter)="name.blur()"
10+
(keyup)="calculateHeaderTextWidth($event.target.value)"
1011
/> keymap
1112
(<input #abbr cancelable
1213
class="keymap__abbrev pane-title__abbrev"

packages/uhk-web/src/app/components/keymap/header/keymap-header.component.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Component,
44
ElementRef,
55
EventEmitter,
6+
HostListener,
67
Input,
78
OnChanges,
89
Output,
@@ -16,6 +17,7 @@ import { Store } from '@ngrx/store';
1617

1718
import { AppState } from '../../../store';
1819
import { KeymapActions } from '../../../store/actions';
20+
import * as util from '../../../util';
1921

2022
const DEFAULT_TRASH_TITLE = '<span class="text-nowrap">Delete keymap</span>';
2123

@@ -50,6 +52,11 @@ export class KeymapHeaderComponent implements OnChanges {
5052
}
5153
}
5254

55+
@HostListener('window:resize')
56+
windowResize(): void {
57+
this.calculateHeaderTextWidth(this.keymap.name);
58+
}
59+
5360
setDefault() {
5461
if (!this.keymap.isDefault) {
5562
this.store.dispatch(KeymapActions.setDefault(this.keymap.abbreviation));
@@ -103,8 +110,16 @@ export class KeymapHeaderComponent implements OnChanges {
103110
this.downloadClick.emit();
104111
}
105112

113+
calculateHeaderTextWidth(text): void {
114+
const htmlInput = this.keymapName.nativeElement as HTMLInputElement;
115+
const maxWidth = htmlInput.parentElement.offsetWidth - 530;
116+
const textWidth = util.getContentWidth(window.getComputedStyle(htmlInput), text);
117+
this.renderer.setStyle(htmlInput, 'width', Math.min(maxWidth, textWidth) + 'px');
118+
}
119+
106120
private setName(): void {
107121
this.renderer.setProperty(this.keymapName.nativeElement, 'value', this.keymap.name);
122+
this.calculateHeaderTextWidth(this.keymap.name);
108123
}
109124

110125
private setAbbreviation() {

packages/uhk-web/src/app/components/macro/action-editor/macro-action-editor.component.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
a {
2020
border-top-right-radius: 0;
2121
border-bottom-right-radius: 0;
22+
user-select: none;
2223

2324
&.selected {
2425
font-style: italic;
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
<div class="macro-delay">
22
<div class="row">
33
<div class="col-xs-12">
4-
<h4>Enter delay in seconds</h4>
4+
<h4>Delay</h4>
55
</div>
66
</div>
77
<div class="row">
8-
<div class="col-xs-4">
9-
<input #macroDelayInput
10-
type="number"
11-
min="0"
12-
max="1000"
13-
step="0.1"
14-
placeholder="Delay amount"
15-
class="form-control"
16-
[value]="delay"
17-
(change)="setDelay(macroDelayInput.value)">
8+
<div class="col-xs-12">
9+
<div class="form-group">
10+
<input #macroDelayInput
11+
type="number"
12+
min="0"
13+
max="1000"
14+
step="0.1"
15+
placeholder="Delay amount"
16+
class="form-control"
17+
[ngModel]="delay"
18+
(ngModelChange)="setDelay(macroDelayInput.value)">
19+
<label>seconds</label>
20+
</div>
1821
</div>
1922
</div>
2023
<div class="row macro-delay__presets">
2124
<div class="col-xs-12">
22-
<h6>Choose a preset</h6>
23-
<button *ngFor="let delay of presets" class="btn btn-sm btn-default" (click)="setDelay(delay)">{{delay}}s</button>
25+
<h6>Choose a preset</h6>
26+
<button *ngFor="let delay of presets" class="btn btn-sm btn-default" (click)="setDelay(delay)">{{delay}}s
27+
</button>
2428
</div>
2529
</div>
2630
</div>

packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@
1414
}
1515
}
1616
}
17+
18+
.form-group {
19+
margin-bottom: 0;
20+
}
21+
22+
.form-control {
23+
width: 16ch;
24+
display: inline-block;
25+
}

packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,31 @@ export class MacroDelayTabComponent extends MacroBaseComponent implements OnInit
2323
@Input() macroAction: DelayMacroAction;
2424
@ViewChild('macroDelayInput') input: ElementRef;
2525

26-
delay: number;
2726
presets: number[] = [0.3, 0.5, 0.8, 1, 2, 3, 4, 5];
2827

28+
get delay(): number {
29+
return this._delay;
30+
}
31+
32+
set delay(value: number) {
33+
this._delay = value;
34+
this.validate();
35+
}
36+
37+
private _delay: number;
38+
2939
constructor() { super(); }
3040

3141
ngOnInit() {
3242
if (!this.macroAction) {
3343
this.macroAction = new DelayMacroAction();
3444
}
3545
this.delay = this.macroAction.delay > 0 ? this.macroAction.delay / 1000 : INITIAL_DELAY;
36-
this.validate(); // initial validation as it has defaults
3746
}
3847

3948
setDelay(value: number): void {
40-
this.delay = value;
41-
this.macroAction.delay = this.delay * 1000;
49+
this._delay = value;
50+
this.macroAction.delay = this._delay * 1000;
4251
this.validate();
4352
}
4453

packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.html

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,68 @@
3636
<div class="col-xs-9 macro-mouse__actions" [ngSwitch]="activeTab">
3737
<div #tab *ngSwitchCase="TabName.Move">
3838
<h4>Move pointer</h4>
39-
<p>Use negative values to move down or left from current position.</p>
4039
<div class="form-horizontal">
4140
<div class="form-group">
42-
<label for="move-mouse-x">X</label>
43-
<input id="move-mouse-x" type="number" class="form-control" [(ngModel)]="macroAction['x']" (keyup)="validate()"> pixels
41+
<label for="move-mouse-x">X:</label>
42+
<input id="move-mouse-x"
43+
type="number"
44+
class="form-control"
45+
[(ngModel)]="macroAction['x']"
46+
(keyup)="validate()"
47+
min="-9999"
48+
max="9999"
49+
maxlength="4"> pixels
4450
</div>
4551
<div class="form-group">
46-
<label for="move-mouse-y">Y</label>
47-
<input id="move-mouse-y" type="number" class="form-control" [(ngModel)]="macroAction['y']" (keyup)="validate()"> pixels
52+
<label for="move-mouse-y">Y:</label>
53+
<input id="move-mouse-y"
54+
type="number"
55+
class="form-control"
56+
[(ngModel)]="macroAction['y']"
57+
(keyup)="validate()"
58+
min="-9999"
59+
max="9999"
60+
maxlength="4"> pixels
4861
</div>
4962
</div>
5063
</div>
5164
<div #tab *ngSwitchCase="TabName.Scroll">
5265
<h4>Scroll</h4>
53-
<p>Use negative values to move down or left from current position.</p>
5466
<div class="form-horizontal">
5567
<div class="form-group">
56-
<label for="scroll-mouse-x">X</label>
57-
<input id="scroll-mouse-x" type="number" class="form-control" [(ngModel)]="macroAction['x']" (keyup)="validate()"> pixels
68+
<label for="scroll-mouse-x">X:</label>
69+
<input id="scroll-mouse-x"
70+
type="number"
71+
class="form-control"
72+
[(ngModel)]="macroAction['x']"
73+
(keyup)="validate()"
74+
min="-9999"
75+
max="9999"
76+
maxlength="4"> pixels
5877
</div>
5978
<div class="form-group">
60-
<label for="scroll-mouse-y">Y</label>
61-
<input id="scroll-mouse-y" type="number" class="form-control" [(ngModel)]="macroAction['y']" (keyup)="validate()"> pixels
79+
<label for="scroll-mouse-y">Y:</label>
80+
<input id="scroll-mouse-y"
81+
type="number"
82+
class="form-control"
83+
[(ngModel)]="macroAction['y']"
84+
(keyup)="validate()"
85+
min="-9999"
86+
max="9999"
87+
maxlength="4"> pixels
6288
</div>
6389
</div>
6490
</div>
6591
<div #tab *ngIf="activeTab === TabName.Click || activeTab === TabName.Hold || activeTab === TabName.Release">
6692
<h4 *ngIf="activeTab === TabName.Click">Click mouse button</h4>
6793
<h4 *ngIf="activeTab === TabName.Hold">Hold mouse button</h4>
6894
<h4 *ngIf="activeTab === TabName.Release">Release mouse button</h4>
69-
<div class="btn-group macro-mouse__buttons">
95+
<div class="btn-group">
7096
<button *ngFor="let buttonLabel of buttonLabels; let buttonIndex = index"
7197
class="btn btn-default"
7298
[class.btn-primary]="hasButton(buttonIndex)"
73-
(click)="setMouseClick(buttonIndex)">{{buttonLabel}}</button>
99+
(click)="setMouseClick(buttonIndex)">{{buttonLabel}}
100+
</button>
74101
</div>
75102
</div>
76103
</div>

packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.scss

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
padding-left: 3rem;
1616
padding-bottom: 1rem;
1717
}
18-
19-
&__buttons {
20-
margin-top: 3rem;
21-
margin-bottom: 1rem;
22-
}
2318
}
2419

2520
.fa {
@@ -38,6 +33,6 @@
3833

3934
.form-control {
4035
display: inline-block;
41-
width: 60%;
36+
width: 10ch;
4237
}
4338
}

packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum TabName {
2626
'../../macro-action-editor.component.scss',
2727
'./macro-mouse.component.scss'
2828
],
29-
host: { 'class': 'macro__mouse' }
29+
host: {'class': 'macro__mouse'}
3030
})
3131
export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit {
3232
@Input() macroAction: MouseMacroAction;
@@ -130,14 +130,14 @@ export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit
130130
switch (this.macroAction.constructor) {
131131
case MoveMouseMacroAction:
132132
case ScrollMouseMacroAction:
133-
const { x, y } = this.macroAction as MoveMouseMacroAction;
134-
return x !== undefined && x !== null && y !== undefined && y !== null;
133+
const {x, y} = this.macroAction as MoveMouseMacroAction;
134+
return x !== undefined && x !== null && y !== undefined && y !== null &&
135+
(x !== 0 || y !== 0) && x < 10000 && x > -10000 && y < 10000 && y > -10000;
135136
case MouseButtonMacroAction:
136-
const { mouseButtonsMask } = this.macroAction as MouseButtonMacroAction;
137+
const {mouseButtonsMask} = this.macroAction as MouseButtonMacroAction;
137138
return !!mouseButtonsMask;
138139
default:
139140
return true;
140141
}
141-
}
142-
142+
};
143143
}

0 commit comments

Comments
 (0)