Add real-time layout sync and refresh default layout
This commit is contained in:
1 parent
274b8538b7
commit
f79e30897b
20 files changed
+289
-77
No files matched your search
+16
-16
@@ -222,7 +222,7 @@ pre.json{font:11px/1.55 ui-monospace,Menlo,monospace;color:#9fb4d8;
|
||||
<option value="1080x2400">1080 × 2400</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="row">safeTop <input type="number" id="safeTop" value="132" step="4"></div>
|
||||
<div class="row">safeTop <input type="number" id="safeTop" value="72" step="4"></div>
|
||||
<div class="row">safeBottom <input type="number" id="safeBottom" value="72" step="4"></div>
|
||||
<div class="row">吸附 12px <input type="checkbox" id="snap" checked></div>
|
||||
<div class="row">参考线 <input type="checkbox" id="showGuides" checked></div>
|
||||
@@ -351,10 +351,10 @@ oy = (H − Dh·s) · anchor</div>
|
||||
* ===========================================================================*/
|
||||
const LIB = [
|
||||
{ type:'app_icon', label:'图标', w:132, h:168, payload:{ package:'com.tencent.mm', label:'微信' } },
|
||||
{ type:'app_icon', label:'相机', w:132, h:168, payload:{ package:'com.android.camera', label:'相机' } },
|
||||
{ type:'widget', label:'时钟组件', w:864, h:320, payload:{ provider:'com.android.deskclock/.ClockWidget', label:'时钟' } },
|
||||
{ type:'widget', label:'天气组件', w:420, h:300, payload:{ provider:'com.android.weather/.WeatherWidget', label:'天气' } },
|
||||
{ type:'widget', label:'音乐组件', w:420, h:300, payload:{ provider:'com.spotify/.MusicWidget', label:'音乐' } },
|
||||
{ type:'app_icon', label:'相机', w:132, h:168, payload:{ package:'com.android.camera2', label:'相机' } },
|
||||
{ type:'widget', label:'时钟组件', w:864, h:320, payload:{ provider:'com.android.deskclock/com.android.alarmclock.DigitalAppWidgetProvider', label:'时钟' } },
|
||||
{ type:'widget', label:'搜索组件', w:420, h:300, payload:{ provider:'com.android.quicksearchbox/com.android.quicksearchbox.SearchWidgetProvider', label:'搜索' } },
|
||||
{ type:'widget', label:'音乐组件', w:420, h:300, payload:{ provider:'com.tencent.qqmusic/com.tencent.qqmusiccommon.WidgetProviderSmall', label:'音乐' } },
|
||||
{ type:'shortcut', label:'快捷方式', w:132, h:168, payload:{ label:'扫一扫', intent:'weixin://scanqrcode' } },
|
||||
{ type:'dock_bg', label:'Dock 底板', w:936, h:200, payload:{ radius:56 } },
|
||||
];
|
||||
@@ -382,7 +382,7 @@ function newState() {
|
||||
return {
|
||||
schemaVersion: 3,
|
||||
revision: 1,
|
||||
canvas: { designWidth:1080, designHeight:1920, safeTop:132, safeBottom:72 },
|
||||
canvas: { designWidth:1080, designHeight:1920, safeTop:72, safeBottom:72 },
|
||||
fit: { mode:'contain', anchorY:0.5 },
|
||||
pages: [{ index:0, background:{ type:'wallpaper' }, items: demoItems() }],
|
||||
};
|
||||
@@ -393,22 +393,22 @@ function demoItems() {
|
||||
const colX = c => pad + c * colW + (colW - icon) / 2;
|
||||
const out = [];
|
||||
out.push({ id:'w_clock', type:'widget', x:pad, y:196, w:864, h:320, z:1,
|
||||
payload:{ provider:'com.android.deskclock/.ClockWidget', label:'时钟' } });
|
||||
payload:{ provider:'com.android.deskclock/com.android.alarmclock.DigitalAppWidgetProvider', label:'时钟' } });
|
||||
|
||||
['微信','相机','相册','设置','浏览器','音乐','地图','日历'].forEach((t, i) => {
|
||||
[['微信','com.tencent.mm'],['相机','com.android.camera2'],['相册','com.android.gallery3d'],['设置','com.android.settings'],['浏览器','com.android.chrome'],['QQ音乐','com.tencent.qqmusic'],['电话','com.android.dialer'],['日历','com.android.calendar']].forEach(([label, pkg], i) => {
|
||||
const c = i % 4, r = Math.floor(i / 4);
|
||||
out.push({ id:'i'+i, type:'app_icon', x:colX(c), y:604 + r*224, w:icon, h:ih, z:2,
|
||||
payload:{ package:'com.demo.app'+i, label:t } });
|
||||
payload:{ package:pkg, label } });
|
||||
});
|
||||
|
||||
out.push({ id:'w_weather', type:'widget', x:pad, y:1076, w:420, h:300, z:1,
|
||||
payload:{ provider:'com.android.weather/.WeatherWidget', label:'天气' } });
|
||||
payload:{ provider:'com.android.quicksearchbox/com.android.quicksearchbox.SearchWidgetProvider', label:'搜索' } });
|
||||
out.push({ id:'w_music', type:'widget', x:552, y:1076, w:420, h:300, z:1,
|
||||
payload:{ provider:'com.spotify/.MusicWidget', label:'音乐' } });
|
||||
payload:{ provider:'com.tencent.qqmusic/com.tencent.qqmusiccommon.WidgetProviderSmall', label:'音乐' } });
|
||||
|
||||
['扫一扫','支付','钱包','更多'].forEach((t, i) => {
|
||||
out.push({ id:'s'+i, type:'shortcut', x:colX(i), y:1650, w:icon, h:ih, z:2,
|
||||
payload:{ label:t, intent:'demo://'+i } });
|
||||
[['联系人','com.android.contacts'],['短信','com.android.messaging'],['文件','com.android.documentsui'],['QQ','com.tencent.mobileqq']].forEach(([label, pkg], i) => {
|
||||
out.push({ id:'s'+i, type:'app_icon', x:colX(i), y:1650, w:icon, h:ih, z:2,
|
||||
payload:{ package:pkg, label } });
|
||||
});
|
||||
return out;
|
||||
}
|
||||
@@ -830,7 +830,7 @@ function validate() {
|
||||
|
||||
if (c.safeTop < 0 || c.safeBottom < 0) push('err', '-', '安全区不能为负数');
|
||||
if (!['contain', 'elastic', 'stretch'].includes(state.fit.mode.toLowerCase())) push('warn', '-', '未知映射模式');
|
||||
if (c.safeTop < 118) push('warn', '-', `safeTop=${c.safeTop} 偏小,1440 屏状态栏约 176px`);
|
||||
if (c.safeTop < 118) push('warn', '-', `safeTop=${c.safeTop} 偏小`);
|
||||
if (c.safeBottom < 40) push('warn', '-', `safeBottom=${c.safeBottom} 偏小,可能被手势条压住`);
|
||||
|
||||
const errors = issues.filter(i => i.lv === 'err').length;
|
||||
@@ -1083,7 +1083,7 @@ $('download').onclick = $('exportBtn').onclick = () => {
|
||||
|
||||
function importLayout(d) {
|
||||
if (!d || (d.schemaVersion ?? 3) !== 3) throw new Error('仅支持布局协议 v3');
|
||||
const canvas = { designWidth:1080, designHeight:1920, safeTop:132, safeBottom:72, ...d.canvas };
|
||||
const canvas = { designWidth:1080, designHeight:1920, safeTop:72, safeBottom:72, ...d.canvas };
|
||||
const fit = { mode:'contain', anchorY:0.5, ...d.fit };
|
||||
if (![canvas.designWidth, canvas.designHeight, canvas.safeTop, canvas.safeBottom].every(Number.isInteger) ||
|
||||
canvas.designWidth < 320 || canvas.designHeight < 480 ||
|
||||
|
||||
Reference in new issue
Block a user