mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
helper: Added createPalette, and a Palette interface change
This commit is contained in:
parent
6567639465
commit
21166a044f
6 changed files with 32 additions and 16 deletions
|
@ -46,18 +46,14 @@ Palette::Palette ()
|
|||
Color ("black on bright cyan"),
|
||||
Color ("black on bright yellow"),
|
||||
};
|
||||
|
||||
_current = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Palette::initialize (const Rules& rules)
|
||||
void Palette::add (Color c)
|
||||
{
|
||||
auto themeColors = rules.all ("theme.palette.color");
|
||||
if (themeColors.size ())
|
||||
{
|
||||
_colors.clear ();
|
||||
for (auto& entry : themeColors)
|
||||
_colors.push_back (Color (rules.get (entry)));
|
||||
}
|
||||
_colors.push_back (c);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -77,3 +73,10 @@ int Palette::size () const
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Palette::clear ()
|
||||
{
|
||||
_colors.clear ();
|
||||
_current = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -36,9 +36,10 @@ class Palette
|
|||
{
|
||||
public:
|
||||
Palette ();
|
||||
void initialize (const Rules&);
|
||||
void add (Color);
|
||||
Color next ();
|
||||
int size () const;
|
||||
void clear ();
|
||||
|
||||
public:
|
||||
bool enabled {true};
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <Palette.h>
|
||||
#include <format.h>
|
||||
#include <timew.h>
|
||||
#include <algorithm>
|
||||
|
@ -189,7 +188,7 @@ int CmdDiagnostics (
|
|||
if (rules.getBoolean ("color"))
|
||||
{
|
||||
out << " ";
|
||||
Palette palette;
|
||||
auto palette = createPalette (rules);
|
||||
for (int color = 0; color < palette.size (); ++color)
|
||||
{
|
||||
if (color && color % 16 == 0)
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <Palette.h>
|
||||
#include <Composite.h>
|
||||
#include <Color.h>
|
||||
#include <Range.h>
|
||||
|
@ -54,10 +53,7 @@ int CmdReportDay (
|
|||
auto excluded = timeline.excluded (rules);
|
||||
|
||||
// Create a color palette.
|
||||
Palette palette;
|
||||
palette.initialize (rules);
|
||||
palette.enabled = rules.getBoolean ("color");
|
||||
|
||||
auto palette = createPalette (rules);
|
||||
Color colorExc (palette.enabled ? rules.get ("theme.colors.exclusion") : "");
|
||||
Color colorLabel (palette.enabled ? rules.get ("theme.colors.label") : "");
|
||||
|
||||
|
|
|
@ -537,6 +537,22 @@ std::vector <Range> combineHolidaysAndExclusions (
|
|||
return addRanges (range, results, exclusionRanges);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Palette createPalette (const Rules& rules)
|
||||
{
|
||||
Palette p;
|
||||
auto colors = rules.all ("theme.palette.color");
|
||||
if (colors.size ())
|
||||
{
|
||||
p.clear ();
|
||||
for (auto& c : colors)
|
||||
p.add (Color (rules.get (c)));
|
||||
}
|
||||
|
||||
p.enabled = rules.getBoolean ("color");
|
||||
return p;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Extract the tags from a set of intervals, and using a rotating color palette,
|
||||
// map unique tags to color.
|
||||
|
|
|
@ -58,6 +58,7 @@ std::vector <Range> addRanges (const Range&, const std::vector <Range>&, const s
|
|||
std::vector <Range> subtractRanges (const Range&, const std::vector <Range>&, const std::vector <Range>&);
|
||||
Range overallRangeFromIntervals (const std::vector <Interval>&);
|
||||
std::vector <Range> combineHolidaysAndExclusions (const Range&, const Rules&, const std::vector <Exclusion>&);
|
||||
Palette createPalette (const Rules&);
|
||||
std::map <std::string, Color> createTagColorMap (const Rules&, Palette&, const std::vector <Interval>&);
|
||||
int quantizeTo15Minutes (const int);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue