Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Meta/include/meta/ext/color_gradient/color_gradient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

#include <nlohmann/json.hpp>

namespace meta {
namespace meta
{

/// A color stop in a gradient.
struct Stop {
struct Stop
{
/// Position in the range [0, 1].
float position;

Expand All @@ -22,7 +24,8 @@ struct Stop {
};

/// A named color gradient preset.
struct Preset {
struct Preset
{
/// Preset name.
std::string name;

Expand All @@ -36,7 +39,8 @@ struct Preset {
/// type: they are host configuration, carried in attribute metadata as a
/// GradientPresets entry (keys::ui::presets), so that deserializing a value
/// cannot clobber the preset library installed at setup time.
class ColorGradient {
class ColorGradient
{
public:
/// Constructs a default black-to-white gradient.
ColorGradient() = default;
Expand Down Expand Up @@ -72,7 +76,8 @@ class ColorGradient {
/// Preset library for a gradient attribute, installed by the host into
/// attribute metadata under keys::ui::presets. Runtime configuration, not
/// document state: never serialized (mirrors meta::DataProvider).
struct GradientPresets {
struct GradientPresets
{
/// Available presets.
std::vector<Preset> presets;
};
Expand Down
42 changes: 23 additions & 19 deletions Meta/include/meta/ext/color_gradient/gradient_library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
#include "meta/core/event.hpp"
#include "meta/ext/color_gradient/color_gradient.hpp"

namespace meta {
namespace meta
{

/// Ordering applied to preset grids. Favourites are always pinned first.
enum class GradientSort {
enum class GradientSort
{
Default, ///< host order, then library insertion order
Name, ///< case-insensitive name
Luminance, ///< dark to light (gradient_luminance)
Expand All @@ -31,11 +33,12 @@ std::string_view to_string(GradientSort sort);
std::optional<GradientSort> gradient_sort_from_string(std::string_view text);

/// Outcome of GradientLibrary::import_file().
struct GradientImportReport {
struct GradientImportReport
{
std::size_t added = 0; ///< stored under their own name
std::size_t renamed = 0; ///< stored under a suffixed name (name clash)
std::size_t skipped = 0; ///< identical to an existing preset
bool ok = false; ///< file could be read and held gradients
bool ok = false; ///< file could be read and held gradients
};

/**
Expand All @@ -61,9 +64,9 @@ nlohmann::json gradient_file_json(const std::vector<Preset> &presets);
*
* @return The parsed presets, or std::nullopt when nothing usable was found.
*/
std::optional<std::vector<Preset>>
parse_gradient_file(const nlohmann::json &json,
std::string_view fallback_name = "Gradient");
std::optional<std::vector<Preset>> parse_gradient_file(
const nlohmann::json &json,
std::string_view fallback_name = "Gradient");

/**
* @brief The user's gradient presets, shared by every gradient widget in the
Expand All @@ -78,7 +81,8 @@ parse_gradient_file(const nlohmann::json &json,
* The Qt GradientPicker assigns a default per-user path on first use when
* none is set; call set_path() + load() beforehand to choose another.
*/
class GradientLibrary {
class GradientLibrary
{
public:
/// Fired after every effective mutation and after a successful load.
Event<> changed;
Expand Down Expand Up @@ -113,8 +117,8 @@ class GradientLibrary {
// --- user presets

const std::vector<Preset> &presets() const;
bool has(std::string_view name) const;
const Preset *find(std::string_view name) const;
bool has(std::string_view name) const;
const Preset *find(std::string_view name) const;

/**
* @brief Stores a preset. The name is trimmed ("Gradient" when empty) and
Expand All @@ -138,19 +142,19 @@ class GradientLibrary {

/// `base` if free, otherwise "base (2)", "base (3)", ...; names in
/// `reserved` (e.g. host presets) count as taken.
std::string unique_name(std::string_view base,
std::string unique_name(std::string_view base,
const std::vector<std::string> &reserved = {}) const;

// --- favourites

bool is_favorite(std::string_view name) const;
void set_favorite(std::string_view name, bool on);
bool is_favorite(std::string_view name) const;
void set_favorite(std::string_view name, bool on);
const std::vector<std::string> &favorites() const;

// --- sort preference

GradientSort sort() const;
void set_sort(GradientSort sort);
void set_sort(GradientSort sort);

// --- serialization

Expand All @@ -171,16 +175,16 @@ class GradientLibrary {

/// Writes `presets` as a gradient file (no favourites, no sort).
bool export_file(const std::filesystem::path &path,
const std::vector<Preset> &presets) const;
const std::vector<Preset> &presets) const;

private:
void on_modified();

std::vector<Preset> presets_;
std::vector<Preset> presets_;
std::vector<std::string> favorites_;
GradientSort sort_ = GradientSort::Default;
std::filesystem::path path_;
bool autosave_ = true;
GradientSort sort_ = GradientSort::Default;
std::filesystem::path path_;
bool autosave_ = true;
};

} // namespace meta
3 changes: 2 additions & 1 deletion Meta/include/meta/ext/color_gradient/gradient_metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

#include "meta/ext/color_gradient/color_gradient.hpp"

namespace meta {
namespace meta
{

/**
* @brief Colour of a gradient at position `t`.
Expand Down
Loading
Loading