diff options
Diffstat (limited to 'src/mgui/button.c')
-rw-r--r-- | src/mgui/button.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/mgui/button.c b/src/mgui/button.c index b548140..08cf91c 100644 --- a/src/mgui/button.c +++ b/src/mgui/button.c @@ -12,8 +12,8 @@ mgui_button* mgui_button_create() { button->background.position = (mgl_vec2f){ 0.0f, 0.0f }; button->background.size = (mgl_vec2f){ 0.0f, 0.0f }; button->background.color = (mgl_color){ 45, 45, 45, 255 }; - mgl_text_init(&button->label, mgui_get_font(MGUI_FONT_LATIN, 32), "Label", 5); - button->background.size = mgl_text_get_bounds(&button->label); + mgl_text_init(&button->text, mgui_get_font(MGUI_FONT_LATIN, 32), "Label", 5); + button->background.size = mgl_text_get_bounds(&button->text); return button; } @@ -27,11 +27,11 @@ mgui_button* mgui_widget_to_button(mgui_widget *widget) { } void mgui_button_set_position(mgui_button *self, mgl_vec2i position) { - const mgl_vec2f label_bounds = mgl_text_get_bounds(&self->label); + const mgl_vec2f text_bounds = mgl_text_get_bounds(&self->text); self->background.position = (mgl_vec2f){ position.x, position.y }; - mgl_text_set_position(&self->label, (mgl_vec2f){ - (int)(self->background.position.x + self->background.size.x * 0.5f - label_bounds.x * 0.5f), - (int)(self->background.position.y + self->background.size.y * 0.5f - label_bounds.y * 0.5f) + mgl_text_set_position(&self->text, (mgl_vec2f){ + (int)(self->background.position.x + self->background.size.x * 0.5f - text_bounds.x * 0.5f), + (int)(self->background.position.y + self->background.size.y * 0.5f - text_bounds.y * 0.5f) }); } @@ -40,13 +40,12 @@ static int max_int(int a, int b) { } void mgui_button_set_width(mgui_button *self, int width) { - mgl_vec2f label_bounds = mgl_text_get_bounds(&self->label); - self->background.size.x = max_int(label_bounds.x, width); + const mgl_vec2f text_bounds = mgl_text_get_bounds(&self->text); + self->background.size.x = max_int(text_bounds.x, width); mgui_button_set_position(self, (mgl_vec2i){ self->background.position.x, self->background.position.y }); } void mgui_button_on_event(mgui_button *self, mgl_window *window, mgl_event *event) { - // TODO: Implement (void)window; if(event->type == MGL_EVENT_MOUSE_MOVED) { if(mgui_rectangle_contains(self->background.position, self->background.size, (mgl_vec2f){ event->mouse_move.x, event->mouse_move.y })) { @@ -64,6 +63,6 @@ void mgui_button_on_event(mgui_button *self, mgl_window *window, mgl_event *even mgl_vec2i mgui_button_draw(mgui_button *self, mgl_window *window) { (void)window; mgl_rectangle_draw(mgl_get_context(), &self->background); - mgl_text_draw(mgl_get_context(), &self->label); + mgl_text_draw(mgl_get_context(), &self->text); return (mgl_vec2i){ self->background.size.x, self->background.size.y }; } |