From b90f1181cee4ad19dff0a24e704a4aa9e23c4447 Mon Sep 17 00:00:00 2001 From: Kittycannon Date: Mon, 20 Apr 2026 20:16:16 -0600 Subject: [PATCH] continue --- src/desktoplib/terminal/ui/Content.hpp | 21 ++++++++ src/desktoplib/terminal/ui/Element.hpp | 0 src/desktoplib/terminal/ui/InnerScroll.cpp | 59 ++++++++++++++++++++++ src/desktoplib/terminal/ui/InnerScroll.hpp | 36 +++++++++++++ src/desktoplib/terminal/ui/Theme.hpp | 9 ---- src/desktoplib/terminal/ui/TitledBox.hpp | 3 -- 6 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 src/desktoplib/terminal/ui/Content.hpp delete mode 100644 src/desktoplib/terminal/ui/Element.hpp create mode 100644 src/desktoplib/terminal/ui/InnerScroll.cpp delete mode 100644 src/desktoplib/terminal/ui/Theme.hpp delete mode 100644 src/desktoplib/terminal/ui/TitledBox.hpp diff --git a/src/desktoplib/terminal/ui/Content.hpp b/src/desktoplib/terminal/ui/Content.hpp new file mode 100644 index 0000000..8c64710 --- /dev/null +++ b/src/desktoplib/terminal/ui/Content.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include + +namespace ckitty::terminal { + + class Content { + public: + + virtual ~Content() = default; + + // Content must report how tall it wants to be + virtual int getTotalHeight() const = 0; + + // Render only the rows between startRow and endRow + // relativeY is where the Content starts drawing in terminal space + virtual void render(Terminal& t, pos screenPos, pos viewport, std::pair rows) const = 0; + + }; + +} \ No newline at end of file diff --git a/src/desktoplib/terminal/ui/Element.hpp b/src/desktoplib/terminal/ui/Element.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/desktoplib/terminal/ui/InnerScroll.cpp b/src/desktoplib/terminal/ui/InnerScroll.cpp new file mode 100644 index 0000000..acde2b6 --- /dev/null +++ b/src/desktoplib/terminal/ui/InnerScroll.cpp @@ -0,0 +1,59 @@ +#include "InnerScroll.hpp" + +namespace ckitty::terminal { + + InnerScroll::InnerScroll(pos p, int w, int h, Content& c) + : position(p), width(w), height(h), _content(c) { + } + + void InnerScroll::scroll(int delta) { + int maxScroll = std::max(0, _content.getTotalHeight() - height); + scrollY = std::clamp(scrollY + delta, 0, maxScroll); + } + + void InnerScroll::render(Terminal& t) const { + int totalH = _content.getTotalHeight(); + int viewH = height; + int contentWidth = width - 1; // Last column reserved for scrollbar + + // 1. Render the Content Viewport + // We only ask content to draw what fits in our height + int start = scrollY; + int end = std::min(totalH, scrollY + viewH); + + _content.render(t, position, pos(contentWidth, height), { start, end }); + + // 2. Clear empty space if content is shorter than viewport + if (end - start < viewH) { + for (int y = (end - start); y < viewH; ++y) { + t << pos{ position.x, position.y + y } + << std::string(contentWidth, ' '); + } + } + + // 3. Render Scrollbar Track + int scrollX = position.x + width - 1; + t << trackColor; + for (int y = 0; y < viewH; ++y) { + t << pos{ scrollX, position.y + y } << "░"; + } + + // 4. Render Scrollbar Thumb + if (totalH > viewH) { + // Calculate thumb height (proportional to visibility) + int thumbH = std::max(1, (viewH * viewH) / totalH); + + // Calculate thumb position + float scrollPercent = (float)scrollY / (totalH - viewH); + int thumbPos = (int)(scrollPercent * (viewH - thumbH)); + + t << thumbColor; + for (int y = 0; y < thumbH; ++y) { + t << pos{ scrollX, position.y + thumbPos + y } << "█"; + } + } + + t << style::RESET; + } + +} \ No newline at end of file diff --git a/src/desktoplib/terminal/ui/InnerScroll.hpp b/src/desktoplib/terminal/ui/InnerScroll.hpp index 139597f..935dc7b 100644 --- a/src/desktoplib/terminal/ui/InnerScroll.hpp +++ b/src/desktoplib/terminal/ui/InnerScroll.hpp @@ -1,2 +1,38 @@ +#pragma once +#include +#include +#include + +namespace ckitty::terminal { + + class InnerScroll : public UI { + public: + + pos position; + int width, height; + int scrollY = 0; // The top-most visible row of the content + + // Styling + color trackColor = color::B_BLACK; + color thumbColor = color::WHITE; + + private: + Content& _content; + + public: + + InnerScroll(pos p, int w, int h, Content& c); + + public: + + void render(Terminal& t) const override; + + // Helper to scroll + void scroll(int delta); + + void scrollTo(int row); + + }; +} \ No newline at end of file diff --git a/src/desktoplib/terminal/ui/Theme.hpp b/src/desktoplib/terminal/ui/Theme.hpp deleted file mode 100644 index 5918b97..0000000 --- a/src/desktoplib/terminal/ui/Theme.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - - -namespace ckitty { - namespace terminal { - - - } -} \ No newline at end of file diff --git a/src/desktoplib/terminal/ui/TitledBox.hpp b/src/desktoplib/terminal/ui/TitledBox.hpp deleted file mode 100644 index 45dcbb0..0000000 --- a/src/desktoplib/terminal/ui/TitledBox.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -