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

Function button_ex

leif.c:617–659  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

615 return button_ex(file, line, pos, size, props, color, border_width, click_color, hover_color, (vec2s){-1, -1});
616}
617LfClickableItemState button_ex(const char* file, int32_t line, vec2s pos, vec2s size, LfUIElementProps props, LfColor color, float border_width, bool click_color, bool hover_color, vec2s hitbox_override) {
618 uint64_t id = DJB2_INIT;
619 id = djb2_hash(id, file, strlen(file));
620 id = djb2_hash(id, &line, sizeof(line));
621 if(state.element_id_stack != -1) {
622 id = djb2_hash(id, &state.element_id_stack, sizeof(state.element_id_stack));
623 }
624
625 if(item_should_cull((LfAABB){.pos = pos, .size= size})) {
626 return LF_IDLE;
627 }
628
629 LfColor hover_color_rgb = hover_color ? (props.hover_color.a == 0.0f ? lf_color_brightness(color, 1.2) : props.hover_color) : color;
630 LfColor held_color_rgb = click_color ? lf_color_brightness(color, 1.3) : color;
631
632 bool is_hovered = lf_hovered(pos, (vec2s){hitbox_override.x != -1 ? hitbox_override.x : size.x,
633 hitbox_override.y != -1 ? hitbox_override.y : size.y});
634 if(state.active_element_id == 0) {
635 if(is_hovered && lf_mouse_button_went_down(GLFW_MOUSE_BUTTON_LEFT)) {
636 state.active_element_id = id;
637 }
638 } else if(state.active_element_id == id) {
639 if(is_hovered && lf_mouse_button_is_released(GLFW_MOUSE_BUTTON_LEFT)) {
640 lf_rect_render(pos, size, hover_color_rgb, props.border_color, border_width, props.corner_radius);
641 state.active_element_id = 0;
642 return LF_CLICKED;
643 }
644 }
645 if(is_hovered && lf_mouse_button_is_released(GLFW_MOUSE_BUTTON_LEFT)) {
646 state.active_element_id = 0;
647 }
648 if(is_hovered && lf_mouse_button_is_down(GLFW_MOUSE_BUTTON_LEFT)) {
649 lf_rect_render(pos, size, held_color_rgb, props.border_color, border_width, props.corner_radius);
650 return LF_HELD;
651 }
652 if(is_hovered && (!lf_mouse_button_went_down(GLFW_MOUSE_BUTTON_LEFT) && !lf_mouse_button_is_down(GLFW_MOUSE_BUTTON_LEFT))) {
653 lf_rect_render(pos, size, hover_color ? hover_color_rgb : color, props.border_color, border_width, props.corner_radius);
654 return LF_HOVERED;
655 }
656 lf_rect_render(pos, size, color, props.border_color, border_width, props.corner_radius);
657 return LF_IDLE;
658
659}
660LfClickableItemState div_container(vec2s pos, vec2s size, LfUIElementProps props, LfColor color, float border_width, bool click_color, bool hover_color) {
661 if(item_should_cull((LfAABB){.pos = pos, .size = size})) {
662 return LF_IDLE;

Callers 2

buttonFunction · 0.85
_lf_slider_int_locFunction · 0.85

Calls 8

djb2_hashFunction · 0.85
item_should_cullFunction · 0.85
lf_color_brightnessFunction · 0.85
lf_hoveredFunction · 0.85
lf_rect_renderFunction · 0.85
lf_mouse_button_is_downFunction · 0.85

Tested by

no test coverage detected