Skip to content

Commit

Permalink
Display selected tile
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine committed Nov 25, 2024
1 parent a56f138 commit 0828fa5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
13 changes: 8 additions & 5 deletions src/App.civet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
solid-js import { createMemo, createSignal, For, Index }
solid-js import { createMemo, createSelector, createSignal, For, Index }
solid-js/store import { createStore }
@thisbeyond/solid-dnd import {
DragDropProvider
Expand All @@ -17,7 +17,8 @@ export function App()
[numTiles, setNumTiles] := createSignal tiles#
glues := colors
[zoom, setZoom] := createSignal 1
[selected, setSelected] := createSignal 0
[selected, setSelected] := createSignal<number?>()
isSelected := createSelector selected
signed := createMemo => unsignedToSigned tiles[..<numTiles()], glues()

function onDragEnd({draggable, droppable})
Expand Down Expand Up @@ -56,7 +57,8 @@ export function App()
>+
<Index each=tiles[..<numTiles()]>
(tile, id) =>
<Tile {tile(), id} onClick={=> setSelected id}>
<Tile {tile(), id}
selected={isSelected id} onClick={=> setSelected id}>
<hr>
<h2>Intermediate: Signed Tiles
<h3>{signed().glues} Glues with 2 Different Signs
Expand All @@ -70,7 +72,8 @@ export function App()
<.tiles>
<Index each=signed().tiles>
(tile, id) =>
<SignedTile {tile(), signed().glues} onClick={=> setSelected id}>
<SignedTile {tile(), signed().glues}
selected={isSelected id} onClick={=> setSelected id}>
<hr>
<h2>Output: Three Tiles
<span .postfix>🔍
Expand All @@ -88,4 +91,4 @@ export function App()
>
Show glues
<div .container>
<ThreeTiles {zoom(), selected()} ...signed()>
<ThreeTiles {zoom()} selected={selected() ?? 0} ...signed()>
8 changes: 4 additions & 4 deletions src/Tile.civet
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export type Prototile
tileSize := 50
glueSize := 13

export function Tile(props: {tile: Prototile, id: number, onClick: any})
export function Tile(props: {tile: Prototile, id: number, selected: boolean, onClick: any})
droppableN := createDroppable 4*props.id+0, 'n'
droppableW := createDroppable 4*props.id+1, 'w'
droppableS := createDroppable 4*props.id+2, 's'
droppableE := createDroppable 4*props.id+3, 'e'
<svg .tile viewBox=`0 0 ${tileSize} ${tileSize}`>
<svg .tile viewBox=`0 0 ${tileSize} ${tileSize}` classList={{props.selected}}>
<rect .background width=tileSize height=tileSize {props.onClick}>
<polygon .glue fill=color(props.tile.n) stroke="#444" points=
`0,0 ${glueSize},${glueSize} ${tileSize - glueSize},${glueSize} ${tileSize},0`
Expand All @@ -36,9 +36,9 @@ export function Tile(props: {tile: Prototile, id: number, onClick: any})
>
<!--<rect .outline width=tileSize height=tileSize>-->

export function SignedTile(props: {tile: Prototile, glues: number, onClick: any})
export function SignedTile(props: {tile: Prototile, glues: number, selected: boolean, onClick: any})
strokeWidth := 1.5
<svg .tile viewBox=`${-strokeWidth/2} ${-strokeWidth/2} ${tileSize + strokeWidth} ${tileSize + strokeWidth}`>
<svg .tile viewBox=`${-strokeWidth/2} ${-strokeWidth/2} ${tileSize + strokeWidth} ${tileSize + strokeWidth}` classList={{props.selected}}>
<rect .background width=tileSize height=tileSize {props.onClick}>
<polygon .glue fill=color(Math.abs(props.tile.n) - 1, props.glues) points=
`0,0 ${glueSize},${glueSize} ${tileSize - glueSize},${glueSize} ${tileSize},0`
Expand Down
4 changes: 3 additions & 1 deletion src/index.sass
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ a, a:visited

.tiles
display: flex
gap: 3px
gap: 5px
flex-wrap: wrap

.tile
width: 50px
height: 50px
&.selected
outline: 3px dotted yellow
> .background
fill: gray
> .outline
Expand Down

0 comments on commit 0828fa5

Please # to comment.