Skip to content

Commit

Permalink
fix: highlight selected menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaDucak committed Dec 26, 2023
1 parent bbe8631 commit 82cbd69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions source/view/windowed_menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ namespace caps_log::view {
using namespace ftxui;

class WindowedMenu : public ComponentBase {
int m_selected;
int m_selected = 0;

public:
WindowedMenu(std::string title, MenuOption option) {
// TODO: messy, callers can specify their own 'selected' but get overriden here?
option.selected = &m_selected;
auto menuComponent = Menu(std::move(option));
auto menuRenderer =
Renderer(menuComponent, [title = std::move(title), menu = menuComponent]() {
auto windowElement =
window(text(title), menu->Render() | frame) | size(WIDTH, LESS_THAN, 25);
if (not menu->Focused())
if (not menu->Focused()) {
windowElement |= dim;
}
return windowElement;
});
Add(menuRenderer);
Expand Down
15 changes: 9 additions & 6 deletions source/view/yearly_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,24 @@ CalendarOption YearView::makeCalendarOptions(const Date &today, bool sundayStart
option.transform = [this, today](const auto &date, const auto &state) {
auto element = text(state.label);

if (today == date)
if (today == date) {
element = element | color(Color::Red);
else if (m_highlightedLogsMap && m_highlightedLogsMap->get(date))
} else if (m_highlightedLogsMap && m_highlightedLogsMap->get(date)) {
element = element | color(Color::Yellow);
else if (date.isWeekend())
} else if (date.isWeekend()) {
element = element | color(Color::Blue);
}

if (state.focused)
if (state.focused) {
element = element | inverted;
}

if (m_availabeLogsMap) {
if (m_availabeLogsMap->get(date))
if (m_availabeLogsMap->get(date)) {
element = element | underlined;
else
} else {
element = element | dim;
}
}

return element | center;
Expand Down

0 comments on commit 82cbd69

Please sign in to comment.