class
Opal::PaletteModel
- Opal::PaletteModel
- Reference
- Object
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.crConstructors
- .from_content(content : String, format : PaletteFormat) : PaletteModel
-
.from_file(path : String) : PaletteModel
Parsing / importing constructors
- .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")
Class Method Summary
Instance Method Summary
-
#add(color : Color, name : String | Nil = nil) : Bool
Modification operations
-
#allow_add=(allow_add : Bool)
Action permissions
-
#allow_add? : Bool
Action permissions
- #allow_remove=(allow_remove : Bool)
- #allow_remove? : Bool
- #allow_rename=(allow_rename : Bool)
- #allow_rename? : Bool
- #allow_reorder=(allow_reorder : Bool)
- #allow_reorder? : Bool
-
#can_add? : Bool
Permission checks
- #can_remove? : Bool
- #can_rename? : Bool
- #can_reorder? : Bool
-
#color_at(index : Int32) : Color | Nil
Returns entry at index
-
#colors : Array(Color)
Returns array of colors in current display order
- #empty? : Bool
- #export(format : PaletteFormat | Symbol | String, name : String = @palette_name) : String
- #indexed_colors : Array(Color)
- #indexed_colors=(indexed_colors : Array(Color))
- #max_colors : Int32 | Nil
- #max_colors=(max_colors : Int32 | Nil)
-
#min_colors : Int32 | Nil
Size restrictions (nil = unbounded)
-
#min_colors=(min_colors : Int32 | Nil)
Size restrictions (nil = unbounded)
- #mode : PaletteMode
- #mode=(mode : PaletteMode)
-
#move(from_idx : Int32, to_idx : Int32) : Bool
Move item from one position to another
- #name_at(index : Int32) : String | Nil
- #named_entries : Array(NamedColorEntry)
- #named_entries=(named_entries : Array(NamedColorEntry))
- #palette_name : String
- #palette_name=(palette_name : String)
- #remove_at(index : Int32) : Bool
- #rename(index : Int32, new_name : String) : Bool
-
#size : Int32
Total count of colors/entries
-
#swap(index_a : Int32, index_b : Int32) : Bool
Swap two indices (used for
[and]reordering) - #to_css(prefix : String = "") : String
-
#to_gpl(name : String = @palette_name) : String
Export format methods
- #to_hex(with_hash : Bool = true) : String
- #to_json : String
- #to_pal : String
- #update_color(index : Int32, color : Color) : Bool
Constructor Detail
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")
#
Class Method Detail
Instance Method Detail
def export(format : PaletteFormat | Symbol | String, name : String = @palette_name) : String
#