MCPcopy Create free account
hub / github.com/cococry/leif / checkbox_element_loc

Function checkbox_element_loc

leif.c:1234–1289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1232
1233}
1234LfClickableItemState checkbox_element_loc(void* text, bool* val, LfColor tick_color, LfColor tex_color, const char* file, int32_t line, bool wide) {
1235 // Retrieving the property values of the checkbox
1236 LfFont font = get_current_font();
1237 LfUIElementProps props = get_props_for(state.theme.checkbox_props);
1238 float margin_left = props.margin_left;
1239 float margin_right = props.margin_right;
1240 float margin_top = props.margin_top;
1241 float margin_bottom = props.margin_bottom;
1242
1243 float checkbox_size;
1244 if(wide)
1245 checkbox_size = lf_text_dimension_wide((const wchar_t*)text).y;
1246 else
1247 checkbox_size = lf_text_dimension((const char*)text).y;
1248
1249 // Advance to next line if the object does not fit on the div
1250 next_line_on_overflow((vec2s){checkbox_size + margin_left + margin_right + props.padding * 2.0f, checkbox_size + margin_top + margin_bottom + props.padding * 2.0f},
1251 state.div_props.border_width);
1252
1253 state.pos_ptr.x += margin_left;
1254 state.pos_ptr.y += margin_top;
1255
1256 // Render the box
1257 LfColor checkbox_color = (*val) ? ((tick_color.a == 0) ? props.color : tick_color) : props.color;
1258 LfClickableItemState checkbox = button(file, line, state.pos_ptr, (vec2s){checkbox_size + props.padding * 2.0f, checkbox_size + props.padding * 2.0f},
1259 props, checkbox_color, props.border_width, false, false);
1260
1261
1262 if(wide)
1263 text_render_simple_wide((vec2s){state.pos_ptr.x + checkbox_size + props.padding * 2.0f + margin_right, state.pos_ptr.y + props.padding}, (const wchar_t*)text, font, props.text_color, false);
1264 else
1265 text_render_simple((vec2s){state.pos_ptr.x + checkbox_size + props.padding * 2.0f + margin_right, state.pos_ptr.y + props.padding}, (const char*)text, font, props.text_color, false);
1266
1267 // Change the value if the checkbox is clicked
1268 if(checkbox == LF_CLICKED) {
1269 *val = !*val;
1270 }
1271 if(*val) {
1272 // Render the image
1273 lf_image_render(
1274 (vec2s){state.pos_ptr.x + props.padding,
1275 state.pos_ptr.y + props.padding},
1276 tex_color,
1277 (LfTexture){
1278 .id = state.tex_tick.id,
1279 .width = (uint32_t)(checkbox_size),
1280 .height = (uint32_t)(checkbox_size)},
1281 (LfColor){0.0f, 0.0f, 0.0f, 0.0f}, 0, props.corner_radius);
1282 }
1283 state.pos_ptr.x += checkbox_size + props.padding * 2.0f + margin_right +
1284 ((wide) ? lf_text_dimension_wide((const wchar_t*)text).x : lf_text_dimension((const char*)text).x) + margin_right;
1285 state.pos_ptr.y -= margin_top;
1286
1287 return checkbox;
1288
1289}
1290void dropdown_menu_item_loc(void** items, void* placeholder, uint32_t item_count, float width, float height, int32_t* selected_index, bool* opened, const char* file, int32_t line, bool wide) {
1291 LfUIElementProps props = get_props_for(state.theme.button_props);

Callers 2

_lf_checkbox_locFunction · 0.85
_lf_checkbox_wide_locFunction · 0.85

Calls 9

get_current_fontFunction · 0.85
get_props_forFunction · 0.85
lf_text_dimension_wideFunction · 0.85
lf_text_dimensionFunction · 0.85
next_line_on_overflowFunction · 0.85
buttonFunction · 0.85
text_render_simple_wideFunction · 0.85
text_render_simpleFunction · 0.85
lf_image_renderFunction · 0.85

Tested by

no test coverage detected