"패널"을 클릭 한 후 "statusField"를 업데이트하는 방법에 대한 조언이 필요합니다.wxhaskell : 패널의 "클릭 할 때"를 사용하여 statusField 업데이트
다음 프로그램은 문제를 보여줍니다. 이 프로그램은 두 개의 프레임을 그립니다 ( ). 왼쪽 프레임이 그림 영역 일 것이라고 상상할 수 있으며 오른쪽 프레임에는 "빨강"과 "녹색"버튼이 있습니다. "빨간색"이라고 표시된 버튼을 클릭 한 후 statusField의 텍스트는 이 "현재 색상 : 빨간색"으로 업데이트되었습니다. "녹색"레이블이 붙은 단추는 텍스트를 "현재 색 : 녹색"으로 업데이트합니다.
사용자가 왼쪽 패널 을 클릭 한 후 statusField 텍스트를 변경하는 방법은 무엇입니까? 예 : " 드로잉 패널을 성공적으로 클릭했습니다."로 변경하십시오.
버튼의 "on 명령"과 같은 방식으로 "클릭"에서 수행 할 수없는 이유는 무엇입니까? (아래 소스의 주석을 참조하십시오.)
고맙습니다.
module Main where
import Graphics.UI.WX
-- | NOP (= No Operation)
data Command = Nop
| Red
| Green
deriving (Eq)
main :: IO()
main
= start hello
hello :: IO()
hello
= do currentCommand <- varCreate $ Nop -- current command performed on next click on "pDrawingarea"
status <- statusField [text := "Welcome."]
-- Frames and Panels
f <- frame [ text := "Demo"
, bgcolor := lightgrey ]
pButtons <- panel f [ bgcolor := lightgrey]
pDrawingarea <- panel f [ on paint := draw
, bgcolor := lightgrey
]
set pDrawingarea [on click := do drawingAreaOnClick status currentCommand pDrawingarea
-- set status [text := "User clicked on the panel."]
-- Problem: uncommenting the line above shows the problem
]
bRed <- button pButtons [text := "Red", on command := do varSet currentCommand Red
set status [text := "Current color: Red"]
]
bGreen <- button pButtons [text := "Green", on command := do varSet currentCommand Green
set status [text := "Current color: Green"]
]
set pButtons [ layout := column 1 [ hstretch.expand $ widget bRed
, hstretch.expand $ widget bGreen
]
]
set f [ statusBar := [status]
, layout := row 3 [
minsize (sz 600 500) $ stretch.expand $ widget pDrawingarea
, vstretch.expand $ rule 3 500
, minsize (sz 200 500) $ vstretch.expand $ widget pButtons
]
]
return()
draw :: DC a -> Rect -> IO()
draw dc viewArea
= do putStrLn "Imagine some code to repaint the screen."
drawingAreaOnClick :: statusField -> Var Command -> Panel() -> Point -> IO()
drawingAreaOnClick sf command panel pt
= do c <- varGet command
case c of
Red -> do putStrLn "Imagine some code to do red painting"
Green -> do putStrLn "Imagine some code to do green painting"