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

docs: Add example for data structures #595

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,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)
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)
)