Skip to content

Commit

Permalink
feat(webui): add page margin option in webtoon reader
Browse files Browse the repository at this point in the history
Closes: #1512
  • Loading branch information
gotson committed Jan 22, 2025
1 parent 9156ff7 commit 214f687
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
6 changes: 5 additions & 1 deletion komga-webui/src/components/readers/ContinuousReader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:height="calcHeight(page)"
:width="calcWidth(page)"
:id="`page${page.number}`"
style="margin: 0 auto;"
:style="`margin: ${i === 0 ? 0 : pageMargin}px auto;`"
v-intersect="onIntersect"
/>
</div>
Expand Down Expand Up @@ -72,6 +72,10 @@ export default Vue.extend({
type: Number,
required: true,
},
pageMargin: {
type: Number,
required: true,
},
},
watch: {
pages: {
Expand Down
3 changes: 3 additions & 0 deletions komga-webui/src/functions/shortcuts/continuous-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ export const shortcutsSettingsContinuous = [
new Shortcut('bookreader.shortcuts.cycle_side_padding',
(ctx: any) => ctx.cycleSidePadding()
, 'p'),
new Shortcut('bookreader.shortcuts.cycle_page_margin',
(ctx: any) => ctx.cyclePageMargin()
, 'n'),
]
3 changes: 3 additions & 0 deletions komga-webui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"beginning_of_book": "You're at the beginning of the book.",
"changing_reading_direction": "Changing Reading Direction to",
"cycling_page_layout": "Cycling Page Layout",
"cycling_page_margin": "Cycling Page Margin",
"cycling_scale": "Cycling Scale",
"cycling_side_padding": "Cycling Side Padding",
"download_current_page": "Download current page",
Expand Down Expand Up @@ -137,6 +138,7 @@
"general": "General",
"gestures": "Gestures",
"page_layout": "Page layout",
"page_margin": "Page margin",
"paged": "Paginated Reader Options",
"reading_mode": "Reading mode",
"scale_type": "Scale type",
Expand All @@ -148,6 +150,7 @@
"close": "Close",
"cycle_page_layout": "Cycle page layout",
"cycle_scale": "Cycle scale",
"cycle_page_margin": "Cycle page margin",
"cycle_side_padding": "Cycle side padding",
"first_page": "First page",
"fullscreen": "Enter/exit full screen",
Expand Down
4 changes: 4 additions & 0 deletions komga-webui/src/plugins/persisted-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const persistedModule: Module<any, any> = {
continuous: {
scale: '',
padding: '',
margin: '',
},
readingDirection: '',
swipe: false,
Expand Down Expand Up @@ -99,6 +100,9 @@ export const persistedModule: Module<any, any> = {
setWebreaderContinuousPadding(state, val) {
state.webreader.continuous.padding = val
},
setWebreaderContinuousMargin(state, val) {
state.webreader.continuous.margin = val
},
setWebreaderReadingDirection(state, val) {
state.webreader.readingDirection = val
},
Expand Down
1 change: 1 addition & 0 deletions komga-webui/src/types/enum-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export enum PagedReaderLayout {
}

export const PaddingPercentage: number[] = [0, 5, 10, 15, 20, 25, 30, 35, 40]
export const MarginValues: number[] = [0, 5, 10, 15]
34 changes: 33 additions & 1 deletion komga-webui/src/views/DivinaReader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
:animations="animations"
:scale="continuousScale"
:sidePadding="sidePadding"
:page-margin="pageMargin"
@menu="toggleToolbars()"
@jump-previous="jumpToPrevious()"
@jump-next="jumpToNext()"
Expand Down Expand Up @@ -221,6 +222,13 @@
:label="$t('bookreader.settings.side_padding')"
/>
</v-list-item>
<v-list-item>
<settings-select
:items="marginValues"
v-model="pageMargin"
:label="$t('bookreader.settings.page_margin')"
/>
</v-list-item>
</template>

<template v-if="!continuousReader">
Expand Down Expand Up @@ -323,7 +331,7 @@ import Vue from 'vue'
import {Location} from 'vue-router'
import PagedReader from '@/components/readers/PagedReader.vue'
import ContinuousReader from '@/components/readers/ContinuousReader.vue'
import {ContinuousScaleType, PaddingPercentage, PagedReaderLayout, ScaleType} from '@/types/enum-reader'
import {ContinuousScaleType, MarginValues, PaddingPercentage, PagedReaderLayout, ScaleType} from '@/types/enum-reader'
import {
shortcutsLTR,
shortcutsRTL,
Expand Down Expand Up @@ -387,6 +395,7 @@ export default Vue.extend({
scale: ScaleType.SCREEN,
continuousScale: ContinuousScaleType.WIDTH,
sidePadding: 0,
pageMargin: 0,
readingDirection: ReadingDirection.LEFT_TO_RIGHT,
backgroundColor: 'black',
},
Expand Down Expand Up @@ -416,6 +425,10 @@ export default Vue.extend({
text: x === 0 ? this.$i18n.t('bookreader.settings.side_padding_none').toString() : `${x}%`,
value: x,
})),
marginValues: Object.values(MarginValues).map(x => ({
text: x === 0 ? this.$i18n.t('bookreader.settings.side_padding_none').toString() : `${x}px`,
value: x,
})),
backgroundColors: [
{text: this.$t('bookreader.settings.background_colors.white').toString(), value: 'white'},
{text: this.$t('bookreader.settings.background_colors.gray').toString(), value: '#212121'},
Expand Down Expand Up @@ -585,6 +598,17 @@ export default Vue.extend({
}
},
},
pageMargin: {
get: function (): number {
return this.settings.pageMargin
},
set: function (margin: number): void {
if (MarginValues.includes(margin)) {
this.settings.pageMargin = margin
this.$store.commit('setWebreaderContinuousMargin', margin)
}
},
},
backgroundColor: {
get: function (): string {
return this.settings.backgroundColor
Expand Down Expand Up @@ -822,6 +846,14 @@ export default Vue.extend({
this.sendNotification(`${this.$t('bookreader.cycling_side_padding')}: ${text}`)
}
},
cyclePageMargin() {
if (this.continuousReader) {
const i = (MarginValues.indexOf(this.settings.pageMargin) + 1) % (MarginValues.length)
this.pageMargin = MarginValues[i]
const text = this.pageMargin === 0 ? this.$t('bookreader.settings.side_padding_none').toString() : `${this.pageMargin}px`
this.sendNotification(`${this.$t('bookreader.cycling_page_margin')}: ${text}`)
}
},
cyclePageLayout() {
if (this.continuousReader) return
const enumValues = Object.values(PagedReaderLayout)
Expand Down

0 comments on commit 214f687

Please sign in to comment.