| 91 | } |
| 92 | |
| 93 | lv_obj_t* toolbar_create(lv_obj_t* parent, const std::string& title) { |
| 94 | auto ui_density = lvgl_get_ui_density(); |
| 95 | auto toolbar_height = getToolbarHeight(ui_density); |
| 96 | toolbar_class.height_def = toolbar_height; |
| 97 | lv_obj_t* obj = lv_obj_class_create_obj(&toolbar_class, parent); |
| 98 | lv_obj_class_init_obj(obj); |
| 99 | lv_obj_set_height(obj, toolbar_height); |
| 100 | |
| 101 | auto* toolbar = reinterpret_cast<Toolbar*>(obj); |
| 102 | lv_obj_set_width(obj, LV_PCT(100)); |
| 103 | lv_obj_set_style_pad_all(obj, 0, LV_STATE_DEFAULT); |
| 104 | lv_obj_set_style_pad_column(obj, 0, LV_STATE_DEFAULT); |
| 105 | |
| 106 | lv_obj_center(obj); |
| 107 | lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW); |
| 108 | |
| 109 | auto icon_padding = getActionIconPadding(ui_density); |
| 110 | |
| 111 | auto* close_button_wrapper = create_action_wrapper(obj, ui_density); |
| 112 | |
| 113 | toolbar->close_button = lv_button_create(close_button_wrapper); |
| 114 | if (ui_density == LVGL_UI_DENSITY_COMPACT) { |
| 115 | lv_obj_set_style_bg_opa(toolbar->close_button, LV_OPA_TRANSP, LV_STATE_DEFAULT); |
| 116 | } |
| 117 | |
| 118 | lv_obj_set_size(toolbar->close_button, toolbar_height - icon_padding, toolbar_height - icon_padding); |
| 119 | |
| 120 | lv_obj_set_style_pad_all(toolbar->close_button, 0, LV_STATE_DEFAULT); |
| 121 | lv_obj_align(toolbar->close_button, LV_ALIGN_CENTER, 0, 0); |
| 122 | toolbar->close_button_image = lv_image_create(toolbar->close_button); |
| 123 | lv_obj_align(toolbar->close_button_image, LV_ALIGN_CENTER, 0, 0); |
| 124 | |
| 125 | auto* title_wrapper = lv_obj_create(obj); |
| 126 | uint32_t title_left_padding = (ui_density != LVGL_UI_DENSITY_COMPACT) ? icon_padding : 2; |
| 127 | uint32_t title_right_padding = (ui_density != LVGL_UI_DENSITY_COMPACT) ? (icon_padding / 2) : 2; |
| 128 | lv_obj_set_size(title_wrapper, LV_SIZE_CONTENT, LV_PCT(100)); |
| 129 | lv_obj_set_style_bg_opa(title_wrapper, 0, LV_STATE_DEFAULT); |
| 130 | lv_obj_set_style_pad_left(title_wrapper, title_left_padding, LV_STATE_DEFAULT); |
| 131 | lv_obj_set_style_pad_right(title_wrapper, title_right_padding, LV_STATE_DEFAULT); |
| 132 | lv_obj_set_style_pad_ver(title_wrapper, 0, LV_STATE_DEFAULT); |
| 133 | lv_obj_set_style_border_width(title_wrapper, 0, LV_STATE_DEFAULT); |
| 134 | lv_obj_set_flex_grow(title_wrapper, 1); |
| 135 | |
| 136 | toolbar->title_label = lv_label_create(title_wrapper); |
| 137 | lv_obj_set_style_text_font(toolbar->title_label, getToolbarFont(ui_density), LV_STATE_DEFAULT); |
| 138 | lv_label_set_text(toolbar->title_label, title.c_str()); |
| 139 | lv_label_set_long_mode(toolbar->title_label, LV_LABEL_LONG_MODE_SCROLL); |
| 140 | lv_obj_set_style_text_align(toolbar->title_label, LV_TEXT_ALIGN_LEFT, LV_STATE_DEFAULT); |
| 141 | lv_obj_align(toolbar->title_label, LV_ALIGN_LEFT_MID, 0, 0); |
| 142 | lv_obj_set_width(toolbar->title_label, LV_PCT(100)); |
| 143 | |
| 144 | toolbar->action_container = lv_obj_create(obj); |
| 145 | lv_obj_set_width(toolbar->action_container, LV_SIZE_CONTENT); |
| 146 | lv_obj_set_flex_flow(toolbar->action_container, LV_FLEX_FLOW_ROW); |
| 147 | lv_obj_set_style_pad_all(toolbar->action_container, 0, LV_STATE_DEFAULT); |
| 148 | lv_obj_set_style_pad_column(toolbar->action_container, 0, LV_STATE_DEFAULT); |
| 149 | lv_obj_set_style_border_width(toolbar->action_container, 0, LV_STATE_DEFAULT); |
| 150 | lv_obj_set_style_bg_opa(toolbar->action_container, 0, LV_STATE_DEFAULT); |
no test coverage detected