Calendar: Create basic object structure
This commit is contained in:
parent
3278c54743
commit
7296559c16
|
@ -22,11 +22,10 @@ project(vis
|
||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
|
||||||
|
|
||||||
add_executable(vis src/main.cpp)
|
add_executable(vis
|
||||||
target_include_directories(vis PRIVATE src)
|
src/main.cpp
|
||||||
|
src/calendar.cpp
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(vis
|
find_library(NCURSES_LIB NAMES ncurses)
|
||||||
PRIVATE ftxui::screen
|
target_link_libraries(vis ncurses)
|
||||||
PRIVATE ftxui::dom
|
|
||||||
PRIVATE ftxui::component # Not needed for this example.
|
|
||||||
)
|
|
||||||
|
|
7
RESOURCES.md
Normal file
7
RESOURCES.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Resources for development
|
||||||
|
|
||||||
|
> **Note:** VIS mainly uses the NCURSES library, therefore, expect the majority of resources to be some sort of documentation for NCURSES.
|
||||||
|
|
||||||
|
- [INVISIBLE_ISLAND - Ncurses Docs](https://invisible-island.net/ncurses/man/ncurses.3x.html)
|
||||||
|
- [TLDP - NCURSES Programming HOWTO](https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/)
|
||||||
|
- [JBWYATT - Ncurses Programming Guide](https://jbwyatt.com/ncurses.html)
|
51
src/calendar.cpp
Normal file
51
src/calendar.cpp
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#include <time.h>
|
||||||
|
#include "calendar.hpp"
|
||||||
|
|
||||||
|
calendar_information::calendar_information() {
|
||||||
|
time_t current_time = time(NULL);
|
||||||
|
struct tm *datetime = localtime(¤t_time);
|
||||||
|
|
||||||
|
current_day = datetime->tm_mday;
|
||||||
|
current_month = datetime->tm_mon+1;
|
||||||
|
current_year = datetime->tm_year + 1900;
|
||||||
|
current_month_days = Calendar::get_days_in_month(current_month, current_year);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Calendar::get_days_in_month(int month, int year) {
|
||||||
|
tm date = {0};
|
||||||
|
date.tm_year = year - 1900;
|
||||||
|
date.tm_mon = month;
|
||||||
|
date.tm_mday = 0;
|
||||||
|
|
||||||
|
mktime(&date);
|
||||||
|
return date.tm_mday;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Calendar::set_day(int day) {
|
||||||
|
if (day > this->info.current_month_days) return;
|
||||||
|
this->info.current_day = day;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Calendar::set_month(int month) {
|
||||||
|
if (month > 12) return;
|
||||||
|
this->info.current_month = month;
|
||||||
|
this->info.current_month_days = Calendar::get_days_in_month(this->info.current_month, this->info.current_year);
|
||||||
|
if (this->info.current_day > this->info.current_month_days)
|
||||||
|
this->info.current_day = this->info.current_month_days;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Calendar::set_year(int year) {
|
||||||
|
this->info.current_year = year;
|
||||||
|
this->info.current_month_days = Calendar::get_days_in_month(this->info.current_month, this->info.current_year);
|
||||||
|
if (this->info.current_day > this->info.current_month_days)
|
||||||
|
this->info.current_day = this->info.current_month_days;
|
||||||
|
}
|
||||||
|
|
||||||
|
Calendar::Calendar(calendar_information *preinfo) {
|
||||||
|
this->info = *preinfo;
|
||||||
|
if (preinfo != nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->info = calendar_information();
|
||||||
|
}
|
21
src/calendar.hpp
Normal file
21
src/calendar.hpp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
struct calendar_information {
|
||||||
|
int current_day;
|
||||||
|
int current_month;
|
||||||
|
int current_month_days;
|
||||||
|
int current_year;
|
||||||
|
|
||||||
|
calendar_information();
|
||||||
|
};
|
||||||
|
|
||||||
|
class Calendar {
|
||||||
|
public:
|
||||||
|
static int get_days_in_month(int month, int year);
|
||||||
|
void set_day(int day);
|
||||||
|
void set_month(int month);
|
||||||
|
void set_year(int year);
|
||||||
|
calendar_information get_info();
|
||||||
|
|
||||||
|
Calendar(calendar_information *preinfo = nullptr);
|
||||||
|
private:
|
||||||
|
calendar_information info;
|
||||||
|
};
|
40
src/main.cpp
40
src/main.cpp
|
@ -1,39 +1,23 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ftxui/dom/elements.hpp>
|
#include <string.h>
|
||||||
#include <ftxui/component/screen_interactive.hpp>
|
#include <ncurses.h>
|
||||||
#include <ftxui/component/component.hpp>
|
#include <curses.h>
|
||||||
#include <ftxui/component/event.hpp>
|
#include "calendar.hpp"
|
||||||
|
|
||||||
|
#define MIN_WIDTH 100
|
||||||
|
#define MIN_HEIGHT 40
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace ftxui;
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
initscr();
|
||||||
|
|
||||||
auto screen = ScreenInteractive::FitComponent();
|
int active_cell = 0;
|
||||||
|
|
||||||
auto component = Renderer([&screen] {
|
for (;;) {
|
||||||
auto make_box = [](int x, int y, int i) {
|
|
||||||
string title = to_string(i);
|
|
||||||
return window(text(""), text(title) | hcenter | size(WIDTH, EQUAL, x) | size(HEIGHT, EQUAL, y));
|
|
||||||
};
|
|
||||||
|
|
||||||
Element calendar = hflow({
|
refresh();
|
||||||
make_box(12,7,0),
|
}
|
||||||
make_box(7,7,1),
|
|
||||||
make_box(7,7,2),
|
|
||||||
make_box(7,7,3),
|
|
||||||
make_box(7,7,4),
|
|
||||||
make_box(7,7,5),
|
|
||||||
make_box(7,7,6),
|
|
||||||
make_box(7,7,7)
|
|
||||||
});
|
|
||||||
|
|
||||||
return window(text("Vi Scheduler"), vbox(calendar));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
screen.Loop(component);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user