Created
January 3, 2020 22:57
-
-
Save ermiry/243916e41cec2f1c8768b53487781bf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cengine/types/types.h" | |
#include "cengine/renderer.h" | |
#include "cengine/ui/ui.h" | |
#include "cengine/ui/image.h" | |
#include "cengine/ui/panel.h" | |
Panel *images_panel = NULL; | |
// create the grid that will display the images | |
void app_ui_images_set_ui_elements (u32 n_images, u32 n_cols, u32 n_rows) { | |
Renderer *main_renderer = renderer_get_by_name ("main"); | |
u32 screen_width = main_renderer->window->window_size.width; | |
u32 screen_height = main_renderer->window->window_size.height; | |
u32 n_actual_rows = n_images / n_cols; // total rows for the layout | |
n_actual_rows += 1; | |
u32 panel_width = (screen_width - 100); | |
u32 panel_height = (screen_height / n_rows) * n_actual_rows; | |
images_panel = ui_panel_create (100, 0, panel_width, panel_height, UI_POS_FREE, main_renderer); | |
ui_panel_layout_set (images_panel, LAYOUT_TYPE_GRID); | |
u32 cell_width = (screen_width - 100) / n_cols; | |
u32 cell_height = (screen_height / n_rows); | |
GridLayout *grid = (GridLayout *) images_panel->layout; | |
ui_layout_grid_set_grid (grid, n_cols, n_actual_rows); | |
ui_layout_grid_set_cell_size (grid, cell_width, cell_height); | |
} | |
// when you are done working with the grid, this is the correct way to free memory | |
void app_ui_images_remove_ui_elements (void) { | |
// remove the panel and the layout | |
GridLayout *grid = (GridLayout *) images_panel->layout; | |
ui_layout_grid_destroy_ui_elements (grid); | |
if (images_panel) { | |
ui_element_destroy (images_panel->ui_element); | |
images_panel = NULL; | |
} | |
} | |
// adds the image into the main grid for display | |
void app_ui_image_display (Image *image) { | |
if (image) { | |
ui_panel_layout_add_element (images_panel, image->ui_element); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment