Merge pull request #79 from Hufe921/feature/alignment
feat:add row alignment
This commit is contained in:
@@ -85,6 +85,9 @@
|
|||||||
<div class="menu-item__right">
|
<div class="menu-item__right">
|
||||||
<i></i>
|
<i></i>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="menu-item__alignment">
|
||||||
|
<i></i>
|
||||||
|
</div>
|
||||||
<div class="menu-item__row-margin">
|
<div class="menu-item__row-margin">
|
||||||
<i></i>
|
<i></i>
|
||||||
<div class="options">
|
<div class="options">
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M2 13h12v1H2v-1zm0-3h12v1H2v-1zm0-3h12v1H2V7zm0-6h12v1H2V1zm0 3h12v1H2V4z" fill="#3D4757" fill-rule="evenodd"/></svg>
|
||||||
|
After Width: | Height: | Size: 209 B |
@@ -35,6 +35,7 @@ export class Command {
|
|||||||
private static left: CommandAdapt['rowFlex']
|
private static left: CommandAdapt['rowFlex']
|
||||||
private static center: CommandAdapt['rowFlex']
|
private static center: CommandAdapt['rowFlex']
|
||||||
private static right: CommandAdapt['rowFlex']
|
private static right: CommandAdapt['rowFlex']
|
||||||
|
private static alignment: CommandAdapt['rowFlex']
|
||||||
private static rowMargin: CommandAdapt['rowMargin']
|
private static rowMargin: CommandAdapt['rowMargin']
|
||||||
private static insertTable: CommandAdapt['insertTable']
|
private static insertTable: CommandAdapt['insertTable']
|
||||||
private static insertTableTopRow: CommandAdapt['insertTableTopRow']
|
private static insertTableTopRow: CommandAdapt['insertTableTopRow']
|
||||||
@@ -104,6 +105,7 @@ export class Command {
|
|||||||
Command.left = adapt.rowFlex.bind(adapt)
|
Command.left = adapt.rowFlex.bind(adapt)
|
||||||
Command.center = adapt.rowFlex.bind(adapt)
|
Command.center = adapt.rowFlex.bind(adapt)
|
||||||
Command.right = adapt.rowFlex.bind(adapt)
|
Command.right = adapt.rowFlex.bind(adapt)
|
||||||
|
Command.alignment = adapt.rowFlex.bind(adapt)
|
||||||
Command.rowMargin = adapt.rowMargin.bind(adapt)
|
Command.rowMargin = adapt.rowMargin.bind(adapt)
|
||||||
Command.insertTable = adapt.insertTable.bind(adapt)
|
Command.insertTable = adapt.insertTable.bind(adapt)
|
||||||
Command.insertTableTopRow = adapt.insertTableTopRow.bind(adapt)
|
Command.insertTableTopRow = adapt.insertTableTopRow.bind(adapt)
|
||||||
@@ -254,6 +256,10 @@ export class Command {
|
|||||||
return Command.right(RowFlex.RIGHT)
|
return Command.right(RowFlex.RIGHT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public executeAlignment() {
|
||||||
|
return Command.alignment(RowFlex.ALIGNMENT)
|
||||||
|
}
|
||||||
|
|
||||||
public executeRowMargin(payload: number) {
|
public executeRowMargin(payload: number) {
|
||||||
return Command.rowMargin(payload)
|
return Command.rowMargin(payload)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -744,6 +744,15 @@ export class Draw {
|
|||||||
|| curRow.width + metrics.width > innerWidth
|
|| curRow.width + metrics.width > innerWidth
|
||||||
|| (i !== 0 && element.value === ZERO)
|
|| (i !== 0 && element.value === ZERO)
|
||||||
) {
|
) {
|
||||||
|
// 两端对齐
|
||||||
|
if (preElement?.rowFlex === RowFlex.ALIGNMENT && curRow.width + metrics.width > innerWidth) {
|
||||||
|
const gap = (innerWidth - curRow.width) / curRow.elementList.length
|
||||||
|
for (let e = 0; e < curRow.elementList.length; e++) {
|
||||||
|
const el = curRow.elementList[e]
|
||||||
|
el.metrics.width += gap
|
||||||
|
}
|
||||||
|
curRow.width = innerWidth
|
||||||
|
}
|
||||||
rowList.push({
|
rowList.push({
|
||||||
width: metrics.width,
|
width: metrics.width,
|
||||||
height,
|
height,
|
||||||
@@ -785,13 +794,11 @@ export class Draw {
|
|||||||
let index = startIndex
|
let index = startIndex
|
||||||
for (let i = 0; i < rowList.length; i++) {
|
for (let i = 0; i < rowList.length; i++) {
|
||||||
const curRow = rowList[i]
|
const curRow = rowList[i]
|
||||||
// 计算行偏移量(行居左、居中、居右)
|
// 计算行偏移量(行居中、居右)
|
||||||
if (curRow.rowFlex && curRow.rowFlex !== RowFlex.LEFT) {
|
if (curRow.rowFlex === RowFlex.CENTER) {
|
||||||
if (curRow.rowFlex === RowFlex.CENTER) {
|
x += (innerWidth - curRow.width) / 2
|
||||||
x += (innerWidth - curRow.width) / 2
|
} else if (curRow.rowFlex === RowFlex.RIGHT) {
|
||||||
} else {
|
x += innerWidth - curRow.width
|
||||||
x += innerWidth - curRow.width
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 当前td所在位置
|
// 当前td所在位置
|
||||||
const tablePreX = x
|
const tablePreX = x
|
||||||
@@ -869,6 +876,10 @@ export class Draw {
|
|||||||
this.checkboxParticle.render(ctx, element, x, y + offsetY)
|
this.checkboxParticle.render(ctx, element, x, y + offsetY)
|
||||||
} else if (element.type === ElementType.TAB) {
|
} else if (element.type === ElementType.TAB) {
|
||||||
this._drawRichText(ctx)
|
this._drawRichText(ctx)
|
||||||
|
} else if (element.rowFlex === RowFlex.ALIGNMENT) {
|
||||||
|
// 如果是两端对齐,因canvas目前不支持letterSpacing需单独绘制文本
|
||||||
|
this.textParticle.record(ctx, element, x, y + offsetY)
|
||||||
|
this._drawRichText(ctx)
|
||||||
} else {
|
} else {
|
||||||
this.textParticle.record(ctx, element, x, y + offsetY)
|
this.textParticle.record(ctx, element, x, y + offsetY)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export enum RowFlex {
|
export enum RowFlex {
|
||||||
LEFT = 'left',
|
LEFT = 'left',
|
||||||
CENTER = 'center',
|
CENTER = 'center',
|
||||||
RIGHT = 'right'
|
RIGHT = 'right',
|
||||||
|
ALIGNMENT = 'alignment'
|
||||||
}
|
}
|
||||||
@@ -146,6 +146,12 @@ window.onload = function () {
|
|||||||
instance.command.executeRight()
|
instance.command.executeRight()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const alignmentDom = document.querySelector<HTMLDivElement>('.menu-item__alignment')!
|
||||||
|
alignmentDom.onclick = function () {
|
||||||
|
console.log('alignment')
|
||||||
|
instance.command.executeAlignment()
|
||||||
|
}
|
||||||
|
|
||||||
const rowMarginDom = document.querySelector<HTMLDivElement>('.menu-item__row-margin')!
|
const rowMarginDom = document.querySelector<HTMLDivElement>('.menu-item__row-margin')!
|
||||||
const rowOptionDom = rowMarginDom.querySelector<HTMLDivElement>('.options')!
|
const rowOptionDom = rowMarginDom.querySelector<HTMLDivElement>('.options')!
|
||||||
rowMarginDom.onclick = function () {
|
rowMarginDom.onclick = function () {
|
||||||
@@ -866,10 +872,13 @@ window.onload = function () {
|
|||||||
leftDom.classList.remove('active')
|
leftDom.classList.remove('active')
|
||||||
centerDom.classList.remove('active')
|
centerDom.classList.remove('active')
|
||||||
rightDom.classList.remove('active')
|
rightDom.classList.remove('active')
|
||||||
|
alignmentDom.classList.remove('active')
|
||||||
if (payload.rowFlex && payload.rowFlex === 'right') {
|
if (payload.rowFlex && payload.rowFlex === 'right') {
|
||||||
rightDom.classList.add('active')
|
rightDom.classList.add('active')
|
||||||
} else if (payload.rowFlex && payload.rowFlex === 'center') {
|
} else if (payload.rowFlex && payload.rowFlex === 'center') {
|
||||||
centerDom.classList.add('active')
|
centerDom.classList.add('active')
|
||||||
|
} else if (payload.rowFlex && payload.rowFlex === 'alignment') {
|
||||||
|
alignmentDom.classList.add('active')
|
||||||
} else {
|
} else {
|
||||||
leftDom.classList.add('active')
|
leftDom.classList.add('active')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,6 +266,10 @@ ul {
|
|||||||
background-image: url('./assets/images/right.svg');
|
background-image: url('./assets/images/right.svg');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.menu-item__alignment i {
|
||||||
|
background-image: url('./assets/images/alignment.svg');
|
||||||
|
}
|
||||||
|
|
||||||
.menu-item__row-margin {
|
.menu-item__row-margin {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user