Skip to content

Commit 4c6fc1d

Browse files
committed
Fix inconsistent icon apparent size
1 parent 23f8b32 commit 4c6fc1d

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

app/src/ui/octicons/octicon.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class Octicon extends React.Component<IOcticonProps, {}> {
4545
const { symbol } = this.props
4646

4747
if (this.isSingleVariant(symbol)) {
48-
return this.renderIcon(symbol.p, symbol.h, symbol.w)
48+
return this.renderIcon(symbol.p, symbol.h, symbol.w, symbol.mult ?? 1)
4949
} else {
5050
const height = this.props.height ?? 16
5151
const naturalHeight = this.closestNaturalHeight(
@@ -63,11 +63,21 @@ export class Octicon extends React.Component<IOcticonProps, {}> {
6363
const naturalWidth = scaledSymbol.w
6464
const width = height * (naturalWidth / naturalHeight)
6565

66-
return this.renderIcon(scaledSymbol.p, height, width)
66+
return this.renderIcon(
67+
scaledSymbol.p,
68+
height,
69+
width,
70+
scaledSymbol.mult ?? 1
71+
)
6772
}
6873
}
6974

70-
private renderIcon(paths: string[], height: number, width: number) {
75+
private renderIcon(
76+
paths: string[],
77+
height: number,
78+
width: number,
79+
sizeMultiplier: number
80+
) {
7181
const { title, tooltipDirection } = this.props
7282
const viewBox = `0 0 ${width} ${height}`
7383
const className = classNames('octicon', this.props.className)
@@ -90,8 +100,8 @@ export class Octicon extends React.Component<IOcticonProps, {}> {
90100
viewBox={viewBox}
91101
ref={this.svgRef}
92102
tabIndex={-1}
93-
height={height}
94-
width={width}
103+
height={height * sizeMultiplier}
104+
width={width * sizeMultiplier}
95105
>
96106
{title !== undefined && (
97107
<Tooltip target={this.svgRef} direction={direction}>

app/src/ui/octicons/octicons.generated.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export type OcticonSymbolVariant = {
1212

1313
/** The height of the symbol */
1414
readonly h: number
15+
16+
/** The size multiplier in order to normalize the apparent size (generally between 0 and 1) */
17+
readonly mult?: number
1518
}
1619

1720
export type OcticonSymbolVariants = Record<PropertyKey, OcticonSymbolVariant>
@@ -1739,6 +1742,7 @@ export const fileDiff: OcticonSymbolVariants = {
17391742
],
17401743
h: 16,
17411744
w: 16,
1745+
mult: 0.875,
17421746
},
17431747
'24': {
17441748
p: [
@@ -1747,6 +1751,7 @@ export const fileDiff: OcticonSymbolVariants = {
17471751
],
17481752
h: 24,
17491753
w: 24,
1754+
mult: 0.875,
17501755
},
17511756
}
17521757
export const fileDirectory: OcticonSymbolVariants = {
@@ -1756,13 +1761,15 @@ export const fileDirectory: OcticonSymbolVariants = {
17561761
],
17571762
h: 16,
17581763
w: 16,
1764+
mult: 0.9375,
17591765
},
17601766
'24': {
17611767
p: [
17621768
'M2 4.75C2 3.784 2.784 3 3.75 3h4.971c.58 0 1.12.286 1.447.765l1.404 2.063c.046.069.124.11.207.11h8.471c.966 0 1.75.783 1.75 1.75V19.25A1.75 1.75 0 0 1 20.25 21H3.75A1.75 1.75 0 0 1 2 19.25Zm1.75-.25a.25.25 0 0 0-.25.25v14.5c0 .138.112.25.25.25h16.5a.25.25 0 0 0 .25-.25V7.687a.25.25 0 0 0-.25-.25h-8.471a1.75 1.75 0 0 1-1.447-.765L8.928 4.61a.252.252 0 0 0-.208-.11Z',
17631769
],
17641770
h: 24,
17651771
w: 24,
1772+
mult: 0.9375,
17661773
},
17671774
}
17681775
export const fileDirectoryFill: OcticonSymbolVariants = {
@@ -2171,13 +2178,15 @@ export const globe: OcticonSymbolVariants = {
21712178
],
21722179
h: 16,
21732180
w: 16,
2181+
mult: 0.875,
21742182
},
21752183
'24': {
21762184
p: [
21772185
'M12 1c6.075 0 11 4.925 11 11s-4.925 11-11 11S1 18.075 1 12 5.925 1 12 1Zm3.241 10.5v-.001c-.1-2.708-.992-4.904-1.89-6.452a13.919 13.919 0 0 0-1.304-1.88L12 3.11l-.047.059c-.354.425-.828 1.06-1.304 1.88-.898 1.547-1.79 3.743-1.89 6.451Zm-12.728 0h4.745c.1-3.037 1.1-5.49 2.093-7.204.39-.672.78-1.233 1.119-1.673C6.11 3.329 2.746 7 2.513 11.5Zm18.974 0C21.254 7 17.89 3.329 13.53 2.623c.339.44.729 1.001 1.119 1.673.993 1.714 1.993 4.167 2.093 7.204ZM8.787 13c.182 2.478 1.02 4.5 1.862 5.953.382.661.818 1.29 1.304 1.88l.047.057.047-.059c.354-.425.828-1.06 1.304-1.88.842-1.451 1.679-3.471 1.862-5.951Zm-1.504 0H2.552a9.505 9.505 0 0 0 7.918 8.377 15.773 15.773 0 0 1-1.119-1.673C8.413 18.085 7.47 15.807 7.283 13Zm9.434 0c-.186 2.807-1.13 5.085-2.068 6.704-.39.672-.78 1.233-1.118 1.673A9.506 9.506 0 0 0 21.447 13Z',
21782186
],
21792187
h: 24,
21802188
w: 24,
2189+
mult: 0.875,
21812190
},
21822191
}
21832192
export const goal: OcticonSymbolVariants = {
@@ -2833,6 +2842,7 @@ export const markGithub: OcticonSymbolVariants = {
28332842
],
28342843
h: 16,
28352844
w: 16,
2845+
mult: 0.875,
28362846
},
28372847
}
28382848
export const markdown: OcticonSymbolVariants = {
@@ -4624,6 +4634,7 @@ export const trash: OcticonSymbolVariants = {
46244634
],
46254635
h: 16,
46264636
w: 16,
4637+
mult: 0.9375,
46274638
},
46284639
'24': {
46294640
p: [
@@ -4632,6 +4643,7 @@ export const trash: OcticonSymbolVariants = {
46324643
],
46334644
h: 24,
46344645
w: 24,
4646+
mult: 0.9375,
46354647
},
46364648
}
46374649
export const triangleDown: OcticonSymbolVariants = {

app/src/ui/octicons/stash.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export const stash: OcticonSymbolVariant = {
1313
'1.29 1.485 1.29h9a1.5 1.5 0 0 0 1.5-1.5v-9a1.5 1.5 0 0 0-1.29-1.485v1.442a.216.216 0 0 1 ' +
1414
'.004.043v9a.214.214 0 0 1-.214.214h-9a.216.216 0 0 1-.043-.004H4.015z',
1515
],
16+
mult: 14 / 16,
1617
}

script/generate-octicons.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ interface IOcticonVariant {
3939
p: string[]
4040
h: number
4141
w: number
42+
mult?: number
4243
}
4344

4445
interface IOcticon {
@@ -73,13 +74,31 @@ async function generateIconData(): Promise<ReadonlyArray<IOcticon>> {
7374
p: data.ast.children.map(c => c.attributes.d),
7475
h: parseInt(data.options.height, 10),
7576
w: parseInt(data.options.width, 10),
77+
mult: getSizeMultiplier(name),
78+
}
79+
if (variants[height].mult === undefined) {
80+
delete variants[height].mult
7681
}
7782
})
7883

7984
return { name: getJsFriendlyName(name), variants }
8085
})
8186
}
8287

88+
function getSizeMultiplier(icon: string) {
89+
switch (icon) {
90+
case 'globe':
91+
case 'mark-github':
92+
case 'file-diff':
93+
return 14 / 16
94+
case 'file-directory':
95+
case 'trash':
96+
return 15 / 16
97+
default:
98+
return undefined
99+
}
100+
}
101+
83102
generateIconData().then(results => {
84103
console.log(`Writing ${results.length} octicons...`)
85104

@@ -104,6 +123,9 @@ export type OcticonSymbolVariant = {
104123
105124
/** The height of the symbol */
106125
readonly h: number
126+
127+
/** The size multiplier in order to normalize the apparent size (generally between 0 and 1) */
128+
readonly mult?: number
107129
}
108130
109131
export type OcticonSymbolVariants = Record<PropertyKey, OcticonSymbolVariant>

0 commit comments

Comments
 (0)