class Opal::PaletteModel

Overview

Core data model for a color palette. Encapsulates either a Named palette (String -> Color) or an Indexed palette (Array(Color)), with min/max size constraints, add/rename/remove/reorder permissions, and format conversion.

Defined in:

opal/style/palette_model.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.from_content(content : String, format : PaletteFormat) : PaletteModel #

[View source]
def self.from_file(path : String) : PaletteModel #

Parsing / importing constructors


[View source]
def self.new(mode : PaletteMode = PaletteMode::Indexed, indexed_colors : Array(Color) | Nil = nil, named_entries : Array(NamedColorEntry | Tuple(String, Color)) | Hash(String, Color) | Nil = nil, min_colors : Int32 | Nil = nil, max_colors : Int32 | Nil = nil, allow_add : Bool = true, allow_rename : Bool = true, allow_remove : Bool = true, allow_reorder : Bool = true, palette_name : String = "Opal Palette") #

[View source]

Class Method Detail

def self.detect_format(content : String) : PaletteFormat #

[View source]

Instance Method Detail

def add(color : Color, name : String | Nil = nil) : Bool #

Modification operations


[View source]
def allow_add=(allow_add : Bool) #

Action permissions


[View source]
def allow_add? : Bool #

Action permissions


[View source]
def allow_remove=(allow_remove : Bool) #

[View source]
def allow_remove? : Bool #

[View source]
def allow_rename=(allow_rename : Bool) #

[View source]
def allow_rename? : Bool #

[View source]
def allow_reorder=(allow_reorder : Bool) #

[View source]
def allow_reorder? : Bool #

[View source]
def can_add? : Bool #

Permission checks


[View source]
def can_remove? : Bool #

[View source]
def can_rename? : Bool #

[View source]
def can_reorder? : Bool #

[View source]
def color_at(index : Int32) : Color | Nil #

Returns entry at index


[View source]
def colors : Array(Color) #

Returns array of colors in current display order


[View source]
def empty? : Bool #

[View source]
def export(format : PaletteFormat | Symbol | String, name : String = @palette_name) : String #

[View source]
def indexed_colors : Array(Color) #

[View source]
def indexed_colors=(indexed_colors : Array(Color)) #

[View source]
def max_colors : Int32 | Nil #

[View source]
def max_colors=(max_colors : Int32 | Nil) #

[View source]
def min_colors : Int32 | Nil #

Size restrictions (nil = unbounded)


[View source]
def min_colors=(min_colors : Int32 | Nil) #

Size restrictions (nil = unbounded)


[View source]
def mode : PaletteMode #

[View source]
def mode=(mode : PaletteMode) #

[View source]
def move(from_idx : Int32, to_idx : Int32) : Bool #

Move item from one position to another


[View source]
def name_at(index : Int32) : String | Nil #

[View source]
def named_entries : Array(NamedColorEntry) #

[View source]
def named_entries=(named_entries : Array(NamedColorEntry)) #

[View source]
def palette_name : String #

[View source]
def palette_name=(palette_name : String) #

[View source]
def remove_at(index : Int32) : Bool #

[View source]
def rename(index : Int32, new_name : String) : Bool #

[View source]
def size : Int32 #

Total count of colors/entries


[View source]
def swap(index_a : Int32, index_b : Int32) : Bool #

Swap two indices (used for [ and ] reordering)


[View source]
def to_css(prefix : String = "") : String #

[View source]
def to_gpl(name : String = @palette_name) : String #

Export format methods


[View source]
def to_hex(with_hash : Bool = true) : String #

[View source]
def to_json : String #

[View source]
def to_pal : String #

[View source]
def update_color(index : Int32, color : Color) : Bool #

[View source]