Support margin option

This commit is contained in:
ryo-ma 2020-09-19 22:32:04 +09:00
parent 3ceb08fce5
commit f9e4a2a795
3 changed files with 16 additions and 14 deletions

View file

@ -17,13 +17,13 @@ export default async (req: ServerRequest) => {
if (Object.keys(COLORS).includes(themeParam)) {
theme = COLORS[themeParam]
}
const paddingWidth = params.getNumberValue(
"padding-w",
CONSTANTS.DEFAULT_PADDING_W,
const marginWidth = params.getNumberValue(
"margin-w",
CONSTANTS.DEFAULT_MARGIN_W,
);
const paddingHeight = params.getNumberValue(
"padding-h",
CONSTANTS.DEFAULT_PADDING_H,
"margin-h",
CONSTANTS.DEFAULT_MARGIN_H,
);
const titles: Array<string> = params.getAll("title").flatMap((r) =>
r.split(",")
@ -62,7 +62,7 @@ export default async (req: ServerRequest) => {
column,
row,
CONSTANTS.DEFAULT_PANEL_SIZE,
paddingWidth,
marginWidth,
paddingHeight,
).render(userInfo, theme),
headers: new Headers(

View file

@ -25,10 +25,10 @@ export class Card {
private maxColumn: number,
private maxRow: number,
private panelSize: number,
private paddingWidth: number,
private paddingHight: number,
private marginWidth: number,
private marginHight: number,
) {
this.width = panelSize * this.maxColumn;
this.width = panelSize * this.maxColumn + this.marginWidth * (this.maxColumn - 1);
}
render(
userInfo: UserInfo,
@ -83,13 +83,15 @@ export class Card {
if (row > this.maxRow) {
row = this.maxRow;
}
this.height = this.panelSize * row;
this.height = this.panelSize * row + this.marginHight * (row - 1);
// Join all trophy
const renderedTrophy = trophyList.reduce(
(sum: string, trophy: Trophy, i: number) => {
const x = this.panelSize * (i % this.maxColumn);
const y = this.panelSize * Math.floor(i / this.maxColumn);
const currentColumn = i % this.maxColumn;
const currentRow = Math.floor(i / this.maxColumn);
const x = this.panelSize * currentColumn + this.marginWidth * currentColumn;
const y = this.panelSize * currentRow + this.marginHight * currentRow;
return sum + trophy.render(theme, x, y, this.panelSize);
},
"",

View file

@ -51,8 +51,8 @@ export const CONSTANTS = {
DEFAULT_PANEL_SIZE: 110,
DEFAULT_MAX_COLUMN: 6,
DEFAULT_MAX_ROW: 3,
DEFAULT_PADDING_W: 0,
DEFAULT_PADDING_H: 0,
DEFAULT_MARGIN_W: 0,
DEFAULT_MARGIN_H: 0,
};
export enum RANK {