Gitjinfeiyang/easy-canvas
About
Create document-flow layouts in canvas with a render function, including Mini Program poster images and images for sharing to Mini Program Moments. easy-canvas is a powerful tool that makes canvas layouts easy.
Web & App DevelopmentMeasured star growth
- in 24h
- 0
- in 7 days
- -1
- in 15 days
- -2
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README_EN.md
OriginalEN | 中文
Introduction
Use the render function to create a document flow in the canvas and quickly implement the layout.
If there is a problem in use, check the code in the example, click to view DEMO
- vue component vue-easy-canvas
- Support document flow, refer to web, no need to set x, y, width and height
- Compatible with small programs and web, no third-party dependencies
- Support componentization, global components and local components
- Support events
- High performance, scroll-view supports dirty rectangles and only draws the visible part
- Support operation element, similar to operation dom to modify document flow
Supporting elements
-
viewbasic element, similar to div -
texttext supports automatic line wrapping and over omitted functions, currently text is implemented as inline-block - ʻimage
imagesrcmodesupports aspectFit and aspectFill, other css features are the same as web supportload` event to monitor image loading and drawing completion -
scroll-viewscroll container, you need to setdirectionin the style to support x, y, xy, and set the specific size. SetrenderOnDemandto draw only the visible part
Styles
Use numbers where the attribute uses pixels
-
displayblock | inline-block | flex, text is inline by default -
widthauto 100% Number This box model uses border-box and cannot be modified -
height -
flexflex does not support auto, use width directly for fixed width -
minWidthmaxWidthminHeightmaxHeightIf the specific width is set, the height will not take effect -
marginmarginLeft,marginRight,marginTop,marginBottommargin supports array abbreviations such as [10,20] [10,20,10,20] -
paddingLeft,paddingRight,paddingTop,paddingBottomSame as above -
backgroundColor -
borderRadius -
borderWidthborderTopWidth... Set the thin border directly to 0.5 -
borderColor -
lineHeightfont related only valid in text -
color -
fontSize -
textAlignleft right center -
textIndentNumber -
verticalAligntop middle bottom -
justifyContentflex-start center flex-end flex layout align horizontally - ʻalignItems` flex-start center flex-end flex layout align it vertically
-
maxLinemaximum number of lines, exceeding the automatic ellipsis, only supports use in text -
whiteSpacenormal nowrap controls line breaks, not fonts - ʻoverflow` hidden If rounded corners are added, hidden will be added automatically
- []
flexDirection -
borderStyledash Array See ctx.setLineDash() for details -
shadowBlurset the shadow will automatically add overflow:hidden; -
shadowColor -
shadowOffsetX -
shadowOffsetY -
positionstaticʻabsolute` - ʻopacity
Number`
Installation
npm install easy-canvas-layout --save
Usage
Basic
import easyCanvas from'easy-canvas-layout'
// create a layer bind with ctx
const layer = easyCanvas.createLayer(ctx, {
dpr: 2,
width: 300,
height: 600,
})
// create a node tree
// c(tag,options,children)
const node = easyCanvas.createElement((c) => {
return c('view', {
styles: {backgroundColor:'#000' }, // style
attrs:(), // attributes such as src
on:{} // events such as click load
},
[
c('text',{color:'#fff'},'Hello World')
])
})
// mount
node.mount(layer)
Register Component
...
function button(c,text){
return c(
'view',
{
styles: {
backgroundColor:'#ff6c79',
borderRadius: 10,
borderColor:'#fff',
display:'inline-block',
margin: 2,
padding:[0,10]
},
},
[
c(
'text',
{
styles: {
lineHeight: 20,
color:'#fff',
textAlign:'center',
fontSize: 11,
},
},
text
),
]
)
}
easyCanvas.component('button',(opt,children,c) => button(c,children))
const node = easyCanvas.createElement((c) => {
return c('view',{},[
c('button',(),'This is a global component')
])
})
...
TodoList
- Support position
- inline-block line break and textAlign
- Realize attribute inheritance through the stack
- Support flex-direction
- box-shadow to be optimized
- Compatible with small program measuretext
- Compatible with applet image
- Packing problem solved
- scroll-view nesting~~~~translate value inheritance
- Supplement other attributes
- image supports mode
- Release npm
- max-width
- vue template support
- Scroll-view click area judgment optimization
- Remove event when removing element
- Scrolling optimization
- Render on demand
- zIndex Hurry! ! !
Known issues
- Linear-gradient must be created in the view to take effect
- If there is a problem with the element event judgment that is not in the document flow, it will be triggered together with the following elements
MIT License
Copyright (c) 2020 Gitjinfeiyang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTW
Explore related projects
Loading…