Skip to content

Commit

Permalink
Fix C array images (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
unwieldycat authored Nov 10, 2024
2 parents 300c20e + a1c3371 commit 218e71d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ Changes to this project will be logged in this file. This project uses
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). Format is loosely
based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

# 2.1.2

Robodash 2.1.2 provides a fix for the image widget.

> [!WARNING] This update has a breaking change
>
> When constructing an `rd::Image` with a C array, you must pass a pointer to
> your `lv_img_dsc_t` instead of a reference. This is to prevent a dangling
> pointer.
### Fixed

- A bug where constructing an `rd::Image` with a C array would not display the
image.

## 2.1.1

Robodash 2.1.1 is a recompilation of 2.1.0 that upgrades to PROS version 4.1.0
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ EXCLUDE_COLD_LIBRARIES:=
# Set this to 1 to add additional rules to compile your project as a PROS library template
IS_LIBRARY:=1
LIBNAME:=robodash
VERSION:=2.1.1
VERSION:=2.1.2

# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c
# this line excludes opcontrol.c and similar files
Expand Down
6 changes: 3 additions & 3 deletions docs/source/guides/usage/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ convert the image to a C array and place it in your project's `src` directory,
or convert it to a a binary file and load it onto a microSD card.

To create an image, we can construct it with a path to an LVGL-converted
`image.bin` file on a loaded SD card, or to an LVGL image variable. You also
must pass a name to the image.
`image.bin` file on a loaded SD card, or a pointer to an LVGL image variable.
You also must pass a name to the image.

```cpp
// microSD approach
rd::Image image1("S:/usd/logo.bin", "Team Logo");

// C array approach
rd::Image image2(team_logo, "Team Logo")
rd::Image image2(&team_logo, "Team Logo")
```
4 changes: 2 additions & 2 deletions include/robodash/views/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class Image {
/**
* @brief Create a new Image
*
* @param image_dsc LVGL image descriptor object
* @param image_dsc Pointer to LVGL image descriptor object
* @param name Name to display on screen
*/
Image(lv_img_dsc_t image_dsc, std::string name = "Image");
Image(lv_img_dsc_t *image_dsc, std::string name = "Image");

/**
* @brief Set this view to the active view
Expand Down
6 changes: 2 additions & 4 deletions src/robodash/views/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

// ============================= Core Functions ============================= //

rd::Image::Image(lv_img_dsc_t image_dsc, std::string name) {
if (!pros::usd::is_installed()) return;

rd::Image::Image(lv_img_dsc_t *image_dsc, std::string name) {
this->view = rd_view_create(name.c_str());
lv_obj_t *image = lv_img_create(view->obj);
lv_img_set_src(image, &image_dsc);
lv_img_set_src(image, image_dsc);
lv_obj_align(image, LV_ALIGN_CENTER, 0, 0);
rd_view_set_anims(this->view, RD_ANIM_OFF);
}
Expand Down

0 comments on commit 218e71d

Please sign in to comment.