Skip to content

Commit

Permalink
Merge pull request #6 from llMBQll/feature/gifs
Browse files Browse the repository at this point in the history
- Added support for animated images.
- Refactored animation handling to support multiple independent applications.
- Updated a few widget properties.
  • Loading branch information
llMBQll authored Jan 20, 2025
2 parents ed27ac3 + b4f7a02 commit 34cef93
Show file tree
Hide file tree
Showing 23 changed files with 1,195 additions and 506 deletions.
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions config/scripts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ local function volume()
Text {
text = AUDIO.IsMuted and 'Muted' or AUDIO.Volume,
font_size = 24,
text_offset = 'AutoUpper',
text_offset = 1,
position = { x = 0, y = 0 },
size = { width = SCREEN.Width, height = SCREEN.Height / 2 },
},
Text {
text = AUDIO.Name,
scrolling = true,
repeats = 'Once',
position = { x = 0, y = SCREEN.Height / 2 },
size = { width = SCREEN.Width, height = SCREEN.Height / 2 },
},
},
duration = 2000,
repeats = 'Once',
}
end

Expand Down Expand Up @@ -55,7 +55,6 @@ local function spotify()
},
},
duration = SPOTIFY_DURATION,
repeats = 'ForDuration',
}
end

Expand All @@ -65,14 +64,14 @@ local function clock()
Text {
text = string.format("%02d", CLOCK.Hours),
font_size = 50,
text_offset = 'AutoUpper',
text_offset = 1,
position = { x = 10, y = 0 },
size = { width = SCREEN.Width / 2, height = SCREEN.Height - 3 },
},
Text {
text = string.format("%02d", CLOCK.Minutes),
font_size = 37,
text_offset = 'AutoUpper',
text_offset = 1,
position = { x = SCREEN.Width / 2 + 3, y = 0 },
size = { width = 54, height = 26 },
},
Expand Down Expand Up @@ -113,7 +112,7 @@ local function weather()
Text {
text = value,
font_size = 30,
text_offset = 'AutoUpper',
text_offset = 1,
position = { x = SCREEN.Height, y = 0 },
size = { width = SCREEN.Height * 2, height = SCREEN.Height * 2 / 3 },
},
Expand Down
230 changes: 161 additions & 69 deletions docs/scripting_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@
> >
> > Load for a system-installed font.
---

> ### `FontSize`
>
> Specifies the text font size inside of `Text` widget.
>
> > `Auto`
> >
> > Calculate font size to fit any text in the widget's height.
>
> > `AutoUpper`
> >
> > Calculate font size to fit any text that doesn't have any "descendants". Useful for text that
> > consists only of uppercase characters or numbers.
>
> > `n: integer`
> >
> > Set font size to be exactly `n`, regardless of widget size.
---

> ### `FontStretch`
Expand Down Expand Up @@ -215,6 +234,44 @@
---

> ### `ImageFormat`
>
> Image format.
>
> > `Avif`
>
> > `Bmp`
>
> > `Dds`
>
> > `Farbfeld`
>
> > `Gif`
>
> > `Hdr`
>
> > `Ico`
>
> > `Jpeg`
>
> > `OpenExr`
>
> > `Pcx`
>
> > `Png`
>
> > `Pnm`
>
> > `Qoi`
>
> > `Tga`
>
> > `Tiff`
>
> > `Webp`
---

> ### `LogLevel`
>
> Log level filter, selecting one value will also activate all values above it, e.g. enabling
Expand Down Expand Up @@ -261,38 +318,20 @@
---

> ### `Offset`
>
> Specifies the text offset from the bottom of a `Text` widget.
>
> > `Auto`
> >
> > Calculate offset to fit any text in the widget's height.
>
> > `AutoUpper`
> >
> > Calculate offset to fit any text that doesn't have any "descendants". Useful for text that
> > consists only of uppercase characters or numbers.
>
> > `n: integer`
> >
> > Offset exactly by `n` pixels, regardless of font size.
---

> ### `Repeat`
>
> Repeat strategy for a widget. Currently, this only applies to scrolling text.
> Repeat strategy for a widget. Applies to scrolling text and animated images.
>
> > `Once`
> >
> > Repeats the script until the text is fully scrolled, even if it takes longer than the duration
> > specified for layout. This way the entire text is displayed exactly once.
> > Repeats the script until the animation is finished, even if it takes longer than the duration
> > specified for layout. This way the entire animation is displayed exactly once.
>
> > `ForDuation`
> >
> > Repeats the script for the time of its duration. This will scroll text for an exact duration,
> > but can cut off mid-scrolling if the time runs out.
> > Repeats the script for the time of its duration. This will run the animation for an exact
> > duration,
> > but can cut off mid-animation if the time runs out.
## Functions

Expand Down Expand Up @@ -442,6 +481,20 @@
---

> ### `ImageData`
>
> Contains image bytes and format
>
> > `format`: `ImageFormat`
> >
> > Image format, required to properly load image bytes.
>
> > `bytes`: `[byte]`
> >
> > Image bytes stored in format specified by the `format` property.
---

> ### `Layout`
>
> Represents a user-defined script that runs on specific events and creates a layout to be rendered.
Expand Down Expand Up @@ -477,12 +530,6 @@
> > How many milliseconds can the layout be shown on the screen before it's allowed to be
> > overridden. Higher priority layouts can always override lower priority, regardless of the
> > remaining duration.
>
> > `repeats: Repeat`
> >
> > _Optional_. Default: `Once`.
> >
> > Specifies the repeat strategy, which is only applicable to scrolling text for now.
---

Expand Down Expand Up @@ -516,23 +563,6 @@
---

> ### `OledImage`
>
> Represents a black-and-white image.
>
> > `size`: `Size`
> >
> > Source image size. To adjust image size on screen, set the appropriate widget size to the
> > desired value.
>
> > `bytes`: `[byte]`
> >
> > Row-major black-and-white image data with one byte per pixel. All non-zero values will result
> > in the pixels being on.
> > `size.width * size.height` must equal the length of the `bytes` array.
---

> ### `Point`
>
> Represents a coordinate in a 2D space with an origin `(0, 0)` in the top left corner of the
Expand Down Expand Up @@ -646,23 +676,6 @@
---

#[mlua(transform(from_hex))]
pub vendor_id: u16,
#[mlua(transform(from_hex))]
pub product_id: u16,
#[mlua(transform(from_hex))]
pub interface: u8,
#[mlua(transform(from_hex))]
pub alternate_setting: u8,
#[mlua(transform(from_hex))]
pub request_type: u8,
#[mlua(transform(from_hex))]
pub request: u8,
#[mlua(transform(from_hex))]
pub value: u16,
#[mlua(transform(from_hex))]
pub index: u16,

> ### `USBSettings`
>
> Configuration for a USB device. All fields relate to the USB configuration.
Expand Down Expand Up @@ -747,10 +760,57 @@ All widgets have the following common attributes in addition to widget-specific
>
> A widget that displays an image.
>
> > `image`: `OledImage`
> > `image`: `ImageData`
> >
> > The image data to display on the screen.
> > This image will be scaled from its original size to the dimensions of the widget.
>
> > `animated`: `bool`
> >
> > _Optional_. Default: `false`
> >
> > Specifies if the image should be animated. Unless set to `true`, event with supported image
> > formats, only a static image will be rendered.
>
> > `animation_group`: `integer`
> >
> > _Optional_. Default: `0`
> >
> > Sets the animation group for the widget. All animations within a single animation group are
> > synced,
> > except for the default group `0`, where all animations are independent.
>
> > `animation_ticks_delay`: `integer`
> >
> > _Optional_. Default: No value
> >
> > Overrides [global animation setting](settings.md#animation) for this widget. Applies only for
> > `animated` images.
> >
> > **Changing this value after initially setting it for a given widget is undefined behaviour.**
>
> > `animation_ticks_rate`: `integer`
> >
> > _Optional_. Default: No value
> >
> > Overrides [global animation setting](settings.md#animation) for this widget. Applies only for
> > `animated` images.
> >
> > **Changing this value after initially setting it for a given widget is undefined behaviour.**
>
> > `repeats: Repeat`
> >
> > _Optional_. Default: `ForDuration`.
> >
> > Specifies the repeat strategy, applies only for animated images.
>
> > `threshold`: `integer`
> >
> > _Optional_. Default: `128`
> >
> > Specifies the threshold from range `[0, 255]` used to convert image to a black and white image.
> > Light values below the threshold will be converted to black, and values above the threshold will
> > be converted to white.
---

Expand All @@ -768,14 +828,46 @@ All widgets have the following common attributes in addition to widget-specific
> >
> > Specifies if the text should scroll if it is too long to fit within the widget's width.
>
> > `font_size`: `integer`
> > `animation_group`: `integer`
> >
> > _Optional_. Default: Calculated to fit within the widget's height.
> > _Optional_. Default: `0`
> >
> > Sets the font size of the text.
> > Sets the animation group for the widget. All animations within a single animation group are
> > synced,
> > except for the default group `0`, where all animations are independent.
>
> > `text_offset`: `Offset`
> > `animation_ticks_delay`: `integer`
> >
> > _Optional_. Default: No value
> >
> > Overrides [global animation setting](settings.md#animation) for this widget. Applies only for
> > `scrolling` text.
> >
> > **Changing this value after initially setting it for a given widget is undefined behaviour.**
>
> > `animation_ticks_rate`: `integer`
> >
> > _Optional_. Default: No value
> >
> > Overrides [global animation setting](settings.md#animation) for this widget. Applies only for
> > `scrolling` text.
> >
> > **Changing this value after initially setting it for a given widget is undefined behaviour.**
>
> > `font_size`: `FontSize`
> >
> > _Optional_. Default: `"Auto"`.
> >
> > Sets the font size of the text.
>
> > `repeats: Repeat`
> >
> > _Optional_. Default: `ForDuration`.
> >
> > Specifies the repeat strategy, applies only for scrolling text.
>
> > `text_offset`: `integer`
> >
> > _Optional_. Default: Calculated automatically based on the `font_size`.
> >
> > Determines the offset of the text from the bottom of the widget.
Loading

0 comments on commit 34cef93

Please sign in to comment.