Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event handling #3

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions examples/hello-rect/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ All this is to draw a rectangle.
import Browser
import Color exposing (..)
import Html exposing (..)
import Techdraw exposing (Drawing, fill, path, render, stroke, strokeWidth, transform)
import Techdraw
exposing
( Drawing
, fill
, onMouseEnter
, onMouseLeave
, path
, render
, stroke
, strokeWidth
, transform
)
import Techdraw.Internal.Util exposing (unsafeForceMaybe)
import Techdraw.Math exposing (Scale(..), affScale)
import Techdraw.PathBuilder as PathBuilder exposing (close, createPath, lineTo, moveTo)
Expand All @@ -26,12 +37,12 @@ type Model

type Msg
= MouseEnter
| MouseExit
| MouseLeave


init : Model
init =
Model { color = red }
Model { color = blue }


rectangle =
Expand All @@ -45,14 +56,16 @@ rectangle =
|> unsafeForceMaybe "Path should be valid."


drawing : Model -> Drawing msg
drawing : Model -> Drawing Msg
drawing (Model model) =
path rectangle
|> fill (Paint model.color)
|> stroke (Paint black)
|> strokeWidth 2
|> transform (affScale <| Scale 2 2)
|> transform (affScale <| Scale 5 5)
|> onMouseEnter (\_ -> MouseEnter)
|> onMouseLeave (\_ -> MouseLeave)


view : Model -> Html Msg
Expand All @@ -71,7 +84,7 @@ update msg (Model model) =
MouseEnter ->
Model { model | color = red }

MouseExit ->
MouseLeave ->
Model { model | color = blue }


Expand Down
Loading