Skip to content

Commit

Permalink
feat: add missing const qualifiers (flipperdevices#2233)
Browse files Browse the repository at this point in the history
* feat: make `ViewPort` getters const
* feat: make tx-buffers const
* feat: make `canvas_get_buffer_size` const
* feat: make `canvas` methods const
* feat: make `icon_animation` methods const
* feat: make `scene_manager` methods const
* feat: make `loader` method const
* feat: make `canvas_get_font_params` const

Co-authored-by: Aleksandr Kutuzov <[email protected]>
  • Loading branch information
JarvisCraft and skotopes authored Feb 9, 2023
1 parent 163be13 commit 4265057
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 77 deletions.
12 changes: 6 additions & 6 deletions applications/services/gui/canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ uint8_t* canvas_get_buffer(Canvas* canvas) {
return u8g2_GetBufferPtr(&canvas->fb);
}

size_t canvas_get_buffer_size(Canvas* canvas) {
size_t canvas_get_buffer_size(const Canvas* canvas) {
furi_assert(canvas);
return u8g2_GetBufferTileWidth(&canvas->fb) * u8g2_GetBufferTileHeight(&canvas->fb) * 8;
}
Expand All @@ -75,17 +75,17 @@ void canvas_frame_set(
canvas->height = height;
}

uint8_t canvas_width(Canvas* canvas) {
uint8_t canvas_width(const Canvas* canvas) {
furi_assert(canvas);
return canvas->width;
}

uint8_t canvas_height(Canvas* canvas) {
uint8_t canvas_height(const Canvas* canvas) {
furi_assert(canvas);
return canvas->height;
}

uint8_t canvas_current_font_height(Canvas* canvas) {
uint8_t canvas_current_font_height(const Canvas* canvas) {
furi_assert(canvas);
uint8_t font_height = u8g2_GetMaxCharHeight(&canvas->fb);

Expand All @@ -96,10 +96,10 @@ uint8_t canvas_current_font_height(Canvas* canvas) {
return font_height;
}

CanvasFontParameters* canvas_get_font_params(Canvas* canvas, Font font) {
const CanvasFontParameters* canvas_get_font_params(const Canvas* canvas, Font font) {
furi_assert(canvas);
furi_assert(font < FontTotalNumber);
return (CanvasFontParameters*)&canvas_font_params[font];
return &canvas_font_params[font];
}

void canvas_clear(Canvas* canvas) {
Expand Down
8 changes: 4 additions & 4 deletions applications/services/gui/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,23 @@ void canvas_commit(Canvas* canvas);
*
* @return width in pixels.
*/
uint8_t canvas_width(Canvas* canvas);
uint8_t canvas_width(const Canvas* canvas);

/** Get Canvas height
*
* @param canvas Canvas instance
*
* @return height in pixels.
*/
uint8_t canvas_height(Canvas* canvas);
uint8_t canvas_height(const Canvas* canvas);

/** Get current font height
*
* @param canvas Canvas instance
*
* @return height in pixels.
*/
uint8_t canvas_current_font_height(Canvas* canvas);
uint8_t canvas_current_font_height(const Canvas* canvas);

/** Get font parameters
*
Expand All @@ -110,7 +110,7 @@ uint8_t canvas_current_font_height(Canvas* canvas);
*
* @return pointer to CanvasFontParameters structure
*/
CanvasFontParameters* canvas_get_font_params(Canvas* canvas, Font font);
const CanvasFontParameters* canvas_get_font_params(const Canvas* canvas, Font font);

/** Clear canvas
*
Expand Down
2 changes: 1 addition & 1 deletion applications/services/gui/canvas_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ uint8_t* canvas_get_buffer(Canvas* canvas);
*
* @return size of canvas in bytes
*/
size_t canvas_get_buffer_size(Canvas* canvas);
size_t canvas_get_buffer_size(const Canvas* canvas);

/** Set drawing region relative to real screen buffer
*
Expand Down
2 changes: 1 addition & 1 deletion applications/services/gui/elements.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ void elements_text_box(
bool inversed_present = false;
Font current_font = FontSecondary;
Font prev_font = FontSecondary;
CanvasFontParameters* font_params = canvas_get_font_params(canvas, current_font);
const CanvasFontParameters* font_params = canvas_get_font_params(canvas, current_font);

// Fill line parameters
uint8_t line_leading_min = font_params->leading_min;
Expand Down
2 changes: 1 addition & 1 deletion applications/services/gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ void gui_remove_framebuffer_callback(Gui* gui, GuiCanvasCommitCallback callback,
gui_unlock(gui);
}

size_t gui_get_framebuffer_size(Gui* gui) {
size_t gui_get_framebuffer_size(const Gui* gui) {
furi_assert(gui);
return canvas_get_buffer_size(gui->canvas);
}
Expand Down
2 changes: 1 addition & 1 deletion applications/services/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void gui_remove_framebuffer_callback(Gui* gui, GuiCanvasCommitCallback callback,
* @param gui Gui instance
* @return size_t size of frame buffer in bytes
*/
size_t gui_get_framebuffer_size(Gui* gui);
size_t gui_get_framebuffer_size(const Gui* gui);

/** Set lockdown mode
*
Expand Down
8 changes: 4 additions & 4 deletions applications/services/gui/icon_animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void icon_animation_set_update_callback(
instance->callback_context = context;
}

const uint8_t* icon_animation_get_data(IconAnimation* instance) {
const uint8_t* icon_animation_get_data(const IconAnimation* instance) {
return instance->icon->frames[instance->frame];
}

Expand All @@ -51,12 +51,12 @@ void icon_animation_timer_callback(void* context) {
}
}

uint8_t icon_animation_get_width(IconAnimation* instance) {
uint8_t icon_animation_get_width(const IconAnimation* instance) {
furi_assert(instance);
return instance->icon->width;
}

uint8_t icon_animation_get_height(IconAnimation* instance) {
uint8_t icon_animation_get_height(const IconAnimation* instance) {
furi_assert(instance);
return instance->icon->height;
}
Expand All @@ -83,7 +83,7 @@ void icon_animation_stop(IconAnimation* instance) {
}
}

bool icon_animation_is_last_frame(IconAnimation* instance) {
bool icon_animation_is_last_frame(const IconAnimation* instance) {
furi_assert(instance);
return instance->icon->frame_count - instance->frame <= 1;
}
6 changes: 3 additions & 3 deletions applications/services/gui/icon_animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ void icon_animation_set_update_callback(
*
* @return width in pixels
*/
uint8_t icon_animation_get_width(IconAnimation* instance);
uint8_t icon_animation_get_width(const IconAnimation* instance);

/** Get icon animation height
*
* @param instance IconAnimation instance
*
* @return height in pixels
*/
uint8_t icon_animation_get_height(IconAnimation* instance);
uint8_t icon_animation_get_height(const IconAnimation* instance);

/** Start icon animation
*
Expand All @@ -83,7 +83,7 @@ void icon_animation_stop(IconAnimation* instance);
*
* @return true if last frame
*/
bool icon_animation_is_last_frame(IconAnimation* instance);
bool icon_animation_is_last_frame(const IconAnimation* instance);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion applications/services/gui/icon_animation_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct IconAnimation {
*
* @return pointer to current frame XBM bitmap data
*/
const uint8_t* icon_animation_get_data(IconAnimation* instance);
const uint8_t* icon_animation_get_data(const IconAnimation* instance);

/** Advance to next frame
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static void widget_element_text_scroll_fill_lines(Canvas* canvas, WidgetElement*
}
// Set canvas font
canvas_set_font(canvas, line_tmp.font);
CanvasFontParameters* params = canvas_get_font_params(canvas, line_tmp.font);
const CanvasFontParameters* params = canvas_get_font_params(canvas, line_tmp.font);
total_height += params->height;
if(total_height > model->height) {
model->scroll_pos_total++;
Expand Down Expand Up @@ -138,7 +138,7 @@ static void widget_element_text_scroll_draw(Canvas* canvas, WidgetElement* eleme
TextScrollLineArray_next(it), curr_line++) {
if(curr_line < model->scroll_pos_current) continue;
TextScrollLineArray* line = TextScrollLineArray_ref(it);
CanvasFontParameters* params = canvas_get_font_params(canvas, line->font);
const CanvasFontParameters* params = canvas_get_font_params(canvas, line->font);
if(y + params->descender > model->y + model->height) break;
canvas_set_font(canvas, line->font);
if(line->horizontal == AlignLeft) {
Expand Down
4 changes: 2 additions & 2 deletions applications/services/gui/scene_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void scene_manager_set_scene_state(SceneManager* scene_manager, uint32_t scene_i
scene_manager->scene[scene_id].state = state;
}

uint32_t scene_manager_get_scene_state(SceneManager* scene_manager, uint32_t scene_id) {
uint32_t scene_manager_get_scene_state(const SceneManager* scene_manager, uint32_t scene_id) {
furi_assert(scene_manager);
furi_assert(scene_id < scene_manager->scene_handlers->scene_num);

Expand Down Expand Up @@ -184,7 +184,7 @@ bool scene_manager_search_and_switch_to_previous_scene_one_of(
return scene_found;
}

bool scene_manager_has_previous_scene(SceneManager* scene_manager, uint32_t scene_id) {
bool scene_manager_has_previous_scene(const SceneManager* scene_manager, uint32_t scene_id) {
furi_assert(scene_manager);
bool scene_found = false;

Expand Down
4 changes: 2 additions & 2 deletions applications/services/gui/scene_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void scene_manager_set_scene_state(SceneManager* scene_manager, uint32_t scene_i
*
* @return Scene state
*/
uint32_t scene_manager_get_scene_state(SceneManager* scene_manager, uint32_t scene_id);
uint32_t scene_manager_get_scene_state(const SceneManager* scene_manager, uint32_t scene_id);

/** Scene Manager allocation and configuration
*
Expand Down Expand Up @@ -134,7 +134,7 @@ bool scene_manager_previous_scene(SceneManager* scene_manager);
*
* @return true if previous scene was found, false otherwise
*/
bool scene_manager_has_previous_scene(SceneManager* scene_manager, uint32_t scene_id);
bool scene_manager_has_previous_scene(const SceneManager* scene_manager, uint32_t scene_id);

/** Search and switch to previous Scene
*
Expand Down
6 changes: 3 additions & 3 deletions applications/services/gui/view_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void view_port_set_width(ViewPort* view_port, uint8_t width) {
view_port->width = width;
}

uint8_t view_port_get_width(ViewPort* view_port) {
uint8_t view_port_get_width(const ViewPort* view_port) {
furi_assert(view_port);
return view_port->width;
}
Expand All @@ -99,7 +99,7 @@ void view_port_set_height(ViewPort* view_port, uint8_t height) {
view_port->height = height;
}

uint8_t view_port_get_height(ViewPort* view_port) {
uint8_t view_port_get_height(const ViewPort* view_port) {
furi_assert(view_port);
return view_port->height;
}
Expand All @@ -112,7 +112,7 @@ void view_port_enabled_set(ViewPort* view_port, bool enabled) {
}
}

bool view_port_is_enabled(ViewPort* view_port) {
bool view_port_is_enabled(const ViewPort* view_port) {
furi_assert(view_port);
return view_port->is_enabled;
}
Expand Down
6 changes: 3 additions & 3 deletions applications/services/gui/view_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void view_port_free(ViewPort* view_port);
* @param width wanted width, 0 - auto.
*/
void view_port_set_width(ViewPort* view_port, uint8_t width);
uint8_t view_port_get_width(ViewPort* view_port);
uint8_t view_port_get_width(const ViewPort* view_port);

/** Set view_port height.
*
Expand All @@ -66,7 +66,7 @@ uint8_t view_port_get_width(ViewPort* view_port);
* @param height wanted height, 0 - auto.
*/
void view_port_set_height(ViewPort* view_port, uint8_t height);
uint8_t view_port_get_height(ViewPort* view_port);
uint8_t view_port_get_height(const ViewPort* view_port);

/** Enable or disable view_port rendering.
*
Expand All @@ -75,7 +75,7 @@ uint8_t view_port_get_height(ViewPort* view_port);
* @warning automatically dispatches update event
*/
void view_port_enabled_set(ViewPort* view_port, bool enabled);
bool view_port_is_enabled(ViewPort* view_port);
bool view_port_is_enabled(const ViewPort* view_port);

/** ViewPort event callbacks
*
Expand Down
2 changes: 1 addition & 1 deletion applications/services/loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void loader_unlock(Loader* instance) {
FURI_CRITICAL_EXIT();
}

bool loader_is_locked(Loader* instance) {
bool loader_is_locked(const Loader* instance) {
return instance->lock_count > 0;
}

Expand Down
2 changes: 1 addition & 1 deletion applications/services/loader/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool loader_lock(Loader* instance);
void loader_unlock(Loader* instance);

/** Get loader lock status */
bool loader_is_locked(Loader* instance);
bool loader_is_locked(const Loader* instance);

/** Show primary loader */
void loader_show_menu();
Expand Down
2 changes: 1 addition & 1 deletion applications/services/locale/locale.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void locale_format_time(
*
* @return The Locale DateFormat.
*/
LocaleDateFormat locale_get_date_format();
LocaleDateFormat locale_get_date_format(void);

/** Set Locale DateFormat
*
Expand Down
Loading

0 comments on commit 4265057

Please sign in to comment.