mirror of
https://github.com/skishore/makemeahanzi.git
synced 2025-11-01 12:07:15 +08:00
Extend stages API to allow for custom UI
This commit is contained in:
@ -35,7 +35,8 @@ const incrementStage = (amount) => {
|
|||||||
const initialize = () => {
|
const initialize = () => {
|
||||||
const glyph = Session.get('editor.glyph');
|
const glyph = Session.get('editor.glyph');
|
||||||
if (glyph === undefined) {
|
if (glyph === undefined) {
|
||||||
changeGlyph('getNextGlyph');
|
//changeGlyph('getNextGlyph');
|
||||||
|
getGlyph({character: '黽'});
|
||||||
} else {
|
} else {
|
||||||
getGlyph({character: glyph.character});
|
getGlyph({character: glyph.character});
|
||||||
}
|
}
|
||||||
@ -58,7 +59,6 @@ Template.editor.events({
|
|||||||
});
|
});
|
||||||
|
|
||||||
Template.editor.helpers({
|
Template.editor.helpers({
|
||||||
stage: () => Session.get('stage.type'),
|
|
||||||
paths: () => Session.get('stage.paths'),
|
paths: () => Session.get('stage.paths'),
|
||||||
lines: () => Session.get('stage.lines'),
|
lines: () => Session.get('stage.lines'),
|
||||||
points: () => Session.get('stage.points'),
|
points: () => Session.get('stage.points'),
|
||||||
@ -66,7 +66,7 @@ Template.editor.helpers({
|
|||||||
|
|
||||||
Template.status.helpers({
|
Template.status.helpers({
|
||||||
stage: () => Session.get('stage.type'),
|
stage: () => Session.get('stage.type'),
|
||||||
instructions: () => Session.get('stage.instructions'),
|
template: () => `${Session.get('stage.type')}_stage`,
|
||||||
lines: () => Session.get('stage.status'),
|
lines: () => Session.get('stage.status'),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="editor">
|
<template name="editor">
|
||||||
<div id="editor" class="{{stage}}">
|
<div id="editor">
|
||||||
<div class="left-pane">
|
<div class="left-pane">
|
||||||
{{> metadata}}
|
{{> metadata}}
|
||||||
{{> status}}
|
{{> status}}
|
||||||
@ -94,7 +94,9 @@
|
|||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h3 class="panel-title">Edit {{stage}}</h3>
|
<h3 class="panel-title">Edit {{stage}}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="instructions">{{instructions}}</div>
|
<div class="template {{template}}">
|
||||||
|
{{> UI.dynamic template=template}}
|
||||||
|
</div>
|
||||||
<ul class="log">
|
<ul class="log">
|
||||||
{{#each lines}}
|
{{#each lines}}
|
||||||
<li class="line {{cls}}">{{message}}</li>
|
<li class="line {{cls}}">{{message}}</li>
|
||||||
|
|||||||
@ -19,11 +19,10 @@ stages.AbstractStage = class AbstractStage {
|
|||||||
// The class name 'selectable' is special for paths, lines, and points.
|
// The class name 'selectable' is special for paths, lines, and points.
|
||||||
// Including this class in cls for those objects will make them interactive
|
// Including this class in cls for those objects will make them interactive
|
||||||
// and will trigger the onClick callback when they are clicked.
|
// and will trigger the onClick callback when they are clicked.
|
||||||
Session.set('stage.type', undefined);
|
Session.set('stage.type', glyph);
|
||||||
Session.set('stage.paths', undefined);
|
Session.set('stage.paths', undefined);
|
||||||
Session.set('stage.lines', undefined);
|
Session.set('stage.lines', undefined);
|
||||||
Session.set('stage.points', undefined);
|
Session.set('stage.points', undefined);
|
||||||
Session.set('stage.instructions', undefined);
|
|
||||||
Session.set('stage.status', undefined);
|
Session.set('stage.status', undefined);
|
||||||
this.colors = ['#0074D9', '#2ECC40', '#FFDC00', '#FF4136', '#7FDBFF',
|
this.colors = ['#0074D9', '#2ECC40', '#FFDC00', '#FF4136', '#7FDBFF',
|
||||||
'#001F3F', '#39CCCC', '#3D9970', '#01FF70', '#FF851B'];
|
'#001F3F', '#39CCCC', '#3D9970', '#01FF70', '#FF851B'];
|
||||||
|
|||||||
@ -11,12 +11,7 @@ const removeBridge = (bridges, bridge) => {
|
|||||||
|
|
||||||
stages.bridges = class BridgesStage extends stages.AbstractStage {
|
stages.bridges = class BridgesStage extends stages.AbstractStage {
|
||||||
constructor(glyph) {
|
constructor(glyph) {
|
||||||
super();
|
super('bridges');
|
||||||
Session.set('stage.type', 'bridges');
|
|
||||||
Session.set('stage.instructions',
|
|
||||||
'Connect each pair of points on the glyph outline such that ' +
|
|
||||||
'the segment connecting those points is part of some stroke ' +
|
|
||||||
'outline. Click on a bridge to drop it.');
|
|
||||||
const bridges = stroke_extractor.getBridges(glyph.stages.path);
|
const bridges = stroke_extractor.getBridges(glyph.stages.path);
|
||||||
this.bridges = bridges.bridges;
|
this.bridges = bridges.bridges;
|
||||||
this.endpoints = [];
|
this.endpoints = [];
|
||||||
|
|||||||
@ -2,13 +2,16 @@
|
|||||||
|
|
||||||
stages.path = class PathStage extends stages.AbstractStage {
|
stages.path = class PathStage extends stages.AbstractStage {
|
||||||
constructor(glyph) {
|
constructor(glyph) {
|
||||||
super();
|
super('path');
|
||||||
Session.set('stage.type', 'path');
|
|
||||||
Session.set('stage.instructions',
|
|
||||||
'Choose a source for glyph path data for this character:');
|
|
||||||
}
|
}
|
||||||
refresh(glyph) {
|
refresh(glyph) {
|
||||||
const d = glyph.stages.path;
|
const d = glyph.stages.path;
|
||||||
Session.set('stage.paths', [{d: d, fill: 'gray', stroke: 'gray'}]);
|
Session.set('stage.paths', [{d: d, fill: 'gray', stroke: 'gray'}]);
|
||||||
|
Session.set('stage.status',
|
||||||
|
d ? [] : [{cls: 'error', message: 'No path data.'}]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Template.path_stage.helpers({
|
||||||
|
options: () => [{label: 'gkai'}, {label: 'UKaiCN'}],
|
||||||
|
});
|
||||||
|
|||||||
@ -22,12 +22,7 @@ const getStrokePaths = (strokes, include, colors) => {
|
|||||||
|
|
||||||
stages.strokes = class StrokesStage extends stages.AbstractStage {
|
stages.strokes = class StrokesStage extends stages.AbstractStage {
|
||||||
constructor(glyph) {
|
constructor(glyph) {
|
||||||
super();
|
super('strokes');
|
||||||
Session.set('stage.type', 'strokes');
|
|
||||||
Session.set('stage.instructions',
|
|
||||||
'Select paths to include in the glyph by clicking on them. ' +
|
|
||||||
'The final number of paths must agree with the stroke count ' +
|
|
||||||
'in the character metadata.');
|
|
||||||
const include = this.include = {};
|
const include = this.include = {};
|
||||||
this.strokes = stroke_extractor.getStrokes(
|
this.strokes = stroke_extractor.getStrokes(
|
||||||
glyph.stages.path, glyph.stages.bridges).strokes;
|
glyph.stages.path, glyph.stages.bridges).strokes;
|
||||||
|
|||||||
@ -63,8 +63,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.status {
|
.status {
|
||||||
.instructions {
|
.template {
|
||||||
margin: 8px;
|
margin: 8px 8px 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.log {
|
.log {
|
||||||
@ -107,3 +107,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#editor .status .template {
|
||||||
|
&.path_stage {
|
||||||
|
.option, .separator {
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.separator:last-child {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
18
client/templates.html
Normal file
18
client/templates.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<template name="path_stage">
|
||||||
|
Choose a source for glyph path data for this character:
|
||||||
|
{{#each options}}
|
||||||
|
<a class="option">{{label}}</a>
|
||||||
|
<div class="separator">•</div>
|
||||||
|
{{/each}}
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template name="bridges_stage">
|
||||||
|
Connect each pair of path points such that the segment between those points
|
||||||
|
is part of some stroke outline. Click on two points to connect them by a
|
||||||
|
bridge, or click on a bridge to drop it.
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template name="strokes_stage">
|
||||||
|
Select paths to include in the glyph by clicking on them. The final number of
|
||||||
|
strokes must agree with the stroke count in the character metadata.
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user