Skip to content

Commit

Permalink
feat(core-components): canvas: initial implementation for canvas with…
Browse files Browse the repository at this point in the history
… improved architecture
  • Loading branch information
stuf committed Oct 19, 2019
1 parent 2d99c90 commit aae6d51
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/components/core/Canvas/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as React from 'karet';
import * as U from 'karet.util';
import * as R from 'kefir.ramda';
import * as K from 'kefir';
import { mouseEventsFor } from 'core/mouse';

import styles from './index.module.scss';

import { offsetIn, fstIn, sndIn } from 'common/meta';
import { elementOffsetFor } from 'common/position';
import { scaleSize } from 'common/canvas';

import Bitmap from 'components/ui/Bitmap';
import Drawable from './_/Drawable';
import PixelGrid from './_/PixelGrid';

export default function Canvas({ size, scale, data, drawable }) {
/** @type {ObsElement>} */
const dom = U.variable();

const { offset, bbox } = U.destructure(drawable);

const domOffset = elementOffsetFor(dom);
const scaledSize = scaleSize(size, scale);

const bus = U.bus();

return (
<div
className={styles.root}
ref={U.refTo(dom)}
style={{
width: fstIn(scaledSize),
height: sndIn(scaledSize),
}}
>
<Drawable offset={offset} bbox={bbox} bus={bus} />
<PixelGrid size={size} scale={scale} />
<Bitmap size={size} scale={scale} data={data} />
</div>
);
}

//

/**
* @typedef {K.Property<HTMLElement, any>} ObsElement
*/
12 changes: 12 additions & 0 deletions src/components/core/Canvas/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.root {
border: solid 1px #f00;
height: 100%;
position: relative;

width: 420px;
height: 240px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}

0 comments on commit aae6d51

Please sign in to comment.