Skip to content

Commit e8c3644

Browse files
committed
feat: Add new widgets and factory functions to TUIKit
- Introduced new widgets: TUITreeView, TUITextArea, TUIProgressBar, TUIScrollableContainer. - Added widget and layout aliases for easier usage. - Implemented factory functions for new widgets to streamline widget creation. - Updated TUIStyle to remove the Default theme and refactor theme initialization. - Fixed potential out-of-bounds access in TUIComboBox, TUIMenu, and TUIRadioBox by using size_t for index comparisons. - Refactored TUIButton to correct the order of member variables. - Enhanced TUIComboBox to track the last known index for better state management. - Cleaned up constructor parameters in TUITextField and TUIWidget.
1 parent a74c3b5 commit e8c3644

14 files changed

Lines changed: 351 additions & 308 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/archives
2-
/build
2+
/build/
3+
/external/
34
/docs
45
/log.txt

CMakeLists.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ endif()
2323
# FTXUI
2424
include(FetchContent)
2525

26-
FetchContent_Declare(ftxui
27-
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
28-
GIT_TAG v6.1.9
26+
# Set a persistent directory for external dependencies
27+
set(FETCHCONTENT_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
28+
29+
FetchContent_Declare(
30+
ftxui
31+
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
32+
GIT_TAG v6.1.9
2933
)
3034

31-
FetchContent_GetProperties(ftxui)
32-
if(NOT ftxui_POPULATED)
33-
FetchContent_Populate(ftxui)
34-
add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
35-
endif()
35+
# This makes the dependency available and adds its targets (e.g., ftxui::screen)
36+
FetchContent_MakeAvailable(ftxui)
3637

3738
# =============================================================================
3839
# PROJECT STRUCTURE

examples/main.cpp

Lines changed: 93 additions & 182 deletions
Large diffs are not rendered by default.

include/tuikit.h

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,128 @@
2323
#include "tuikit/widgets/TUIForm.h"
2424
#include "tuikit/widgets/TUIStatusBar.h"
2525
#include "tuikit/widgets/TUIToolbar.h"
26+
#include "tuikit/widgets/TUITreeView.h"
27+
#include "tuikit/widgets/TUITextArea.h"
28+
#include "tuikit/widgets/TUIProgressBar.h"
29+
#include "tuikit/widgets/TUIScrollableContainer.h"
30+
31+
32+
#include <memory>
33+
#include <string>
34+
#include <vector>
35+
36+
namespace TUIKIT {
37+
38+
// Widget Aliases
39+
using Widget = std::shared_ptr<TUIWidget>;
40+
using Button = std::shared_ptr<TUIButton>;
41+
using CheckBox = std::shared_ptr<TUICheckBox>;
42+
using Collapsible = std::shared_ptr<TUICollapsible>;
43+
using ComboBox = std::shared_ptr<TUIComboBox>;
44+
using Form = std::shared_ptr<TUIForm>;
45+
using GroupBox = std::shared_ptr<TUIGroupBox>;
46+
using Label = std::shared_ptr<TUILabel>;
47+
using Menu = std::shared_ptr<TUIMenu>;
48+
using ProgressBar = std::shared_ptr<TUIProgressBar>;
49+
using RadioBox = std::shared_ptr<TUIRadioBox>;
50+
using ResizableSplit = std::shared_ptr<TUIResizableSplit>;
51+
using ScrollableContainer = std::shared_ptr<TUIScrollableContainer>;
52+
using Slider = std::shared_ptr<TUISlider>;
53+
using StatusBar = std::shared_ptr<TUIStatusBar>;
54+
using TabWidget = std::shared_ptr<TUITabWidget>;
55+
using TextArea = std::shared_ptr<TUITextArea>;
56+
using TextField = std::shared_ptr<TUITextField>;
57+
using Toolbar = std::shared_ptr<TUIToolbar>;
58+
using TreeView = std::shared_ptr<TUITreeView>;
59+
60+
// Layout Aliases
61+
using Layout = std::shared_ptr<TUILayout>;
62+
using HBoxLayout = std::shared_ptr<TUIHBoxLayout>;
63+
using VBoxLayout = std::shared_ptr<TUIVBoxLayout>;
64+
65+
// Factory Functions
66+
inline Button button(const std::string& text) {
67+
return std::make_shared<TUIButton>(text);
68+
}
69+
70+
inline CheckBox checkbox(const std::string& text, bool initial_checked = false) {
71+
return std::make_shared<TUICheckBox>(text, initial_checked);
72+
}
73+
74+
inline Collapsible collapsible(const std::string& title, Widget content) {
75+
return std::make_shared<TUICollapsible>(title, content);
76+
}
77+
78+
inline ComboBox combobox(const std::vector<std::string>& options, int initial_selected = 0) {
79+
return std::make_shared<TUIComboBox>(options, initial_selected);
80+
}
81+
82+
inline Form form() {
83+
return std::make_shared<TUIForm>();
84+
}
85+
86+
inline GroupBox groupbox(const std::string& title, Widget content, bool show_border = true) {
87+
return std::make_shared<TUIGroupBox>(title, content, show_border);
88+
}
89+
90+
inline Label label(const std::string& text = "") {
91+
return std::make_shared<TUILabel>(text);
92+
}
93+
94+
inline Menu menu(const std::vector<std::string>& options) {
95+
return std::make_shared<TUIMenu>(options);
96+
}
97+
98+
inline ProgressBar progressbar(float initial_value = 0.0f, const std::string& label = "") {
99+
return std::make_shared<TUIProgressBar>(initial_value, label);
100+
}
101+
102+
inline RadioBox radiobox(const std::vector<std::string>& options, int initial_selected = 0) {
103+
return std::make_shared<TUIRadioBox>(options, initial_selected);
104+
}
105+
106+
inline ResizableSplit resizable_split(Widget first, Widget second, TUIResizableSplit::Orientation orientation = TUIResizableSplit::Horizontal) {
107+
return std::make_shared<TUIResizableSplit>(first, second, orientation);
108+
}
109+
110+
inline ScrollableContainer scrollable_container(Widget content, int height) {
111+
return std::make_shared<TUIScrollableContainer>(content, height);
112+
}
113+
114+
inline Slider slider(const std::string& label, float initial_value, float min_value, float max_value, float increment) {
115+
return std::make_shared<TUISlider>(label, initial_value, min_value, max_value, increment);
116+
}
117+
118+
inline StatusBar statusbar(const std::string& message = "") {
119+
return std::make_shared<TUIStatusBar>(message);
120+
}
121+
122+
inline TabWidget tabwidget() {
123+
return std::make_shared<TUITabWidget>();
124+
}
125+
126+
inline TextArea textarea(const std::string& placeholder = "", const std::string& label = "", int height = 5) {
127+
return std::make_shared<TUITextArea>(placeholder, label, height);
128+
}
129+
130+
inline TextField textfield(const std::string& placeholder = "") {
131+
return std::make_shared<TUITextField>(placeholder);
132+
}
133+
134+
inline Toolbar toolbar() {
135+
return std::make_shared<TUIToolbar>();
136+
}
137+
138+
inline TreeView treeview(TreeNode root_node) {
139+
return std::make_shared<TUITreeView>(root_node);
140+
}
141+
142+
// Layout Factories
143+
inline HBoxLayout hbox() {
144+
return std::make_shared<TUIHBoxLayout>();
145+
}
146+
147+
inline VBoxLayout vbox() {
148+
return std::make_shared<TUIVBoxLayout>();
149+
}
150+
}

include/tuikit/core/TUIStyle.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace TUIKIT {
99

1010
// Enum for predefined themes
1111
enum class Theme {
12-
Default,
1312
Dark,
1413
Light,
1514
Monokai,

include/tuikit/widgets/TUIButton.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class TUIButton : public TUIWidget {
2121
const std::string& icon() const;
2222

2323
private:
24-
std::string text_; // This will hold the text displayed by the FTXUI button (icon + original_text_)
2524
std::string original_text_; // This will hold the text provided by the user, without the icon
25+
std::string text_; // This will hold the text displayed by the FTXUI button (icon + original_text_)
2626
std::string icon_;
2727
OnClickedCallback on_clicked_;
2828
ftxui::Component ftxui_button_component_;

include/tuikit/widgets/TUIComboBox.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class TUIComboBox : public TUIWidget {
1818
private:
1919
std::vector<std::string> options_;
2020
int selected_index_ = 0;
21+
int last_known_index_ = -1; // To track changes
2122
OnSelectCallback on_select_;
2223
ftxui::Component ftxui_dropdown_component_;
2324
void update_ftxui_dropdown_component();

src/core/TUIApp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ int TUIApp::exec() {
154154
if (show_modal_) {
155155
return modal_->OnEvent(event);
156156
} else {
157-
if (!pages_.empty() && active_page_ >= 0 && active_page_ < pages_.size()) {
157+
if (!pages_.empty() && active_page_ >= 0 && static_cast<size_t>(active_page_) < pages_.size()) {
158158
ftxui::Component active_page_component = pages_[active_page_];
159159
if (active_page_component->OnEvent(event)) {
160160
return true;
@@ -198,7 +198,7 @@ void TUIApp::add_page(const std::string& name, ftxui::Component page) {
198198
}
199199

200200
void TUIApp::set_active_page(int index) {
201-
if (index >= 0 && index < pages_.size()) {
201+
if (index >= 0 && static_cast<size_t>(index) < pages_.size()) {
202202
active_page_ = index;
203203
}
204204
}

0 commit comments

Comments
 (0)