Skip to content

Commit

Permalink
Merge pull request #7 from ipuppet/dev
Browse files Browse the repository at this point in the history
增加显示周和天数
  • Loading branch information
ipuppet authored Dec 16, 2021
2 parents e224a55 + b62ca52 commit 2f6cdb9
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 24 deletions.
79 changes: 59 additions & 20 deletions scripts/widget/MyDays/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MyDaysWidget extends Widget {
this.isImageBackground = $file.exists(this.backgroundImage)
this.showMinus = this.setting.get("showMinus")
this.displayMode = this.setting.get("displayMode") // 0: 显示天数, 1: 显示周数
this.weekXWXD = this.setting.get("week.xWxD") // 0: 显示天数, 1: 显示周数
}

dateSpan(date) {
Expand All @@ -45,8 +46,12 @@ class MyDaysWidget extends Widget {
}
}

weekToString(week) {
return String(this.showMinus ? week : Math.abs(week))
getWeekInfo(days) {
days = this.showMinus ? days : Math.abs(days)
return {
week: String(Number(days / 7).toFixed(0)),
day: String(Number(days % 7).toFixed(0))
}
}

view2x2() {
Expand All @@ -56,9 +61,56 @@ class MyDaysWidget extends Widget {
props: { text: $l10n("NONE") }
}
const remainingDays = this.dateSpan(myday.date)
const remainingWeek = parseInt(remainingDays / 7)
const content = this.displayMode ? this.weekToString(remainingWeek) : this.dateSpanToString(remainingDays)
let view = {
const getContent = (content, props = {}) => ({
type: "text",
props: Object.assign({
text: content,
font: $font(this.dateFontSize),
color: remainingDays >= 0 ? $color(this.dateColor, this.dateColorDark) : $color(this.overdueColor, this.overdueColorDark),
padding: 0,
frame: {
alignment: $widget.alignment.topLeading,
maxWidth: Infinity,
maxHeight: Infinity
}
}, props)
})
const mainView = []
if (this.displayMode) { // 周数
const weekInfo = this.getWeekInfo(remainingDays)
if (this.weekXWXD) {
mainView.push({
type: "hstack",
props: {
padding: 0,
spacing: 0,
frame: {
alignment: $widget.alignment.topLeading,
maxWidth: Infinity,
maxHeight: Infinity
}
},
views: [
getContent(weekInfo.week, {
frame: {
alignment: $widget.alignment.topTrailing,
maxWidth: this.dateFontSize / 1.5, // 字体大小和布局宽度之间存在某种比例
maxHeight: Infinity
}
}),
getContent(weekInfo.day, {
font: $font(this.dateFontSize / 2),
offset: $point(5, this.dateFontSize - this.dateFontSize / 2)
})
]
})
} else {
mainView.push(getContent(weekInfo.week))
}
} else { //天数
mainView.push(getContent(this.dateSpanToString(remainingDays)))
}
const view = {
type: "vstack",
props: {
alignment: $widget.verticalAlignment.center,
Expand All @@ -72,20 +124,7 @@ class MyDaysWidget extends Widget {
link: this.setting.settingUrlScheme,
widgetURL: this.setting.settingUrlScheme
},
views: [
{
type: "text",
props: {
text: content,
font: $font(this.dateFontSize),
color: remainingDays >= 0 ? $color(this.dateColor, this.dateColorDark) : $color(this.overdueColor, this.overdueColorDark),
frame: {
alignment: $widget.alignment.topLeading,
maxWidth: Infinity,
maxHeight: Infinity
}
}
},
views: mainView.concat([
{
type: "text",
props: {
Expand Down Expand Up @@ -122,7 +161,7 @@ class MyDaysWidget extends Widget {
}
}
}
]
])
}
if (this.isImageBackground) {
return {
Expand Down
15 changes: 11 additions & 4 deletions scripts/widget/MyDays/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@
"value": false
},
{
"icon": [
"flag.fill",
"#FFCC00"
],
"title": "DISPLAY_MODE",
"type": "tab",
"key": "displayMode",
Expand All @@ -63,6 +59,17 @@
"value": 0
}
]
},
{
"title": "DISPLAY_MODE_WEEK",
"items": [
{
"title": "X_WEEK_X_DAY",
"type": "switch",
"key": "week.xWxD",
"value": false
}
]
}
]
},
Expand Down
1 change: 1 addition & 0 deletions scripts/widget/MyDays/strings/en.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"SHOW_MINUS" = "Show Minus";
"DISPLAY_MODE_DAY" = "Day";
"DISPLAY_MODE_WEEK" = "Week";
"X_WEEK_X_DAY" = "xW + xD";
"OVERDUE_COLOR" = "Overdue Color";
"DATE_FONT_SIZE" = "Date Font Size";
"DATE_COLOR" = "Date Color";
Expand Down
1 change: 1 addition & 0 deletions scripts/widget/MyDays/strings/zh-Hans.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"SHOW_MINUS" = "显示负号";
"DISPLAY_MODE_DAY" = "天数";
"DISPLAY_MODE_WEEK" = "周数";
"X_WEEK_X_DAY" = "x周 + x天";
"OVERDUE_COLOR" = "过期日期颜色";
"DATE_FONT_SIZE" = "日期字体大小";
"DATE_COLOR" = "日期颜色";
Expand Down

0 comments on commit 2f6cdb9

Please sign in to comment.