-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSimpleColumnView.h
More file actions
121 lines (103 loc) · 3.23 KB
/
SimpleColumnView.h
File metadata and controls
121 lines (103 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef SIMPLE_COLUMN_VIEW_H
#define SIMPLE_COLUMN_VIEW_H
#include <Message.h>
#include <Messenger.h>
#include <Rect.h>
#include <ScrollView.h>
#include <String.h>
#include <View.h>
#include <vector>
/**
* @struct SimpleItem
* @brief Represents a single item in the SimpleColumnView.
*/
struct SimpleItem {
BString text; ///< The display text of the item.
BString path; ///< An associated hidden path or value (optional).
bool selected = false; ///< Selection state of the item.
};
/**
* @class SimpleColumnView
* @brief A lightweight, custom list view that supports single selection.
*
* This view renders a list of strings (with optional associated paths) in a
* vertical column. It handles drawing, scrollbar updates, and mouse interaction
* for selection. It sends a message to a target when the selection changes.
*/
class SimpleColumnView : public BView {
public:
/**
* @brief Constructor.
* @param name The name of the view (internal identifier).
*/
SimpleColumnView(const char *name);
/**
* @brief Adds an item with the given display text.
* @param text The text to display.
*/
void AddItem(const BString &text);
/**
* @brief Adds an item with display text and an associated hidden path/value.
* @param text The text to display.
* @param path The associated path or value.
*/
void AddItem(const BString &text, const BString &path);
/**
* @brief Removes all items from the list and clears selection.
*/
void Clear();
int32 CountItems() const;
const BString &ItemAt(int32 index) const;
const BString &PathAt(int32 index) const;
int32 CurrentSelection() const;
void Select(int32 index);
void RemoveItemAt(int32 index);
void ScrollToSelection();
void UpdateScrollbars();
float LineHeight() const;
void Draw(BRect updateRect) override;
void FrameResized(float width, float height) override;
void MouseDown(BPoint where) override;
void MessageReceived(BMessage *msg) override;
/**
* @brief Sets the command constant for the selection change message.
* @param what The command constant (e.g., MSG_SELECTION_CHANGED).
*/
void SetSelectionMessage(uint32 what);
/**
* @brief Sets the target messenger that receives selection notifications.
* @param target The BMessenger to send messages to.
*/
void SetTarget(BMessenger target);
/**
* @brief Virtual hook called when selection changes.
* @param index The index of the newly selected item.
*
* The default implementation sends the selection message to the target.
*/
virtual void SelectionChanged(int32 index);
/**
* @brief Sets a custom selection background color.
* @param color The custom selection color.
*/
void SetSelectionColor(rgb_color color);
protected:
/** @name Data */
///@{
std::vector<SimpleItem> fItems;
float fItemHeight;
int32 fCurrentSelection;
///@}
/** @name Notification */
///@{
uint32 fSelectionWhat = 0;
BMessenger fTarget;
///@}
/** @name Appearance */
///@{
rgb_color fSelectionColor;
rgb_color fSelectionTextColor;
bool fUseCustomColor = false;
///@}
};
#endif // SIMPLE_COLUMN_VIEW_H