mirror of https://github.com/espruino/BangleApps
Sliding Clock: Adding aligment to row definitions.
parent
b698c60a41
commit
08715650e3
|
@ -365,6 +365,7 @@ const speeds = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const Y_RESERVED = 20;
|
const Y_RESERVED = 20;
|
||||||
|
const SPACES = ' ';
|
||||||
/**
|
/**
|
||||||
* takes a json definition for a row type and creates an instance
|
* takes a json definition for a row type and creates an instance
|
||||||
*/
|
*/
|
||||||
|
@ -415,6 +416,21 @@ function create_row_type(row_type, row_def){
|
||||||
return scroll_offs[idx](row_display);
|
return scroll_offs[idx](row_display);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var text_formatter = (txt)=>txt;
|
||||||
|
if(row_def.hasOwnProperty("alignment")){
|
||||||
|
var alignment = row_def.alignment;
|
||||||
|
if(alignment.startsWith("centre")){
|
||||||
|
const padding = parseInt(alignment.split("-")[1]);
|
||||||
|
if(padding > 0){
|
||||||
|
text_formatter = (txt) => {
|
||||||
|
const front_spaces = (padding - txt.length)/2 | 0;
|
||||||
|
return front_spaces > 0? SPACES.substring(0,front_spaces + 1) + txt : txt;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var version = bangleVersion() - 1;
|
var version = bangleVersion() - 1;
|
||||||
return {
|
return {
|
||||||
row_speed: speed,
|
row_speed: speed,
|
||||||
|
@ -424,7 +440,8 @@ function create_row_type(row_type, row_def){
|
||||||
y: (row_no) => Y_RESERVED + row_def.init_coords[1] * (g.getHeight() - Y_RESERVED) + row_def.row_direction[1] * height[version] * row_no,
|
y: (row_no) => Y_RESERVED + row_def.init_coords[1] * (g.getHeight() - Y_RESERVED) + row_def.row_direction[1] * height[version] * row_no,
|
||||||
scroll_in: scroll_in,
|
scroll_in: scroll_in,
|
||||||
scroll_off: scroll_off,
|
scroll_off: scroll_off,
|
||||||
fg_color: () => (row_type.color === 'major')? main_color(): other_color()
|
fg_color: () => (row_type.color === 'major')? main_color(): other_color(),
|
||||||
|
row_text_formatter : text_formatter
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -531,7 +548,7 @@ function drawClock(){
|
||||||
var display;
|
var display;
|
||||||
for (var i = 0; i < rows.length; i++) {
|
for (var i = 0; i < rows.length; i++) {
|
||||||
display = row_displays[i];
|
display = row_displays[i];
|
||||||
var txt = rows[i];
|
var txt = display.getRowContext().row_text_formatter(rows[i]);
|
||||||
display_row(display,txt);
|
display_row(display,txt);
|
||||||
}
|
}
|
||||||
// If the dateformatter has not returned enough
|
// If the dateformatter has not returned enough
|
||||||
|
@ -605,7 +622,7 @@ class DigitDateTimeFormatter {
|
||||||
angle_to_horizontal: 90,
|
angle_to_horizontal: 90,
|
||||||
scroll_off: ['down'],
|
scroll_off: ['down'],
|
||||||
scroll_in: ['up'],
|
scroll_in: ['up'],
|
||||||
size: 'vsmall'
|
size: 'vvsmall'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -613,13 +630,13 @@ class DigitDateTimeFormatter {
|
||||||
{
|
{
|
||||||
type: 'large',
|
type: 'large',
|
||||||
row_direction: [0.0,1.0],
|
row_direction: [0.0,1.0],
|
||||||
init_coords: [0.15,0.4],
|
init_coords: [0.1,0.35],
|
||||||
rows: 1
|
rows: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'small',
|
type: 'small',
|
||||||
row_direction: [1.0,0],
|
row_direction: [1.0,0],
|
||||||
init_coords: [0.9,0.95],
|
init_coords: [0.85,0.99],
|
||||||
rows: 2
|
rows: 2
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -7,7 +7,7 @@ class DigitDateTimeFormatter {
|
||||||
scroll_off: ['down'],
|
scroll_off: ['down'],
|
||||||
scroll_in: ['up'],
|
scroll_in: ['up'],
|
||||||
size: 'large',
|
size: 'large',
|
||||||
speed: 'vslow'
|
speed: 'slow'
|
||||||
},
|
},
|
||||||
small: {
|
small: {
|
||||||
angle_to_horizontal: 0,
|
angle_to_horizontal: 0,
|
||||||
|
@ -19,9 +19,15 @@ class DigitDateTimeFormatter {
|
||||||
this.row_defs = [
|
this.row_defs = [
|
||||||
{
|
{
|
||||||
type: 'large',
|
type: 'large',
|
||||||
row_direction: [0.8,0.0],
|
row_direction: [0.7,0.0],
|
||||||
init_coords: [0.1,0.35],
|
init_coords: [0.15,0.35],
|
||||||
rows: 5
|
rows: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'large',
|
||||||
|
row_direction: [0.7,0.0],
|
||||||
|
init_coords: [0.55,0.35],
|
||||||
|
rows: 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'small',
|
type: 'small',
|
||||||
|
|
|
@ -2,37 +2,6 @@ var DateFormatter = require("slidingtext.dtfmt.js");
|
||||||
const hoursToText = require("slidingtext.utils.en.js").hoursToText;
|
const hoursToText = require("slidingtext.utils.en.js").hoursToText;
|
||||||
const numberToText = require("slidingtext.utils.en.js").numberToText;
|
const numberToText = require("slidingtext.utils.en.js").numberToText;
|
||||||
|
|
||||||
/**
|
|
||||||
* Alternative layouts
|
|
||||||
*
|
|
||||||
{
|
|
||||||
row_types: {
|
|
||||||
large:{
|
|
||||||
angle_to_horizontal: 90
|
|
||||||
}
|
|
||||||
},
|
|
||||||
row_defs: [
|
|
||||||
{
|
|
||||||
type: 'large',
|
|
||||||
init_coords: [0.05,0.95],
|
|
||||||
row_direction: [1.0,0.0],
|
|
||||||
rows: 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'medium',
|
|
||||||
init_coords: [0.3,0.1],
|
|
||||||
row_direction: [0.0,1.0],
|
|
||||||
rows: 2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'small',
|
|
||||||
init_coords: [0.3,0.9],
|
|
||||||
row_direction: [0.0,1.0],
|
|
||||||
rows: 1
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
class EnglishDateFormatter extends DateFormatter {
|
class EnglishDateFormatter extends DateFormatter {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
|
@ -2,51 +2,6 @@ var DateFormatter = require("slidingtext.dtfmt.js");
|
||||||
const hoursToText = require("slidingtext.utils.en.js").hoursToText;
|
const hoursToText = require("slidingtext.utils.en.js").hoursToText;
|
||||||
const numberToText = require("slidingtext.utils.en.js").numberToText;
|
const numberToText = require("slidingtext.utils.en.js").numberToText;
|
||||||
|
|
||||||
/**
|
|
||||||
alternatives:
|
|
||||||
row_types: {
|
|
||||||
vsmall: {
|
|
||||||
scroll_off: ['right'],
|
|
||||||
scroll_in: ['right'],
|
|
||||||
angle_to_horizontal: 0
|
|
||||||
},
|
|
||||||
large: {
|
|
||||||
size: 'vlarge',
|
|
||||||
angle_to_horizontal: 90,
|
|
||||||
speed: 'slow',
|
|
||||||
color: 'major',
|
|
||||||
scroll_off: ['down'],
|
|
||||||
scroll_in: ['up']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
row_defs: [
|
|
||||||
{
|
|
||||||
type: 'large',
|
|
||||||
init_coords: [0.7,0.9],
|
|
||||||
row_direction: [0.0,1.0],
|
|
||||||
rows: 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'small',
|
|
||||||
init_coords: [0.05,0.35],
|
|
||||||
row_direction: [0.0,1.0],
|
|
||||||
rows: 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'large',
|
|
||||||
init_coords: [0.7,0.9],
|
|
||||||
row_direction: [0.0,1.0],
|
|
||||||
rows: 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'vsmall',
|
|
||||||
init_coords: [0.05,0.1],
|
|
||||||
row_direction: [0.0,1.0],
|
|
||||||
rows: 1
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
*/
|
|
||||||
class EnglishTraditionalDateFormatter extends DateFormatter {
|
class EnglishTraditionalDateFormatter extends DateFormatter {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
|
@ -29,17 +29,18 @@
|
||||||
type: 'large',
|
type: 'large',
|
||||||
init_coords: [0.05,0.99],
|
init_coords: [0.05,0.99],
|
||||||
row_direction: [1.0,0.0],
|
row_direction: [1.0,0.0],
|
||||||
|
alignment: 'centre-6',
|
||||||
rows: 1
|
rows: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'medium',
|
type: 'medium',
|
||||||
init_coords: [0.29,0.1],
|
init_coords: [0.27,0.1],
|
||||||
row_direction: [0.0,1.0],
|
row_direction: [0.0,1.0],
|
||||||
rows: 2
|
rows: 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'small',
|
type: 'small',
|
||||||
init_coords: [0.29,0.9],
|
init_coords: [0.27,0.9],
|
||||||
row_direction: [0.0,1.0],
|
row_direction: [0.0,1.0],
|
||||||
rows: 1
|
rows: 1
|
||||||
}
|
}
|
||||||
|
@ -64,8 +65,9 @@
|
||||||
row_defs: [
|
row_defs: [
|
||||||
{
|
{
|
||||||
type: 'large',
|
type: 'large',
|
||||||
init_coords: [0.7,0.9],
|
init_coords: [0.7,0.99],
|
||||||
row_direction: [0.0,1.0],
|
row_direction: [0.0,1.0],
|
||||||
|
alignment: 'centre-6',
|
||||||
rows: 1
|
rows: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -78,6 +80,7 @@
|
||||||
type: 'large',
|
type: 'large',
|
||||||
init_coords: [0.7,0.99],
|
init_coords: [0.7,0.99],
|
||||||
row_direction: [0.0,1.0],
|
row_direction: [0.0,1.0],
|
||||||
|
alignment: 'centre-6',
|
||||||
rows: 1
|
rows: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -93,6 +96,7 @@
|
||||||
'es': { date_formatter: 'es'},
|
'es': { date_formatter: 'es'},
|
||||||
'jp': { date_formatter: 'jp'},
|
'jp': { date_formatter: 'jp'},
|
||||||
'dgt': { date_formatter: 'dgt'},
|
'dgt': { date_formatter: 'dgt'},
|
||||||
|
'dgt2': { date_formatter: 'default'},
|
||||||
}
|
}
|
||||||
var locales = Object.keys(locale_mappings);
|
var locales = Object.keys(locale_mappings);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue