refactoring; modal window init
This commit is contained in:
+11
-9
@@ -29,7 +29,7 @@ app_t *init_app() {
|
||||
_app->action_win = newwin(y_max - 4, action_w_x, 2, menu_w_x + 1);
|
||||
|
||||
// dialogue
|
||||
_app->modal.win = NULL;
|
||||
_app->modal.dialogue.win = NULL;
|
||||
|
||||
// print decorative bars
|
||||
print_bars(_app);
|
||||
@@ -38,16 +38,16 @@ app_t *init_app() {
|
||||
draw_borders(_app);
|
||||
|
||||
// init menus
|
||||
// _app->menus = malloc(3 * sizeof(menu_t));
|
||||
// _app->menus[0] = init_menu("(F)ile", 'f');
|
||||
// _app->menus[1] = init_menu("(E)dit", 'e');
|
||||
// _app->menus[2] = init_menu("(A)bout", 'a');
|
||||
// _app->menus = malloc(3 * sizeof(menu_t));
|
||||
// _app->menus[0] = init_menu("(F)ile", 'f');
|
||||
// _app->menus[1] = init_menu("(E)dit", 'e');
|
||||
// _app->menus[2] = init_menu("(A)bout", 'a');
|
||||
|
||||
// set active window by default
|
||||
// _app->active = N_MENU;
|
||||
// _app->active = N_MENU;
|
||||
|
||||
// call the action window content by default
|
||||
// ac_file(_app->action_win, _app->active);
|
||||
// ac_file(_app->action_win, _app->active);
|
||||
|
||||
// refresh the windows
|
||||
wnoutrefresh(_app->win);
|
||||
@@ -70,6 +70,7 @@ void init_nc() {
|
||||
start_color();
|
||||
init_pair(1, COLOR_RED, COLOR_BLACK);
|
||||
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
||||
init_pair(MODAL_COLOR_PAIR, COLOR_BLUE, COLOR_WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +95,9 @@ void print_bars(app_t *app) {
|
||||
}
|
||||
|
||||
// add content to the top bar
|
||||
mvwprintw(app->win, 1, 2, "example curses app | ");
|
||||
mvwprintw(app->win, 1, 20, "size %d, %d", app->cur_x, app->cur_y);
|
||||
mvwprintw(app->win, 1, 2, "example cprint_barsurses app | ");
|
||||
mvwprintw(app->win, 1, sizeof "example cprint_barsurses app | " + 1,
|
||||
"size %d, %d", app->cur_x, app->cur_y);
|
||||
|
||||
// add content to the bottom bar
|
||||
mvwprintw(app->win, app->cur_y - 2, 2, "F1 - Help | F9 - Quit");
|
||||
|
||||
+7
-2
@@ -2,9 +2,14 @@
|
||||
#define N_APP_H
|
||||
|
||||
#include <ncurses.h>
|
||||
#include "widget/dialogue.h"
|
||||
|
||||
typedef enum {
|
||||
none = 0,
|
||||
MODAL_COLOR_PAIR = 3,
|
||||
} color;
|
||||
|
||||
typedef enum {
|
||||
none_active = 0,
|
||||
login = 1,
|
||||
} dialogue_e;
|
||||
|
||||
@@ -14,7 +19,7 @@ typedef struct {
|
||||
WINDOW *action_win;
|
||||
struct {
|
||||
dialogue_e active;
|
||||
WINDOW *win;
|
||||
dialogue_t dialogue;
|
||||
} modal;
|
||||
|
||||
// menu_bar_t *menu_bar;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef WIDGET_H
|
||||
#define WIDGET_H
|
||||
|
||||
#include "../main.h"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
char title[DIALOGUE_TITLE];
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
uint32_t m_x;
|
||||
uint32_t m_y;
|
||||
char color_pair;
|
||||
} widget_t;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef BUTTON_H
|
||||
#define BUTTON_H
|
||||
|
||||
#include "../../main.h"
|
||||
#include "../widget.h"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
widget_t widget;
|
||||
char value;
|
||||
uint32_t is_focused : 1;
|
||||
uint32_t is_disabled : 1;
|
||||
} button_t;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "dialogue.h"
|
||||
#include "../app.h"
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
dialogue_t *init_dialogue(char title[]) {
|
||||
dialogue_t *dialogue = malloc(sizeof(dialogue_t));
|
||||
dialogue->win = 0;
|
||||
dialogue->buttons = NULL;
|
||||
strcpy(dialogue->w.title, title);
|
||||
return dialogue;
|
||||
}
|
||||
|
||||
int32_t draw_dialogue(dialogue_t *d, uint32_t cur_x, uint32_t cur_y) {
|
||||
d->w.x = 50;
|
||||
d->w.y = 20;
|
||||
d->w.m_x = (cur_x - d->w.x) / 2;
|
||||
d->w.m_y = (cur_y - d->w.y) / 2;
|
||||
|
||||
d->win = newwin(d->w.y, d->w.x, d->w.m_y, d->w.m_x);
|
||||
|
||||
wcolor_set(d->win, MODAL_COLOR_PAIR, NULL);
|
||||
wattrset(d->win, A_REVERSE);
|
||||
|
||||
for (int xp = 1; xp < d->w.x; xp++) {
|
||||
for (int yp = 1; yp < d->w.y - 1; yp++) {
|
||||
mvwprintw(d->win, yp, xp, " ");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t title_mx_pos = (d->w.x - strlen(d->w.title)) / 2;
|
||||
|
||||
box(d->win, 0, 0);
|
||||
mvwprintw(d->win, 0, title_mx_pos-1, " ");
|
||||
mvwprintw(d->win, 0, title_mx_pos, d->w.title);
|
||||
mvwprintw(d->win, 0, title_mx_pos + strlen(d->w.title), " ");
|
||||
wattroff(d->win, A_REVERSE);
|
||||
wrefresh(d->win);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
void destroy_active_dialogue(dialogue_t *d) {
|
||||
delwin(d->win);
|
||||
free(d->win);
|
||||
d->win = NULL;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef DIALOGUE_H
|
||||
#define DIALOGUE_H
|
||||
|
||||
#include <ncurses.h>
|
||||
#include "../widget.h"
|
||||
#include "button.h"
|
||||
|
||||
typedef struct {
|
||||
WINDOW *win;
|
||||
widget_t w;
|
||||
button_t *buttons; // ! should be NULL-terminated
|
||||
} dialogue_t;
|
||||
|
||||
dialogue_t *init_dialogue(char title[]);
|
||||
int32_t draw_dialogue(dialogue_t *d, uint32_t cur_x, uint32_t cur_y);
|
||||
void destroy_active_dialogue(dialogue_t *d);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user