Skip to content

Commit

Permalink
docs: Add example for data structures (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
PrettyCoffee authored Aug 25, 2024
1 parent 452cab7 commit 96529d3
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ If you want to display a list of values, you can use the `for`-Element to fill a
This can be useful in many situations, for example when generating a workspace list from a JSON representation of your workspaces.
In many cases, this can be used instead of `literal`, and should most likely be preferred in those cases.

To see how to declare and use more advanced data structures, check out the [data structures example](/examples/data-structures/eww.yuck).

## Splitting up your configuration

As time passes, your configuration might grow larger and larger. Luckily, you can easily split up your configuration into multiple files!
Expand Down
4 changes: 4 additions & 0 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ These configurations of eww are available in the `examples/` directory of the [r

An eww bar configuration:
![Example bar](https://github.com/elkowar/eww/raw/master/examples/eww-bar/eww-bar.png)

A demo on how to declare and use data structures:

![Data structure example](/examples/data-structures/data-structures-preview.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions examples/data-structures/eww.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
* {
all: unset;
}

.layout {
padding: 8px;
border: 1px solid black;
border-radius: 4px;
background-color: bisque;
font-size: 16px;
color: black;
}

.animalLayout {
margin: 0 4px;
}

.animal {
font-size: 24px;
transition: 0.2s;
border-radius: 4px;
background-color: rgba(0, 0, 0, 0);
border: 0 solid lightcoral;
}

.animal.selected {
background-color: rgba(0, 0, 0, 0.2);
border-width: 2px;
}
73 changes: 73 additions & 0 deletions examples/data-structures/eww.yuck
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
(defvar stringArray `[
"🦝",
"🐱",
"🐡",
"🦁",
"🐹",
"🦊"
]`)

(defvar object `{
"🦝": "racoon",
"🐱": "cat",
"🐡": "ape",
"🦁": "lion",
"🐹": "hamster",
"🦊": "fox"
}`)

; You could also create an array of objects:
; (defvar objectArray `[{ "emoji": "🦝", "name": "racoon" }, { "emoji": "🦊", "name": "fox" }]`)

(defvar selected `🦝`)

(defwidget animalButton [emoji]
(box
:class "animalLayout"
(eventbox
:class `animal ${selected == emoji ? "selected" : ""}`
:cursor "pointer"
:onhover "eww update selected=${emoji}"
emoji
)
)
)

(defwidget animalRow []
(box
:class "animals"
:orientation "horizontal"
:halign "center"
(for animal in stringArray
(animalButton
:emoji animal
)
)
)
)

(defwidget currentAnimal []
(box
`${object[selected]} ${selected}`
)
)

(defwidget layout []
(box
:class "layout"
:orientation "vertical"
:halign "center"
(animalRow)
(currentAnimal)
)
)

(defwindow data-structures
:monitor 0
:exclusive false
:focusable false
:geometry (geometry
:anchor "center"
)
(layout)
)

0 comments on commit 96529d3

Please sign in to comment.