榆树 - 表格检查

时间:2016-04-07 11:04:11

标签: forms element dimensions elm inspection

以下功能包括使用collage,仅用于转换 形状/形状成元素。

makeSlider : Element -> Form -> Element
makeSlider sliderShape sliderBarForm =
  let                                                                                                 
    sliderBar =
      --convert sliderBarForm from type Form to Element
      collage 1000 1000 [(move (0,0) sliderBarForm)]
  in 
    layers [sliderShape, sliderBar]

有没有办法提取表单的维度,例如Graphics.Element.sizeOf,以便makeSlider函数不需要知道sliderBarForm的显式维度?

或者toElement函数是否存在以便

collage 1000 1000 [(move (0,0) sliderBarForm)]

可以替换为

toElement (move (0,0) sliderBarForm)

1 个答案:

答案 0 :(得分:3)

我认为你不能轻易获得表格的尺寸。我想这是因为一个表格可以有很多种不同的东西(形状,路径等)。当我需要稍后知道尺寸时,我会在创建表单时跟踪它们。

type alias MyForm =
  {   form : Form
    , width : Int
    , height : Int
  }

makeRectForm: Float -> Float -> MyForm
makeRectForm  w h = {form: (filled grey (rect w h)), width: (round w), height: (round h)}

然后,在您的情况下,您可以MyForm使用collage

makeSlider : Element -> MyForm -> Element
makeSlider sliderShape sliderBarMyForm =
  let                                                                                                 
    sliderBar =
      --convert sliderBarForm from type Form to Element
      collage sliderBarMyForm.width sliderBarMyForm.height [(move (0,0) sliderBarMyForm)]
  in 
    layers [sliderShape, sliderBar]