<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gitjinfeiyang</title>
    <description>The latest articles on DEV Community by Gitjinfeiyang (@gitjinfeiyang).</description>
    <link>https://dev.to/gitjinfeiyang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F489149%2Fbe5c3986-dd2b-4f4b-9448-6cb1b283c7c4.jpeg</url>
      <title>DEV Community: Gitjinfeiyang</title>
      <link>https://dev.to/gitjinfeiyang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gitjinfeiyang"/>
    <language>en</language>
    <item>
      <title>Create document flow in canvas</title>
      <dc:creator>Gitjinfeiyang</dc:creator>
      <pubDate>Wed, 14 Oct 2020 02:45:25 +0000</pubDate>
      <link>https://dev.to/gitjinfeiyang/create-document-flow-in-canvas-29ci</link>
      <guid>https://dev.to/gitjinfeiyang/create-document-flow-in-canvas-29ci</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Use the render function to create a document flow in the canvas and quickly implement the layout.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://github.com/Gitjinfeiyang/easy-canvas"&gt;Respontory&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If there is a problem in use, check the code in the example, click to view &lt;a href="https://gitjinfeiyang.github.io/easy-canvas/example/"&gt;DEMO&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/Fiyoung/pen/pobvWRa?editors=1010"&gt;Try it in CodePen&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;vue component &lt;a href="https://github.com/Gitjinfeiyang/vue-easy-canvas"&gt;vue-easy-canvas&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Support document flow, refer to web, no need to set x, y, width and height&lt;/li&gt;
&lt;li&gt;Compatible with small programs and web, no third-party dependencies&lt;/li&gt;
&lt;li&gt;Support componentization, global components and local components&lt;/li&gt;
&lt;li&gt;Support events&lt;/li&gt;
&lt;li&gt;High performance, scroll-view supports dirty rectangles and only draws the visible part&lt;/li&gt;
&lt;li&gt;Support operation element, similar to operation dom to modify document flow&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Supporting elements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[x] &lt;code&gt;view&lt;/code&gt; basic element, similar to div&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;text&lt;/code&gt; text supports automatic line wrapping and over omitted functions, currently text is implemented as inline-block&lt;/li&gt;
&lt;li&gt;[x] ʻimage&lt;code&gt;image&lt;/code&gt;src&lt;code&gt;&lt;/code&gt;mode&lt;code&gt;supports aspectFit and aspectFill, other css features are the same as web support&lt;/code&gt;load` event to monitor image loading and drawing completion&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;scroll-view&lt;/code&gt; scroll container, you need to set &lt;code&gt;direction&lt;/code&gt; in the style to support x, y, xy, and set the specific size. Set &lt;code&gt;renderOnDemand&lt;/code&gt; to draw only the visible part&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Styles
&lt;/h2&gt;

&lt;p&gt;Use numbers where the attribute uses pixels&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[x] &lt;code&gt;display&lt;/code&gt; block | inline-block | flex, text is inline by default&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;width&lt;/code&gt; auto 100% Number This box model uses border-box and cannot be modified&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;height&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;flex&lt;/code&gt; flex does not support auto, use width directly for fixed width&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;minWidth&lt;/code&gt; &lt;code&gt;maxWidth&lt;/code&gt; &lt;code&gt;minHeight&lt;/code&gt; &lt;code&gt;maxHeight&lt;/code&gt; If the specific width is set, the height will not take effect&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;margin&lt;/code&gt; &lt;code&gt;marginLeft&lt;/code&gt;,&lt;code&gt;marginRight&lt;/code&gt;,&lt;code&gt;marginTop&lt;/code&gt;,&lt;code&gt;marginBottom&lt;/code&gt; margin supports array abbreviations such as [10,20] [10,20,10,20]&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;paddingLeft&lt;/code&gt;,&lt;code&gt;paddingRight&lt;/code&gt;,&lt;code&gt;paddingTop&lt;/code&gt;,&lt;code&gt;paddingBottom&lt;/code&gt; Same as above&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;backgroundColor&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;borderRadius&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;borderWidth&lt;/code&gt; &lt;code&gt;borderTopWidth&lt;/code&gt; ... Set the thin border directly to 0.5&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;borderColor&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;lineHeight&lt;/code&gt; font related only valid in text&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;color&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;fontSize&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;textAlign&lt;/code&gt; left right center&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;textIndent&lt;/code&gt; Number&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;verticalAlign&lt;/code&gt; top middle bottom&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;justifyContent&lt;/code&gt; flex-start center flex-end flex layout align horizontally&lt;/li&gt;
&lt;li&gt;[x] ʻalignItems` flex-start center flex-end flex layout align it vertically&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;maxLine&lt;/code&gt; maximum number of lines, exceeding the automatic ellipsis, only supports use in text&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;whiteSpace&lt;/code&gt; normal nowrap controls line breaks, not fonts&lt;/li&gt;
&lt;li&gt;[x] ʻoverflow` hidden If rounded corners are added, hidden will be added automatically&lt;/li&gt;
&lt;li&gt;[] &lt;code&gt;flexDirection&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;borderStyle&lt;/code&gt; dash Array See ctx.setLineDash() for details&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;shadowBlur&lt;/code&gt; set the shadow will automatically add overflow:hidden;&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;shadowColor&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;shadowOffsetX&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;shadowOffsetY&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[x] &lt;code&gt;position&lt;/code&gt; &lt;code&gt;static&lt;/code&gt; ʻabsolute`&lt;/li&gt;
&lt;li&gt;[x] ʻopacity&lt;code&gt;&lt;/code&gt;Number`&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
npm install easy-canvas-layout --save&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Basic
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;` javascript&lt;br&gt;
    import easyCanvas from'easy-canvas-layout'&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 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) =&amp;gt; {
  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)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Register Component
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;` javascript&lt;br&gt;
    ...&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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) =&amp;gt; button(c,children))

const node = easyCanvas.createElement((c) =&amp;gt; {
  return c('view',{},[
    c('button',(),'This is a global component')
  ])
})

...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>canvas</category>
      <category>css</category>
    </item>
  </channel>
</rss>
