Skip to content

Commit 9229333

Browse files
authored
Theme/dimmable secondary columns (#554)
* Allows configuring secondary columns' opacity via theme parameter * a better label? * clang format * refactor as per #554 (comment) * Skip calculating secondary color when opacity is 100% * clang format
1 parent 06ac355 commit 9229333

11 files changed

+31
-5
lines changed

Source/NimbleCommander/NimbleCommander/Core/Theming/Theme.h

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class SWIFT_UNSAFE_REFERENCE Theme
9191
// File Panels --> List presentation settings //////////////////////////////////////////////////
9292
NSFont *FilePanelsListFont() const noexcept;
9393
unsigned FilePanelsListRowVerticalPadding() const noexcept;
94+
unsigned FilePanelsListSecondaryColumnsOpacity() const noexcept;
9495
NSColor *FilePanelsListGridColor() const noexcept;
9596
NSFont *FilePanelsListHeaderFont() const noexcept;
9697
NSColor *FilePanelsListHeaderBackgroundColor() const noexcept;

Source/NimbleCommander/NimbleCommander/Core/Theming/Theme.mm

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
NSColor *m_FilePanelsTabsPictogramColor;
4646
NSFont *m_FilePanelsListFont;
4747
unsigned m_FilePanelsListRowVerticalPadding;
48+
unsigned m_FilePanelsListSecondaryColumnsOpacity;
4849
NSColor *m_FilePanelsListGridColor;
4950
NSFont *m_FilePanelsListHeaderFont;
5051
NSColor *m_FilePanelsListHeaderBackgroundColor;
@@ -162,6 +163,7 @@
162163

163164
I->m_FilePanelsListFont = ExtractFont("filePanelsListFont");
164165
I->m_FilePanelsListRowVerticalPadding = ExtractUInt("filePanelsListRowVerticalPadding");
166+
I->m_FilePanelsListSecondaryColumnsOpacity = ExtractUInt("filePanelsListSecondaryColumnsOpacity");
165167
I->m_FilePanelsListGridColor = ExtractColor("filePanelsListGridColor");
166168

167169
I->m_FilePanelsHeaderFont = ExtractFont("filePanelsHeaderFont");
@@ -281,6 +283,11 @@
281283
return I->m_FilePanelsListRowVerticalPadding;
282284
}
283285

286+
unsigned Theme::FilePanelsListSecondaryColumnsOpacity() const noexcept
287+
{
288+
return I->m_FilePanelsListSecondaryColumnsOpacity;
289+
}
290+
284291
NSColor *Theme::FilePanelsListFocusedActiveRowBackgroundColor() const noexcept
285292
{
286293
return I->m_FilePanelsListFocusedActiveRowBackgroundColor;

Source/NimbleCommander/NimbleCommander/Core/Theming/ThemesManager.mm

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static constexpr auto make_array_n(T &&value)
6060
{"filePanelsFooterActiveBackgroundColor", TMN::FilePanelsFooter},
6161
{"filePanelsFooterInactiveBackgroundColor", TMN::FilePanelsFooter},
6262
{"filePanelsListFont", TMN::FilePanelsList},
63+
{"filePanelsListSecondaryColumnsOpacity", TMN::FilePanelsList},
6364
{"filePanelsListRowVerticalPadding", TMN::FilePanelsList},
6465
{"filePanelsListGridColor", TMN::FilePanelsList},
6566
{"filePanelsListHeaderFont", TMN::FilePanelsList},

Source/NimbleCommander/NimbleCommander/Preferences/PreferencesWindowThemesTabModel.mm

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ - (instancetype)initWithTitle:(NSString *)_title andChildren:(NSArray *)_childre
135135
auto fp_list_nodes = @[
136136
SpawnFontNode(@"Text font", "filePanelsListFont"),
137137
SpawnIntNode(@"Row vertical padding", "filePanelsListRowVerticalPadding"),
138+
SpawnIntNode(@"Secondary text opacity (%)", "filePanelsListSecondaryColumnsOpacity"),
138139
SpawnColorNode(@"Grid color", "filePanelsListGridColor"),
139140
SpawnFontNode(@"Header font", "filePanelsListHeaderFont"),
140141
SpawnColorNode(@"Header background", "filePanelsListHeaderBackgroundColor"),

Source/NimbleCommander/NimbleCommander/Resources/Config.json

+5
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@
587587

588588
/* File Panels -> List settings */
589589
"filePanelsListFont": "@systemFont, 13",
590+
"filePanelsListSecondaryColumnsOpacity": "100",
590591
"filePanelsListRowVerticalPadding": "0",
591592
"filePanelsListGridColor": "@clearColor",
592593
"filePanelsListHeaderFont": "@systemFont, 11",
@@ -710,6 +711,7 @@
710711

711712
/* File Panels -> List settings */
712713
"filePanelsListFont": "@systemFont, 13",
714+
"filePanelsListSecondaryColumnsOpacity": "100",
713715
"filePanelsListRowVerticalPadding": "0",
714716
"filePanelsListGridColor": "@clearColor",
715717
"filePanelsListHeaderFont": "@systemFont, 11",
@@ -850,6 +852,7 @@
850852

851853
/* File Panels -> List settings */
852854
"filePanelsListFont": "Menlo-Regular, 13",
855+
"filePanelsListSecondaryColumnsOpacity": "100",
853856
"filePanelsListRowVerticalPadding": "0",
854857
"filePanelsListGridColor": "#00FFFF",
855858
"filePanelsListHeaderFont": "Menlo-Regular, 13",
@@ -964,6 +967,7 @@
964967
"filePanelsFooterActiveBackgroundColor": "#FFFFFF",
965968
"filePanelsFooterInactiveBackgroundColor": "#E8E8E8",
966969
"filePanelsListFont": "@systemFont, 13",
970+
"filePanelsListSecondaryColumnsOpacity": "100",
967971
"filePanelsListRowVerticalPadding": "0",
968972
"filePanelsListGridColor": "#FFFFFF00",
969973
"filePanelsListHeaderFont": "@systemFont, 11",
@@ -1072,6 +1076,7 @@
10721076
"filePanelsFooterActiveBackgroundColor": "#353535",
10731077
"filePanelsFooterInactiveBackgroundColor": "#1D1D1D",
10741078
"filePanelsListFont": "@systemFont, 13",
1079+
"filePanelsListSecondaryColumnsOpacity": "100",
10751080
"filePanelsListGridColor": "#1D1D1D",
10761081
"filePanelsListRowVerticalPadding": "0",
10771082
"filePanelsListHeaderFont": "@systemFont, 11",

Source/NimbleCommander/NimbleCommander/States/FilePanels/List/PanelListViewDateTimeView.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ - (void)drawRect:(NSRect) [[maybe_unused]] _rect
164164
[PanelListViewTableView drawVerticalSeparatorForView:self];
165165

166166
if( m_Line ) {
167-
CGContextSetFillColorWithColor(context, rv.rowTextColor.CGColor);
167+
CGContextSetFillColorWithColor(context, rv.rowSecondaryTextColor.CGColor);
168168
CGContextSetTextPosition(context, geometry.LeftInset(), geometry.TextBaseLine());
169169
CGContextSetTextDrawingMode(context, kCGTextFill);
170170
CTLineDraw(m_Line, context);

Source/NimbleCommander/NimbleCommander/States/FilePanels/List/PanelListViewExtensionView.mm

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ - (void)buildPresentation
6969
PanelListViewRowView *row_view = static_cast<PanelListViewRowView *>(self.superview);
7070
if( !row_view )
7171
return;
72+
7273
NSDictionary *attrs = @{
7374
NSFontAttributeName: row_view.listView.font,
74-
NSForegroundColorAttributeName: row_view.rowTextColor,
75+
NSForegroundColorAttributeName: row_view.rowSecondaryTextColor,
7576
NSParagraphStyleAttributeName: g_Style
7677
};
7778
auto attr_str = [[NSMutableAttributedString alloc] initWithString:m_Extension attributes:attrs];
@@ -96,7 +97,7 @@ - (void)drawRect:(NSRect) [[maybe_unused]] _rect
9697
if( m_Line ) {
9798
const auto geometry = lv.geometry;
9899
const auto context = NSGraphicsContext.currentContext.CGContext;
99-
CGContextSetFillColorWithColor(context, rv.rowTextColor.CGColor);
100+
CGContextSetFillColorWithColor(context, rv.rowSecondaryTextColor.CGColor);
100101
CGContextSetTextPosition(context, geometry.LeftInset(), geometry.TextBaseLine());
101102
CGContextSetTextDrawingMode(context, kCGTextFill);
102103
CTLineDraw(m_Line.get(), context);

Source/NimbleCommander/NimbleCommander/States/FilePanels/List/PanelListViewRowView.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@property(nonatomic, weak) PanelListView *listView;
1919
@property(nonatomic, readonly) NSColor *rowBackgroundColor;
2020
@property(nonatomic, readonly) NSColor *rowTextColor;
21+
@property(nonatomic, readonly) NSColor *rowSecondaryTextColor;
2122
@property(nonatomic, readonly) NSColor *tagAccentColor; // may return nil when no accent should be drawn
2223
@property(nonatomic) bool panelActive;
2324
@property(nonatomic) int itemIndex;

Source/NimbleCommander/NimbleCommander/States/FilePanels/List/PanelListViewRowView.mm

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ @implementation PanelListViewRowView {
2222
data::ItemVolatileData m_VD;
2323
NSColor *m_RowColor;
2424
NSColor *m_TextColor;
25+
NSColor *m_TextSecondaryColor;
2526
NSColor *m_TagAccentColor;
2627
int m_ItemIndex;
2728
bool m_PanelActive;
@@ -30,6 +31,7 @@ @implementation PanelListViewRowView {
3031
}
3132
@synthesize rowBackgroundColor = m_RowColor;
3233
@synthesize rowTextColor = m_TextColor;
34+
@synthesize rowSecondaryTextColor = m_TextSecondaryColor;
3335
@synthesize tagAccentColor = m_TagAccentColor;
3436
@synthesize itemIndex = m_ItemIndex;
3537
@synthesize item = m_Item;
@@ -46,6 +48,7 @@ - (id)initWithItem:(VFSListingItem)_item
4648
m_ItemIndex = 0;
4749
m_RowColor = NSColor.whiteColor;
4850
m_TextColor = NSColor.blackColor;
51+
m_TextSecondaryColor = NSColor.blackColor;
4952
self.selected = false;
5053
[self updateColors];
5154
[self registerForDraggedTypes:PanelView.acceptedDragAndDropTypes];
@@ -249,6 +252,11 @@ - (void)updateColors
249252
auto new_row_fg_color = [self findCurrentTextColor];
250253
if( new_row_fg_color != m_TextColor ) {
251254
m_TextColor = new_row_fg_color;
255+
256+
if( const unsigned opacity = nc::CurrentTheme().FilePanelsListSecondaryColumnsOpacity(); opacity < 100 )
257+
m_TextSecondaryColor = [m_TextColor colorWithAlphaComponent:static_cast<double>(opacity) / 100.];
258+
else
259+
m_TextSecondaryColor = m_TextColor;
252260
colors_has_changed = true;
253261
}
254262

Source/NimbleCommander/NimbleCommander/States/FilePanels/List/PanelListViewSizeView.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ - (void)buildPresentation
144144
if( auto row_view = nc::objc_cast<PanelListViewRowView>(self.superview) ) {
145145
m_TextAttributes = @{
146146
NSFontAttributeName: row_view.listView.font,
147-
NSForegroundColorAttributeName: row_view.rowTextColor,
147+
NSForegroundColorAttributeName: row_view.rowSecondaryTextColor,
148148
NSParagraphStyleAttributeName: PStyle()
149149
};
150150
[self setNeedsDisplay:true];

Source/NimbleCommander/NimbleCommander/States/FilePanels/List/PanelListViewTagsView.mm

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ - (void)buildPresentation
7373
PanelListViewRowView *row_view = static_cast<PanelListViewRowView *>(self.superview);
7474
if( !row_view )
7575
return;
76+
7677
NSDictionary *attrs = @{
7778
NSFontAttributeName: row_view.listView.font,
78-
NSForegroundColorAttributeName: row_view.rowTextColor,
79+
NSForegroundColorAttributeName: row_view.rowSecondaryTextColor,
7980
NSParagraphStyleAttributeName: g_Style
8081
};
8182

0 commit comments

Comments
 (0)