Skip to content

Commit

Permalink
screen: use class Point in struct Layout
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 5, 2024
1 parent ebf4e93 commit 321c391
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/screen.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@ class ScreenManager {
struct Layout {
Size size;

static constexpr int title_y = 0, title_x = 0;
static constexpr int main_y = TitleBar::GetHeight(), main_x = 0;
static constexpr Point title{0, 0};
static constexpr Point main{0, (int)TitleBar::GetHeight()};
static constexpr int progress_x = 0;
static constexpr int status_x = 0;

constexpr explicit Layout(Size _size) noexcept
:size(_size) {}

constexpr unsigned GetMainRows() const noexcept {
return GetProgressY() - main_y;
return GetProgress().y - main.y;
}

constexpr Size GetMainSize() const noexcept {
return {size.width, GetMainRows()};
}

constexpr int GetProgressY() const noexcept {
return GetStatusY() - 1;
constexpr Point GetProgress() const noexcept {
return {progress_x, GetStatus().y - 1};
}

constexpr int GetStatusY() const noexcept {
return size.height - 1;
constexpr Point GetStatus() const noexcept {
return {status_x, (int)size.height - 1};
}
};

Expand Down
15 changes: 6 additions & 9 deletions src/screen_init.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ ScreenManager::ScreenManager(EventLoop &event_loop) noexcept
:paint_event(event_loop, BIND_THIS_METHOD(Paint)),
layout({std::max<unsigned>(COLS, SCREEN_MIN_COLS),
std::max<unsigned>(LINES, SCREEN_MIN_ROWS)}),
title_bar({layout.title_x, layout.title_y}, layout.size.width),
main_window({layout.main_x, layout.main_y}, layout.GetMainSize()),
progress_bar({layout.progress_x, layout.GetProgressY()}, layout.size.width),
status_bar(event_loop,
{layout.status_x, layout.GetStatusY()}, layout.size.width),
title_bar(layout.title, layout.size.width),
main_window(layout.main, layout.GetMainSize()),
progress_bar(layout.GetProgress(), layout.size.width),
status_bar(event_loop, layout.GetStatus(), layout.size.width),
mode_fn_prev(&screen_queue)
{
buf_size = layout.size.width;
Expand Down Expand Up @@ -70,12 +69,10 @@ ScreenManager::OnResize() noexcept
main_window.Resize(layout.GetMainSize());

/* progress window */
progress_bar.OnResize({layout.progress_x, layout.GetProgressY()},
layout.size.width);
progress_bar.OnResize(layout.GetProgress(), layout.size.width);

/* status window */
status_bar.OnResize({layout.status_x, layout.GetStatusY()},
layout.size.width);
status_bar.OnResize(layout.GetStatus(), layout.size.width);

buf_size = layout.size.width;
delete[] buf;
Expand Down

0 comments on commit 321c391

Please sign in to comment.