Sha256: 94d517bb1f1d6e495a21e4f604791f52fd340f7612ea2dc0b0182ac835cfe0f5

Contents?: true

Size: 1.62 KB

Versions: 11

Compression:

Stored size: 1.62 KB

Contents

<!--
# @markup markdown
# @title 7. wxRuby Colour and Font
-->

# 6. wxRuby Colour and Font

## Introduction

The wxWidgets API makes use of typical C++ features to support automatic conversion of certain types providing
user friendly options for argument specifications. This way for example a developer does not need to explicitly
declare a colour object construction where a colour instance value is expected but rather can specify a simple string
constant like:

```C++
wxPen pen;
pen.SetColour("CYAN"); // instead of pen.SetColour(wxColour("CYAN"));
```

For the wxRuby API similar support has been achieved for various much used argument types.  

## Colour

Wherever a `Wx::Colour` object is expected as an argument wxRuby supports the specification of `String` or `Symbol`
values as a developer friendly alternative. This way the following code is equivalent:

```ruby
pen = Wx::Pen.new
pen.set_colour(Wx::Colour.new("CYAN"))

pen = Wx::Pen.new
pen.set_colour("CYAN")

pen = Wx::Pen.new
pen.set_colour(:CYAN)
```

## Font

Wherever a `Wx::Font` object is expected as an argument wxRuby supports the specification of a `Wx::FontInfo` object.
This way the following code is equivalent:

```ruby
title = Wx::StaticText.new(self, -1, "Title")
title.set_font(Wx::Font.new(18, Wx::FontFamily::FONTFAMILY_SWISS, Wx::FontStyle::FONTSTYLE_NORMAL, Wx::FontWeight::FONTWEIGHT_BOLD))

title = Wx::StaticText.new(self, -1, "Title")
title.set_font(Wx::FontInfo.new(18)
                 .family(Wx::FontFamily::FONTFAMILY_SWISS)
                 .style(Wx::FontStyle::FONTSTYLE_NORMAL)
                 .bold())
```

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
wxruby3-0.9.0.pre.rc.3-x64-mingw-ucrt lib/wx/doc/extra/07_colour_and_font.md
wxruby3-0.9.0.pre.rc.2-x64-mingw-ucrt lib/wx/doc/extra/07_colour_and_font.md
wxruby3-0.9.0.pre.rc.1-x64-mingw-ucrt lib/wx/doc/extra/07_colour_and_font.md
wxruby3-0.9.0.pre.beta.14-x64-mingw-ucrt lib/wx/doc/extra/07_colour_and_font.md
wxruby3-0.9.0.pre.beta.13-x64-mingw-ucrt lib/wx/doc/extra/07_colour_and_font.md
wxruby3-0.9.0.pre.beta.11-x64-mingw-ucrt lib/wx/doc/extra/07_colour_and_font.md
wxruby3-0.9.0.pre.beta.10-x64-mingw-ucrt lib/wx/doc/extra/07_colour_and_font.md
wxruby3-0.9.0.pre.beta.9-x64-mingw-ucrt lib/wx/doc/extra/07_colour_and_font.md
wxruby3-0.9.0.pre.beta.8-x64-mingw-ucrt lib/wx/doc/extra/07_colour_and_font.md
wxruby3-0.9.0.pre.beta.2-x64-mingw-ucrt-3.2-3.2.2 lib/wx/doc/extra/07_colour_and_font.md
wxruby3-0.9.0.pre.beta.1-x64-mingw-ucrt-3.2 lib/wx/doc/extra/07_colour_and_font.md