diff options
| author | Amir Rajan <[email protected]> | 2020-07-25 16:46:32 -0500 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-07-25 16:46:32 -0500 |
| commit | 7fb2ac99d77e6f8c7506271f56cfdce766d5b2e3 (patch) | |
| tree | 0a989bf292764a52da5ab1c888161a46750a31ea /dragon/console_font_style.rb | |
| parent | aac51e8b318920de32fca1c0dd82a0fbc5a1bbfd (diff) | |
| download | dragonruby-game-toolkit-contrib-7fb2ac99d77e6f8c7506271f56cfdce766d5b2e3.tar.gz dragonruby-game-toolkit-contrib-7fb2ac99d77e6f8c7506271f56cfdce766d5b2e3.zip | |
added current docs
Diffstat (limited to 'dragon/console_font_style.rb')
| -rw-r--r-- | dragon/console_font_style.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/dragon/console_font_style.rb b/dragon/console_font_style.rb new file mode 100644 index 0000000..8efab4f --- /dev/null +++ b/dragon/console_font_style.rb @@ -0,0 +1,40 @@ +# Copyright 2019 DragonRuby LLC +# MIT License +# console_font_style.rb has been released under MIT (*only this file*). + +# Contributors outside of DragonRuby who also hold Copyright: +# - Kevin Fischer: https://github.com/kfischer-okarin + +module GTK + class Console + class FontStyle + attr_reader :font, :size_enum, :line_height + + def initialize(font:, size_enum:, line_height:) + @font = font + @size_enum = size_enum + @line_height = line_height + end + + def letter_size + @letter_size ||= $gtk.calcstringbox 'W', size_enum, font + end + + def line_height_px + @line_height_px ||= letter_size.y * line_height + end + + def label(x:, y:, text:, color:, alignment_enum: 0) + { + x: x, + y: y.shift_up(line_height_px), # !!! FIXME: remove .shift_up(line_height_px) when we fix coordinate origin on labels. + text: text, + font: font, + size_enum: size_enum, + alignment_enum: alignment_enum, + **color.to_h, + }.label + end + end + end +end |
