mirror of
https://github.com/m1ngsama/TUT.git
synced 2026-02-08 00:54:05 +00:00
Major architectural refactoring from ncurses to FTXUI framework with professional engineering structure. Project Structure: - src/core/: Browser engine, URL parser, HTTP client - src/ui/: FTXUI components (main window, address bar, content view, panels) - src/renderer/: HTML renderer, text formatter, style parser - src/utils/: Logger, config manager, theme manager - tests/unit/: Unit tests for core components - tests/integration/: Integration tests - assets/: Default configs, themes, keybindings New Features: - btop-style four-panel layout with rounded borders - TOML-based configuration system - Multiple color themes (default, nord, gruvbox, solarized) - Comprehensive logging system - Modular architecture with clear separation of concerns Build System: - Updated CMakeLists.txt for modular build - Prefer system packages (Homebrew) over FetchContent - Google Test integration for testing - Version info generation via cmake/version.hpp.in Configuration: - Default config.toml with browser settings - Four built-in themes - Default keybindings configuration - Config stored in ~/.config/tut/ Removed: - Legacy v1 source files (ncurses-based) - Old render/ directory - Duplicate and obsolete test files - Old documentation files Binary: ~827KB (well under 5MB goal) Dependencies: FTXUI, cpp-httplib, toml11, gumbo-parser, OpenSSL
123 lines
2.3 KiB
C++
123 lines
2.3 KiB
C++
/**
|
|
* @file main_window.hpp
|
|
* @brief 主窗口模块
|
|
* @author m1ngsama
|
|
* @date 2024-12-29
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <memory>
|
|
#include <functional>
|
|
#include <vector>
|
|
|
|
namespace tut {
|
|
|
|
/**
|
|
* @brief 窗口事件类型
|
|
*/
|
|
enum class WindowEvent {
|
|
None,
|
|
Quit,
|
|
Navigate,
|
|
Back,
|
|
Forward,
|
|
Refresh,
|
|
Search,
|
|
AddBookmark,
|
|
OpenBookmarks,
|
|
OpenHistory,
|
|
OpenSettings,
|
|
OpenHelp,
|
|
};
|
|
|
|
/**
|
|
* @brief 链接信息 (用于内容显示)
|
|
*/
|
|
struct DisplayLink {
|
|
std::string text;
|
|
std::string url;
|
|
bool visited{false};
|
|
};
|
|
|
|
/**
|
|
* @brief 书签信息 (用于显示)
|
|
*/
|
|
struct DisplayBookmark {
|
|
std::string title;
|
|
std::string url;
|
|
};
|
|
|
|
/**
|
|
* @brief 主窗口类
|
|
*
|
|
* 负责整体 UI 布局和事件协调
|
|
* 采用 btop 风格的四分区布局
|
|
*/
|
|
class MainWindow {
|
|
public:
|
|
MainWindow();
|
|
~MainWindow();
|
|
|
|
/**
|
|
* @brief 初始化窗口
|
|
*/
|
|
bool init();
|
|
|
|
/**
|
|
* @brief 运行主事件循环
|
|
*/
|
|
int run();
|
|
|
|
// ========== 状态设置 ==========
|
|
|
|
void setStatusMessage(const std::string& message);
|
|
void setUrl(const std::string& url);
|
|
void setTitle(const std::string& title);
|
|
void setContent(const std::string& content);
|
|
void setLoading(bool loading);
|
|
|
|
// ========== 内容管理 ==========
|
|
|
|
/**
|
|
* @brief 设置页面链接列表
|
|
*/
|
|
void setLinks(const std::vector<DisplayLink>& links);
|
|
|
|
/**
|
|
* @brief 设置书签列表
|
|
*/
|
|
void setBookmarks(const std::vector<DisplayBookmark>& bookmarks);
|
|
|
|
/**
|
|
* @brief 设置历史记录列表
|
|
*/
|
|
void setHistory(const std::vector<DisplayBookmark>& history);
|
|
|
|
/**
|
|
* @brief 设置导航状态
|
|
*/
|
|
void setCanGoBack(bool can);
|
|
void setCanGoForward(bool can);
|
|
|
|
// ========== 统计信息 ==========
|
|
|
|
/**
|
|
* @brief 设置加载统计
|
|
*/
|
|
void setLoadStats(double elapsed_seconds, size_t bytes, int link_count);
|
|
|
|
// ========== 回调注册 ==========
|
|
|
|
void onNavigate(std::function<void(const std::string&)> callback);
|
|
void onEvent(std::function<void(WindowEvent)> callback);
|
|
void onLinkClick(std::function<void(int index)> callback);
|
|
void onBookmarkClick(std::function<void(const std::string& url)> callback);
|
|
|
|
private:
|
|
class Impl;
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|
|
|
|
} // namespace tut
|