Skip to content

Commit

Permalink
predefined theme come from readium css
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarsniik committed Dec 26, 2018
1 parent 2156020 commit 8d207f4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
21 changes: 19 additions & 2 deletions src/renderer/components/reader/ReaderApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const computeReadiumCssJsonMessage = (): IEventPayload_R2_EVENT_READIUMCSS => {
colCount: settings.colCount === "1" ? colCountEnum.one :
(settings.colCount === "2" ? colCountEnum.two : colCountEnum.auto),

darken: settings.dark,
darken: settings.darken,

This comment has been minimized.

Copy link
@danielweck

danielweck Dec 26, 2018

Member

Correct :)
night and sepia are predefined colour schemes / themes (aka reading modes) https://github.com/readium/readium-css/blob/master/docs/CSS12-user_prefs.md#reading-modes , whereas darken and invert are filters https://github.com/readium/readium-css/blob/master/docs/CSS12-user_prefs.md#filters

This comment has been minimized.

Copy link
@llemeurfr

llemeurfr Dec 26, 2018

Contributor

so in fact should it be settings.darken (filter) or settings.night (colour scheme)?

This comment has been minimized.

Copy link
@danielweck

danielweck Dec 26, 2018

Member

...or darken: undefined, or darken: readiumCSSDefaults.darken :)

Basically, the question is: should the desktop app expose user-configurable settings for the predefined colour themes / reading modes (i.e. night and sepia), and/or the filters (i.e. darken and invert)? I feel that reading modes are fine (let's ignore the filters for now), and in the future we could even configure backgroundColor and textColor individually to achieve the desired custom "look" that users want / need. What about the iOS and Android apps, do they use the ReadiumCSS filters?

This comment has been minimized.

Copy link
@JayPanoz

JayPanoz Dec 27, 2018

Origin of those filters can be found there, if that can provide some context readium/readium-css#7 (comment)

(Sent from the train station, typos my own)

This comment has been minimized.

Copy link
@JayPanoz

JayPanoz Dec 28, 2018

On a related note, we needed the invert filter for gaiji anyway, cf. https://github.com/readium/readium-css/blob/master/css/src/modules/ReadiumCSS-night_mode.css#L47

So the filter is like exposing it to the RS in case implementers want to provide the option to invert images – please feel free to ping me if you need examples for which it would help quite a lot as there’s a ton of illustrations with a white background – kinda defeating the purpose of night mode in the first place.

Now, I can also recall that for gaiji, our friends at Fruit Company allow authors to pick the className they want, cf. this section of their docs. I’m afraid that if you want to support that, a CSS rule will have to be created on the fly as I can’t retrieve and use such a custom className in ReadiumCSS.


font: settings.font,

Expand Down Expand Up @@ -129,6 +129,7 @@ const computeReadiumCssJsonMessage = (): IEventPayload_R2_EVENT_READIUMCSS => {
wordSpacing: settings.wordSpacing,
};
const jsonMsg: IEventPayload_R2_EVENT_READIUMCSS = { setCSS: cssJson };
console.log(cssJson);
return jsonMsg;
};
setReadiumCssJsonGetter(computeReadiumCssJsonMessage);
Expand Down Expand Up @@ -243,6 +244,7 @@ export default class ReaderApp extends React.Component<undefined, ReaderAppState
this.handleMenuButtonClick = this.handleMenuButtonClick.bind(this);
this.handleSettingsClick = this.handleSettingsClick.bind(this);
this.handleFullscreenClick = this.handleFullscreenClick.bind(this);
this.setSettings = this.setSettings.bind(this);
}

public async componentDidMount() {
Expand Down Expand Up @@ -350,6 +352,7 @@ export default class ReaderApp extends React.Component<undefined, ReaderAppState
handleLinkClick={this.handleLinkClick.bind(this)}
handleSettingChange={this.handleSettingsValueChange.bind(this)}
handleIndexChange={this.handleIndexValueChange.bind(this)}
setSettings={this.setSettings}
/>
<div className={styles.content_root}>
<div className={styles.reader}>
Expand Down Expand Up @@ -487,10 +490,14 @@ export default class ReaderApp extends React.Component<undefined, ReaderAppState
}

private handleSettingsValueChange(event: any, name: string, givenValue?: any) {
if ((givenValue === null || givenValue === undefined) && !event) {
return;
}

const settingsValues = this.state.settingsValues;
let value = givenValue;

if (!value) {
if (givenValue === null || givenValue === undefined) {
value = event.target.value.toString();
}

Expand All @@ -501,6 +508,7 @@ export default class ReaderApp extends React.Component<undefined, ReaderAppState
}

settingsValues[name] = value;
console.log(settingsValues);

this.setState({settingsValues});

Expand All @@ -522,6 +530,15 @@ export default class ReaderApp extends React.Component<undefined, ReaderAppState
this.handleSettingsSave();
}

private setSettings(settingsValues: ReadiumCSS) {
if (!settingsValues) {
return;
}

this.setState({ settingsValues });
this.handleSettingsSave();
}

private getEpubReadingSystem: () => INameVersion = () => {
return { name: "Readium2 Electron/NodeJS desktop app", version: _APP_VERSION };
}
Expand Down
62 changes: 55 additions & 7 deletions src/renderer/components/reader/ReaderOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ interface Props {
handleLinkClick: (event: any, url: string) => void;
handleSettingChange: (event: any, name: string, value?: any) => void;
handleIndexChange: (event: any, name: string, value?: any) => void;
setSettings: (settings: any) => void;
}

interface State {
sectionOpenList: boolean[];
}

enum themeType {
Sepia,
Darken,

This comment has been minimized.

Copy link
@danielweck

danielweck Dec 26, 2018

Member

Note that darken is not a colour scheme / theme / reading mode. It is a filter (see my previous code comment).

Night,
}

export default class ReaderOptions extends React.Component<Props, State> {
private sectionRefList: any = [];

Expand All @@ -65,6 +72,8 @@ export default class ReaderOptions extends React.Component<Props, State> {
React.createRef(),
React.createRef(),
];

this.handleChooseTheme = this.handleChooseTheme.bind(this);
}

public render(): React.ReactElement<{}> {
Expand All @@ -86,16 +95,31 @@ export default class ReaderOptions extends React.Component<Props, State> {
<div ref={this.sectionRefList[0]} className={styles.line_tab_content}>
<div className={styles.subheading}>{__("reader.settings.theme.predefined")}</div>
<div className={styles.theme_choices}>
<input type="radio" id="theme1" name="theme" value="theme1" />
<label>Thème 1</label>
<input
type="radio"
name="theme"
onChange={() => this.handleChooseTheme(themeType.Sepia)}
{...(this.props.settings.sepia && {checked: true})}
/>
<label>Sepia</label>
</div>
<div className={styles.theme_choices}>
<input type="radio" id="theme2" name="theme" value="theme2" />
<label>Thème 2</label>
<input
type="radio"
name="theme"
onChange={() => this.handleChooseTheme(themeType.Darken)}
{...(this.props.settings.darken && {checked: true})}
/>
<label>Dark</label>
</div>
<div className={styles.theme_choices}>
<input type="radio" id="theme3" name="theme" value="theme3" />
<label>Thème 3</label>
<input
type="radio"
name="theme"
onChange={() => this.handleChooseTheme(themeType.Night)}
{...(this.props.settings.night && {checked: true})}
/>
<label>Night</label>
</div>
</div>
</div>
Expand Down Expand Up @@ -394,6 +418,31 @@ export default class ReaderOptions extends React.Component<Props, State> {
this.setState({ sectionOpenList });
}

private handleChooseTheme(theme: themeType) {
const values = this.props.settings;
let sepia = false;
let night = false;
let darken = false;

switch (theme) {
case themeType.Darken:
darken = true;
break;
case themeType.Night:
night = true;
break;
case themeType.Sepia:
sepia = true;
break;
}

values.darken = darken;
values.sepia = sepia;
values.night = night;

this.props.setSettings(values);
}

// round the value to the hundredth
private roundRemValue(value: string) {
if (!value) {
Expand Down Expand Up @@ -424,7 +473,6 @@ export default class ReaderOptions extends React.Component<Props, State> {
if (property === value) {
classname = styles.active;
}
console.log(property, value, classname);
return classNames(classname, additionalClassName);
}
}

0 comments on commit 8d207f4

Please sign in to comment.