Skip to content

Commit 6550b55

Browse files
committed
Merge branch 'develop' of https://github.com/plugdata-team/plugdata into develop
2 parents 86c9eb2 + bd03f9c commit 6550b55

File tree

4 files changed

+45
-30
lines changed

4 files changed

+45
-30
lines changed

Source/Components/DraggableNumber.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,21 +370,19 @@ class DraggableNumber : public Label
370370

371371
// NOTE: We could simply do `String(numberText.getDoubleValue(), 0)` but using string manipulation
372372
// bypasses any potential issues with precision
373-
auto removeDecimalNumString = [](String& numString) {
373+
auto removeDecimalNumString = [](String& numString) -> String {
374374
if (numString.contains(".")) {
375375
// Split the string into the integer and fractional parts
376376
StringArray parts = StringArray::fromTokens(numString, ".", "");
377377

378-
// If the fractional part is "0" or empty, remove the decimal point
379-
if (parts[1] == "0" || parts[1].isEmpty()) {
380-
return parts[0]; // Just keep the integer part
381-
} else {
382-
return numString; // Keep the full string (with decimal point & fractional part)
378+
// If fractional only contains zeros, only return the first part (no decimal point)
379+
if (parts[1].removeCharacters("0").isEmpty()) {
380+
return parts[0];
383381
}
384-
} else {
385-
// If there’s no decimal point, leave the string as it is
386382
return numString;
387383
}
384+
// If there’s no decimal point, leave the string as it is
385+
return numString;
388386
};
389387

390388
// Only display the decimal point if fractional exists, but make sure to show it as a user hovers over the fractional decimal places

Source/Components/WelcomePanel.h

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ class WelcomePanel : public Component
230230

231231
String creationTimeDescription = String();
232232
String modifiedTimeDescription = String();
233+
String accessedTimeDescription = String();
233234
String fileSizeDescription = String();
234235

235236
File patchFile;
@@ -246,24 +247,33 @@ class WelcomePanel : public Component
246247

247248
auto is24Hour = OSUtils::is24HourTimeFormat();
248249

249-
auto formatTimeDescription = [is24Hour](const Time& openTime) {
250-
auto diff = Time::getCurrentTime() - openTime;
250+
auto formatTimeDescription = [is24Hour](const Time& openTime, bool showDayAndDate = false) {
251+
auto const now = Time::getCurrentTime();
251252

252-
String date;
253-
auto days = diff.inDays();
254-
if (days < 1)
255-
date = "Today";
256-
else if (days > 1 && days < 2)
257-
date = "Yesterday";
258-
else
259-
date = openTime.toString(true, false);
253+
// Extract just the date part (YYYY-MM-DD) for comparison
254+
auto const openDate = openTime.toISO8601(true).substring(0, 10);
255+
auto const currentDate = now.toISO8601(true).substring(0, 10);
256+
auto const yesterday = (now - RelativeTime::days(1)).toISO8601(true).substring(0, 10);
257+
258+
String dateOrDay;
259+
if (openDate == currentDate) {
260+
dateOrDay = "Today";
261+
} else if (openDate == yesterday) {
262+
dateOrDay = "Yesterday";
263+
}
260264

261265
String time = openTime.toString(false, true, false, is24Hour);
262266

263-
return date + ", " + time;
267+
if (showDayAndDate)
268+
return (dateOrDay.isNotEmpty() ? dateOrDay + ", " : "") + openTime.toString(true, false) + ", " + time;
269+
270+
return (dateOrDay.isNotEmpty() ? dateOrDay : openTime.toString(true, false)) + ", " + time;
271+
264272
};
265273

266-
tileSubtitle = formatTimeDescription(Time(static_cast<int64>(subTree.getProperty("Time"))));
274+
auto const accessedInPlugdasta = Time(static_cast<int64>(subTree.getProperty("Time")));
275+
276+
tileSubtitle = formatTimeDescription(accessedInPlugdasta);
267277

268278
auto const fileSize = patchFile.getSize();
269279

@@ -275,8 +285,13 @@ class WelcomePanel : public Component
275285
fileSizeDescription = String(fileSize / (1024.0 * 1024.0), 2) + " MiB"; // 1 MiB or more
276286
}
277287

278-
creationTimeDescription = formatTimeDescription(patchFile.getCreationTime());
279-
modifiedTimeDescription = formatTimeDescription(patchFile.getLastModificationTime());
288+
creationTimeDescription = formatTimeDescription(patchFile.getCreationTime(), true);
289+
modifiedTimeDescription = formatTimeDescription(patchFile.getLastModificationTime(), true);
290+
// Accessed time will show the last time the file was read, which is when the Home panel has been refreshed.
291+
// We need to show the time accessed from plugdata, which is saved in the settings XML
292+
// We want to show this again as well as in the subtile, but format it differently (with both Today/Yesterday and date)
293+
// because the popup menu may occlude the tile + subtitle
294+
accessedTimeDescription = formatTimeDescription(accessedInPlugdasta, true);
280295

281296
updateGeneratedThumbnailIfNeeded(thumbImage, svgImage, iconColour);
282297
}
@@ -331,7 +346,7 @@ class WelcomePanel : public Component
331346
patchInfoSubMenu.addSeparator();
332347
patchInfoSubMenu.addItem(String("Created: " + creationTimeDescription), false, false, nullptr);
333348
patchInfoSubMenu.addItem(String("Modified: " + modifiedTimeDescription), false, false, nullptr);
334-
patchInfoSubMenu.addItem(String("Accessed: " + tileSubtitle), false, false, nullptr);
349+
patchInfoSubMenu.addItem(String("Accessed: " + accessedTimeDescription), false, false, nullptr);
335350
tileMenu.addSubMenu(String(tileName + ".pd file info"), patchInfoSubMenu, true);
336351
tileMenu.addSeparator();
337352
// TODO: we may want to be clearer about this - that it doesn't delete the file on disk

Source/Statusbar.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,11 +1329,9 @@ void Statusbar::updateZoomLevel()
13291329

13301330
void Statusbar::paint(Graphics& g)
13311331
{
1332-
if(welcomePanelIsShown) return;
1333-
13341332
g.setColour(findColour(PlugDataColour::toolbarOutlineColourId));
13351333

1336-
auto start = !editor->palettes->isExpanded() ? 29.0f : 0.0f;
1334+
auto start = !editor->palettes->isExpanded() && editor->palettes->isVisible() ? 29.0f : 0.0f;
13371335
auto end = editor->sidebar->isHidden() ? 29.0f : 0.0f;
13381336
g.drawLine(start, 0.5f, static_cast<float>(getWidth()) - end, 0.5f);
13391337

Source/Utility/CachedTextRender.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ class CachedTextRender {
2121
nvgFillRect(nvg, bounds.getX(), bounds.getY(), bounds.getWidth() + 3, bounds.getHeight());
2222
}
2323

24-
AttributedString getSyntaxHighlightedString(String const& text, Font const& font, Colour const& colour)
24+
AttributedString getSyntaxHighlightedString(String const& text, Font const& font, Colour const& colour, Colour const& nameColour)
2525
{
2626
auto attributedText = AttributedString();
2727
auto tokens = StringArray::fromTokens(text, true);
2828

29-
auto nameColour = colour.interpolatedWith(LookAndFeel::getDefaultLookAndFeel().findColour(PlugDataColour::dataColourId), 0.7f);
3029
auto flagColour = colour.interpolatedWith(LookAndFeel::getDefaultLookAndFeel().findColour(PlugDataColour::signalColourId), 0.7f);
3130

3231
bool firstToken = true;
@@ -55,10 +54,13 @@ class CachedTextRender {
5554
{
5655
auto textHash = hash(text);
5756
bool needsUpdate = lastTextHash != textHash || colour != lastColour || cachedWidth != lastWidth || highlightObjectSyntax != isSyntaxHighlighted;
58-
if (needsUpdate) {
57+
auto nameColour = colour.interpolatedWith(LookAndFeel::getDefaultLookAndFeel().findColour(PlugDataColour::dataColourId), 0.7f);
58+
bool highlightTextNeedsUpdaste = highlightObjectSyntax ? lastTextHighlightedColour != nameColour : false;
59+
60+
if (needsUpdate || highlightTextNeedsUpdaste) {
5961
AttributedString attributedText;
6062
if (highlightObjectSyntax) {
61-
attributedText = getSyntaxHighlightedString(text, font, colour);
63+
attributedText = getSyntaxHighlightedString(text, font, colour, nameColour);
6264
attributedText.setJustification(Justification::centredLeft);
6365
} else {
6466
attributedText = AttributedString(text);
@@ -75,6 +77,7 @@ class CachedTextRender {
7577

7678
lastTextHash = textHash;
7779
lastColour = colour;
80+
lastTextHighlightedColour = nameColour;
7881
isSyntaxHighlighted = highlightObjectSyntax;
7982
updateImage = true;
8083
}
@@ -103,6 +106,7 @@ class CachedTextRender {
103106
hash32 lastTextHash = 0;
104107
float lastScale = 1.0f;
105108
Colour lastColour;
109+
Colour lastTextHighlightedColour;
106110
int lastWidth = 0;
107111
int idealWidth = 0, idealHeight = 0;
108112
Rectangle<int> lastRenderBounds;

0 commit comments

Comments
 (0)