updates widget positions
This commit is contained in:
+18
-9
@@ -1,19 +1,30 @@
|
||||
#include "button.h"
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
button_t *init_button() {
|
||||
#include "../app.h"
|
||||
#include "../widget.h"
|
||||
#include "button.h"
|
||||
|
||||
button_t *init_button(WINDOW **win, uint32_t parent_id, char *label) {
|
||||
button_t *btn = malloc(sizeof(button_t));
|
||||
init_widget(&(btn->w), win, label, parent_id);
|
||||
btn->is_disabled = 0;
|
||||
btn->is_focused = 0;
|
||||
btn->is_hovered = 0;
|
||||
btn->callback = NULL;
|
||||
btn->w.x = strlen(btn->w.title) + 4; // + "[ ]"
|
||||
btn->w.y = 1; // TODO: detect new line
|
||||
if (btn->is_focused) btn->w.x += 2; // + "<>"
|
||||
return btn;
|
||||
}
|
||||
|
||||
int32_t draw_button(WINDOW *win, button_t *btn, uint32_t cur_x, uint32_t cur_y) {
|
||||
int32_t draw_button(button_t *btn) {
|
||||
char title[DIALOGUE_TITLE + 6];
|
||||
WINDOW *win = *(btn->w.parent_win);
|
||||
uint32_t cur_y = btn->w.m_y;
|
||||
uint32_t cur_x = btn->w.m_x;
|
||||
|
||||
if (btn->is_focused) {
|
||||
sprintf(title, "[< %s >]", btn->w.title);
|
||||
@@ -22,17 +33,15 @@ int32_t draw_button(WINDOW *win, button_t *btn, uint32_t cur_x, uint32_t cur_y)
|
||||
}
|
||||
|
||||
if (btn->is_hovered) {
|
||||
wattrset(win, COLOR_PAIR(1) | A_BOLD | A_REVERSE);
|
||||
wattrset(win, COLOR_PAIR(MODAL_COLOR_PAIR) | A_BOLD | A_REVERSE);
|
||||
} else {
|
||||
wattrset(win, COLOR_PAIR(1) | A_BOLD);
|
||||
wattrset(win, COLOR_PAIR(0) | A_REVERSE);
|
||||
}
|
||||
|
||||
mvwprintw(win, cur_y, cur_x, "%s", title);
|
||||
|
||||
wattroff(win, A_REVERSE | A_BOLD);
|
||||
wattroff(win, A_BOLD | A_REVERSE);
|
||||
return strlen(title);
|
||||
}
|
||||
|
||||
void destroy_button(button_t *btn) {
|
||||
free(btn);
|
||||
}
|
||||
void destroy_button(button_t *btn) { free(btn); }
|
||||
Reference in New Issue
Block a user