Skip to content

Commit

Permalink
Merge pull request #28 from cannoneyed/resize
Browse files Browse the repository at this point in the history
More elegantly handle screens of varying widths
  • Loading branch information
cannoneyed authored Aug 5, 2019
2 parents d31e654 + 7354943 commit d27b65f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/components/sequences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export class Sequences extends React.Component<SequencesProps> {
marginTop: 20,
display: 'flex',
flexDirection: 'column',
width: layout.sequencesWidth,
});

const showCandidateSequences = sequences.candidateSequences.length > 0;
Expand Down
3 changes: 3 additions & 0 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export const DEFAULT_NOTES = [
[76, 8],
];

export const DEFAULT_EDITOR_WIDTH = 1200;
export const DEFAULT_SEQUENCES_WIDTH = 200;

export const PIANO_ROLL_WIDTH = 24;
export const NOTE_HEIGHT = 12;
export const MASK_LANE_HEIGHT = 20;
Expand Down
18 changes: 18 additions & 0 deletions src/core/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,30 @@ import { computed, observable } from 'mobx';

import { editor } from './index';
import {
DEFAULT_EDITOR_WIDTH,
DEFAULT_SEQUENCES_WIDTH,
PIANO_ROLL_WIDTH,
MASK_LANE_HEIGHT,
TIMELINE_HEIGHT,
} from './constants';

class Layout {
constructor() {
window.onresize = () => this.handleResize();
this.handleResize();
}

handleResize() {
const { innerWidth, innerHeight } = window;
const defaultAppWidth = DEFAULT_EDITOR_WIDTH + DEFAULT_SEQUENCES_WIDTH;
const appWidth = Math.min(innerWidth, defaultAppWidth);

this.sequencesWidth = DEFAULT_SEQUENCES_WIDTH;
this.editorWidth = appWidth - this.sequencesWidth;

console.log({ innerWidth, appWidth, sequencesWidth: this.sequencesWidth });
}

@observable editorWidth = 1200;
@observable sequencesWidth = 200;
@observable sequenceHeight = 80;
Expand Down

0 comments on commit d27b65f

Please sign in to comment.