fillStyle如何在bs-webapi Canvas2d中工作 [英] How does fillStyle work in bs-webapi Canvas2d

查看:121
本文介绍了fillStyle如何在bs-webapi Canvas2d中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在ReasonML中使用bs-webapi和Canvas2d接口创建a并设置填充样式。

I'm wondering how to create a and set a fill style using bs-webapi and Canvas2d interface in ReasonML.

我认为我可能需要的定义是< a href = https://github.com/reasonml-community/bs-webapi-incubator/blob/master/src/Webapi/Webapi__Canvas/Webapi__Canvas__Canvas2d.re#L139 rel = nofollow noreferrer>此 :

I think the definition I might need is this:

let fillStyle = (ctx: t) =>
  ctx |> fillStyle |> reifyStyle;

但是我很难理解它。

我以前使用过此项目作为示例来源,但我认为自该项目创建以来,bs-webapi发生了变化。至少在该示例之后建模的以下行:

I have previously used this project as a source of examples, but I think the bs-webapi has changed since that project was authored. At least the following line modeled after the example:

Canvas2d.fillStyle(ctx, "rgba(0,255,255,255)");

给我这个错误:

Error: This function has type
         Webapi.Canvas.Canvas2d.t => (Webapi.Canvas.Canvas2d.style('a), 'a)
       It is applied to too many arguments; maybe you forgot a `;'.


推荐答案

您想要的功能是 setFillStyle

Canvas2d.setFillStyle(ctx, String, "rgba(0,255,255,255)");

这是从 fillStyle 重命名的,因为那时还没有吸气剂,所以惯例是将吸气剂命名为 fillStyle ,将其命名为 setFillStyle

This was renamed from fillStyle long ago, because there was no getter back then and the convention is to name the getter fillStyle and the setter setFillStyle. At the same time it was made to support gradients and pattern.

setFillStyle 现在起作用的方式是第二个参数确定第三个的类型。如果传递 String 作为第二个参数,则第三个参数必须是 string 。如果通过 Gradient ,则必须是 gradient ,您可以从 createLinearGradient createRadialGradient 。最后,您可以传递 Pattern ,这要求第三个参数是从 createPattern获得的模式

The way setFillStyle now works is that the second argument determines the type of the third. If you pass String as the second argument, the third is required to be a string. If you pass Gradient it needs to be a gradient, which you can get from createLinearGradient or createRadialGradient. And lastly you can pass Pattern, which requires the third argument be a pattern obtained from createPattern.

通常,您应该参考 Canvas2d测试文件以获取用法示例。

In general, you should refer to the Canvas2d test file for usage examples.

这篇关于fillStyle如何在bs-webapi Canvas2d中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆