Haskell:wxHaskell 中的网格

发布于 2024-09-01 08:56:01 字数 384 浏览 4 评论 0原文

有人可以逐行解释一下这段代码的作用吗?

如何准确理解声明的第一行? [Prop (Grid ())] 是什么意思?

谢谢你的帮助

gridCtrl :: Window a -> [Prop (Grid ())] -> IO (Grid ())
gridCtrl parent props
  = feed2 props 0 $
    initialWindow $ \id rect -> \props flags ->
    do g <- gridCreate parent id rect flags
       gridCreateGrid g 0 0 0
       set g props
       return g

Could someone explain me what this code does line by line ?

how t ounderstand excactly first line with declaration ?
what does it mean: [Prop (Grid ())]?

thanks for help

gridCtrl :: Window a -> [Prop (Grid ())] -> IO (Grid ())
gridCtrl parent props
  = feed2 props 0 $
    initialWindow $ \id rect -> \props flags ->
    do g <- gridCreate parent id rect flags
       gridCreateGrid g 0 0 0
       set g props
       return g

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为你鎻心 2024-09-08 08:56:01

在 wxHaskell 中,控件具有可以读取或更改的附加属性。 [Prop (Grid ())] 节可以理解为“任何 Grid 类型的属性列表”。

这是 wxHaskell 处理 wxWidgets 库(它所构建的库)是面向对象这一事实的方式。 Grid () 实际上意味着“Grid 派生的继承层次结构中的任何内容” - 即 Grid、ScrolledWindow、Panel、Window、EvtHandler、wxObject(如果您从 http://wxhaskell.sourceforge.net/doc/Graphics-UI-WXCore-WxcClassTypes.html#204< /a>)

当您查看控件(例如ListCtrl)的文档时,您会发现它被报告为具有一组属性和实例。基本上,您可以使用适用于网格层次结构的那些。例如,Grid 派生自ScrolledWindow,因此您可以使用:

  • 属性scrollRate
  • Colored 类的属性,例如bgcolor、颜色
  • 等。

您按如下方式使用这些属性,例如

g <- gridCtrl parent [color := red, bgcolor := green, scrollRate := 41]
...
set g [color := blue]

逐行,代码如下所示:

  • 使用提供的属性( props
  • 和一个initialWindow(它将填充窗口id和初始矩形标志< /strong>),按顺序调用以下包装函数:
  • gridCreate 创建一个新的网格实例
  • 使用新的网格实例,将网格设置为 0 行、0 列且未选择任何内容。
  • 将调用者提供的属性(props)应用到网格(例如,放入数据、设置样式等)。

使代码最难阅读的部分是feed2函数,并且代码是以“$”样式编写的,以便为 feed2 提供正确的参数。我上面的解释应该足够了,但是如果你想了解细节,请理解 feed2 只是由倒置函数应用程序组成,

feed2 x y f = f x y

然后用括号替换“$”应用程序。这看起来不那么可爱,但更容易阅读。

gridCtrl parent props =
  feed2 props 0
    (initialWindow (\id rect ->
                      \props flags ->
                        do
                        g <- gridCreate parent id rect flags
                        gridCreateGrid g 0 0 0
                        set g props
                        return g )))

In wxHaskell, controls have attached properties which can be read or changed. The stanza [Prop (Grid ())] can be understood as "a list of properties for any Grid type".

This is wxHaskell's way of dealing with the fact that the wxWidgets library, which it is built on, is object-oriented. Grid () actually means "anything in the inheritance hierarchy from which Grid derives" - i.e. Grid, ScrolledWindow, Panel, Window, EvtHandler, wxObject (you can follow this through if you start at at http://wxhaskell.sourceforge.net/doc/Graphics-UI-WXCore-WxcClassTypes.html#204)

When you look at the documentation of a Control (e.g. ListCtrl) you will find that it is reported as having a set of Attributes and Instances. Basically, you can use those which apply to the hierarchy for Grid. For example, Grid derives from ScrolledWindow, so you can use:

  • Attribute scrollRate
  • Attributes of Colored class e.g. bgcolor, color
  • etc.

You use these properties as follows, e.g.

g <- gridCtrl parent [color := red, bgcolor := green, scrollRate := 41]
...
set g [color := blue]

Line by line, the code reads something like the following:

  • Using the supplied properties (props)
  • and an initialWindow (which will fill in the window id and initial rect and flags), call the floowing wrapped functions in order:
  • gridCreate to create a new Grid instance
  • Using the new grid instance, set the grid inside with 0 rows, 0 columns and nothing selected.
  • Apply the properties (props) supplied by the caller to the grid (e.g. put data in, set styles etc.)

The part which makes the code hardest to read is the feed2 function, and that fact that the code is written in '$' style to provide the correct parameters to feed2. My slightly hand-waving explanation above should be enough, but if you want to understand the details, understand that feed2 is just composed inverted function application

feed2 x y f = f x y

then replace the '$' applications with parentheses. This doesn't look as cute, but is easier to read.

gridCtrl parent props =
  feed2 props 0
    (initialWindow (\id rect ->
                      \props flags ->
                        do
                        g <- gridCreate parent id rect flags
                        gridCreateGrid g 0 0 0
                        set g props
                        return g )))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文