入门
开发指南
- 模块
- 控件基础知识
- 控件树
- 选择器 API
- 布局
- 手势和触摸事件
- W3C APIs 兼容
- Cordova 插件支持
- EcmaScript 6,TypeScript 和 JSX
- Windows 10 支持说明
- 构建 Tabris.js App
- Tabris.js App 补丁
API 参考文档
- app
- device
- fs
- localStorage
- ui
- ActionSheet(操作列表)
- AlertDialog(对话框)
- CanvasContext
- InactivityTimer(闲置定时器)
- NativeObject
- Popup(弹出窗)
- Timer(计时器)
- WidgetCollection
控件
- Action
- ActivityIndicator
- Button
- Canvas
- CheckBox
- CollectionView
- Composite
- Drawer
- ImageView
- NavigationBar
- NavigationView
- Page
- Picker
- ProgressBar
- RadioButton
- ScrollView
- SearchAction
- Slider
- StatusBar
- Switch
- Tab
- TabFolder
- TextInput
- TextView
- ToggleButton
- Video
- WebView
- Widget
自定义控件
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
Canvas
Extends Composite
Canvas is a widget that can be used to draw graphics using a canvas context.
Import this type with “const {Canvas} = require('tabris');
”
Example:
new Canvas({
left: 0, top: 0, right: 0, bottom: 0
}).on("resize", ({target: canvas, width, height}) => {
let ctx = canvas.getContext("2d", width, height);
ctx.moveTo(0, 0);
// ...
}).appendTo(page);
Methods
getContext(contextType, width, height)
Parameters:
- contextType: string
- the context identifier. Only
"2d"
is currently supported.
- the context identifier. Only
- width: number
- the width of the canvas context to create
- height: number
- the height of the canvas context to create
Returns: CanvasContext
Returns the drawing context with the given size.
Example
const {Canvas, ui, device} = require('tabris');
// Draw shapes on a canvas using HTML5 Canvas API
new Canvas({
left: 10, top: 10, right: 10, bottom: 10
}).on('resize', ({target: canvas, width, height}) => {
let scaleFactor = device.scaleFactor;
let ctx = canvas.getContext('2d', width * scaleFactor, height * scaleFactor);
ctx.scale(scaleFactor, scaleFactor);
ctx.strokeStyle = 'rgb(78, 154, 217)';
ctx.lineWidth = 10;
ctx.moveTo(20, 20);
ctx.lineTo(width - 40, height - 40);
ctx.stroke();
// draw image
ctx.putImageData(createImageData(80, 40), 100, 100);
// copy region
let data = ctx.getImageData(0, 0, 100, 100);
ctx.putImageData(data, 180, 100);
}).appendTo(ui.contentView);
function createImageData(width, height) {
let array = [];
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
let alpha = x % 20 > y % 20 ? 255 : 0;
array.push(200, 0, 0, alpha);
}
}
return new ImageData(new Uint8ClampedArray(array), width, height);
}
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论