Class: Wx::MDAP::MaterialDesignArtProvider

Inherits:
ArtProvider
  • Object
show all
Defined in:
lib/wx/mdap/provider.rb

Overview

Material Design art provider class.

This derived Wx::ArtProvider class implements all required overrides to support the full functionality of Wx::ArtProvider to access a set of Material Design SVG Art consisting of nearly 9000 images distributed over 11 lists from Fluent UI, Font Awesome, Material Design and Simple Icons collections (see the README for more information).

Identifying art resources

Each list from these collections has been mapped to a distinct Art Client id and for each image a distinct Art id has been defined.
See here for all defined Art (Client) id constants.

Art overviews

Overviews of the available icons for the various Art Client id/Art id combinations can be found at the following locations:

Extensions

The MaterialDesignArtProvider class provides a number of extensions to customize the default colour and default size for MaterialDesignArtProvider returned images as well a mapping scheme for standard wxRuby3 Art (Client) ids to MaterialDesignArtProvider specific ids.

Managing Art colour

By default MaterialDesignArtProvider will return images in the colour as defined in the original SVG which is usually BLACK. This can be overridden by using either of 2 methods; MaterialDesignArtProvider.use_art_colour and/or MaterialDesignArtProvider.with_art_colour.

Managing Art size

When requesting images from MaterialDesignArtProvider with Wx::DEFAULT_SIZE by default the size used will be derived from Wx::ArtProvider.get_native_size_hint. In case this returns Wx::DEFAULT_SIZE itself the default will be Wx::Size.new(24,24). This can be overridden by using MaterialDesignArtProvider.set_default_size. Use MaterialDesignArtProvider.get_default_size to see what the current default size will be.

Mapping standard wxRuby3 Art ids

MaterialDesignArtProvider implements a fixed mapping scheme for mapping standard wxRuby3 Art ids (like Wx::ART_ERROR, Wx::FILE_SAVE, Wx::ART_FOLDER etc.) to MaterialDesignArtProvider Art ids (defined in Wx::MDAP). An overview of this mapping scheme can be found here.
In addition to that MaterialDesignArtProvider implements a customizable mapping scheme for mapping standard wxRuby3 Art Client ids (like Wx::ART_MENU, Wx::ART_TOOLBAR, Wx::ART_OTHER etc.) to MaterialDesignArtProvider Art Client ids (defined in Wx::MDAP). By default all standard Art Client ids are mapped to ART_FLUENT_UI_REGULAR. This can be overridden by using MaterialDesignArtProvider.map_std_client_id.

Class Method Summary collapse

Class Method Details

.get_default_size(client) ⇒ Wx::size

Returns the default art size for the given (standard or Material Design) Art Client id. By default will derive default from ArtProvider.get_native_size_hint.

Parameters:

  • client (String)

    Art Client id

Returns:

  • (Wx::size)

Raises:

  • (ArgumentError)


135
136
137
138
139
140
141
142
# File 'lib/wx/mdap/provider.rb', line 135

def get_default_size(client)
  raise ArgumentError, "Invalid art client id [#{client}]" unless std_client_ids.include?(client) || MDAP.has_art_client_id?(client)
  unless default_sizes.has_key?(client)
    def_sz = Wx::ArtProvider.get_native_size_hint(client)
    default_sizes[client] = (def_sz == Wx::DEFAULT_SIZE ? Wx::Size.new(24,24) : def_sz)
  end
  default_sizes[client]
end

.map_std_client_id(std_client_id, md_client_id) ⇒ Object

Sets the MDAP client id to use when a std wxRuby3 ClientArtId is passed to Wx::MDAP::MaterialDesignArtProvider. By default the alternative id used for any standard id is ART_FLUENT_UI_REGULAR. The std_client_id passed should be one of:

  • ART_TOOLBAR
  • ART_MENU
  • ART_BUTTON
  • ART_FRAME_ICON
  • ART_CMN_DIALOG
  • ART_HELP_BROWSER
  • ART_MESSAGE_BOX
  • ART_OTHER

The md_client_id passed should be one of:

Parameters:

  • std_client_id (String)

    the standard client id to map

  • md_client_id (String)

    the alternative Material Design client id to use

Raises:

  • (ArgumentError)


179
180
181
182
183
# File 'lib/wx/mdap/provider.rb', line 179

def map_std_client_id(std_client_id, md_client_id)
  raise ArgumentError, "Invalid standard art client id [#{std_client_id}]" unless std_client_ids.include?(std_client_id)
  raise ArgumentError, "Invalid Material Design art client id [#{md_client_id}]" unless MDAP.has_art_client_id?(md_client_id)
  std_client_id_map[std_client_id] = md_client_id
end

.set_default_size(client, size) ⇒ Object

Sets the default art size for the given (standard or Material Design) Art Client id.

Parameters:

  • client (String)

    Art Client id

  • size (Wx::Size, Array(Integer,Integer))

Raises:

  • (ArgumentError)


147
148
149
150
# File 'lib/wx/mdap/provider.rb', line 147

def set_default_size(client, size)
  raise ArgumentError, "Invalid art client id [#{client}]" unless std_client_ids.include?(client) || MDAP.has_art_client_id?(client)
  default_sizes[client] = size.to_size
end

.use_art_colour(colour) ⇒ Object

Sets the active colour to use for created MaterialDesign art. By default the colour is nil (which is equivalent to :BLACK).

Parameters:

  • colour (Wx::Colour, String, Symbol, nil)


114
115
116
# File 'lib/wx/mdap/provider.rb', line 114

def use_art_colour(colour)
  set_art_colour(colour)
end

.with_art_colour(colour) ⇒ Object

Sets the active colour to use for created MaterialDesign art in the scope of the given block. After the block returns the colour is restored to it’s setting from before the block.

Parameters:

  • colour (Wx::Colour, String, Symbol, nil)


121
122
123
124
125
126
127
128
129
# File 'lib/wx/mdap/provider.rb', line 121

def with_art_colour(colour)
  prev_colour = art_colour
  begin
    set_art_colour(colour)
    yield if block_given?
  ensure
    set_art_colour(prev_colour)
  end
end