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

Function button_element_loc

leif.c:1137–1178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1135}
1136
1137LfClickableItemState button_element_loc(void* text, const char* file, int32_t line, bool wide) {
1138 // Retrieving the property data of the button
1139 LfUIElementProps props = get_props_for(state.theme.button_props);
1140 float padding = props.padding;
1141 float margin_left = props.margin_left, margin_right = props.margin_right,
1142 margin_top = props.margin_top, margin_bottom = props.margin_bottom;
1143
1144 // Advancing the position pointer by the margins
1145 state.pos_ptr.x += margin_left;
1146 state.pos_ptr.y += margin_top;
1147 LfFont font = get_current_font();
1148
1149 LfTextProps text_props;
1150 if(wide)
1151 text_props = text_render_simple_wide(state.pos_ptr, (const wchar_t*)text, font, LF_NO_COLOR, true);
1152 else
1153 text_props = text_render_simple(state.pos_ptr, (const char*)text, font, LF_NO_COLOR, true);
1154
1155 LfColor color = props.color;
1156 LfColor text_color = lf_hovered(state.pos_ptr, (vec2s){text_props.width, text_props.height}) && props.hover_text_color.a != 0.0f ? props.hover_text_color : props.text_color;
1157
1158 // If the button does not fit onto the current div, advance to the next line
1159 next_line_on_overflow(
1160 (vec2s){text_props.width + padding * 2.0f + margin_right + margin_left,
1161 text_props.height + padding * 2.0f + margin_bottom + margin_top}, state.div_props.border_width);
1162
1163
1164 // Rendering the button
1165 LfClickableItemState ret = button(file, line, state.pos_ptr, (vec2s){text_props.width + padding * 2, text_props.height + padding * 2},
1166 props, color, props.border_width, true, true);
1167 // Rendering the text of the button
1168 if(wide)
1169 text_render_simple_wide((vec2s){state.pos_ptr.x + padding, state.pos_ptr.y + padding}, (const wchar_t*)text, font, text_color, false);
1170 else
1171 text_render_simple((vec2s){state.pos_ptr.x + padding, state.pos_ptr.y + padding}, (const char*)text, font, text_color, false);
1172
1173 // Advancing the position pointer by the width of the button
1174 state.pos_ptr.x += text_props.width + margin_right + padding * 2.0f;
1175 state.pos_ptr.y -= margin_top;
1176
1177 return ret;
1178}
1179LfClickableItemState button_fixed_element_loc(void* text, float width, float height, const char* file, int32_t line, bool wide) {
1180 // Retrieving the property data of the button
1181 LfUIElementProps props = get_props_for(state.theme.button_props);

Callers 2

_lf_button_locFunction · 0.85
_lf_button_wide_locFunction · 0.85

Calls 7

get_props_forFunction · 0.85
get_current_fontFunction · 0.85
text_render_simple_wideFunction · 0.85
text_render_simpleFunction · 0.85
lf_hoveredFunction · 0.85
next_line_on_overflowFunction · 0.85
buttonFunction · 0.85

Tested by

no test coverage detected