| 1 |
|
| 2 |
|
| 3 |
require 'gtk3' |
| 4 |
|
| 5 |
、各パーツの座標の取得設定のためのモジュール |
| 6 |
module Gdk::Coordinate |
| 7 |
attr_accessor :width, :color, :icon_width, :icon_height, :icon_margin |
| 8 |
|
| 9 |
Coordinate = Data.define(:main_icon, :main_text, :header_text, :reply) |
| 10 |
|
| 11 |
DEPTH = Gdk::Visual.system.depth |
| 12 |
SCALE = Gdk::Visual.system.screen.resolution / 100 |
| 13 |
|
| 14 |
class Region |
| 15 |
extend Memoist |
| 16 |
|
| 17 |
def initialize(x, y, w, h) |
| 18 |
@x, @y, @w, @h = x, y, w, h end |
| 19 |
|
| 20 |
def point_in?(mx, my) |
| 21 |
left <= mx and mx <= right and top <= my and my <= bottom |
| 22 |
end |
| 23 |
|
| 24 |
[:x, :y, :w, :h].each{ |node| |
| 25 |
define_method(node){ |
| 26 |
n = instance_eval("@#{node}") |
| 27 |
if n.is_a?(Proc) |
| 28 |
n.call |
| 29 |
else |
| 30 |
n end } |
| 31 |
memoize node } |
| 32 |
|
| 33 |
def bottom |
| 34 |
y + h end |
| 35 |
|
| 36 |
def right |
| 37 |
x + w end |
| 38 |
|
| 39 |
alias :left :x |
| 40 |
alias :top :y |
| 41 |
alias :width :w |
| 42 |
alias :height :h |
| 43 |
end |
| 44 |
|
| 45 |
計算して返す |
| 46 |
def height |
| 47 |
@height ||= Hash.new |
| 48 |
@height[width] ||= |
| 49 |
[(main_message.size[1] + header_left.size[1]) / Pango::SCALE, icon_height].max + icon_margin*2 + subparts_height |
| 50 |
end |
| 51 |
|
| 52 |
def mainpart_height |
| 53 |
@mainpart_height ||= Hash.new |
| 54 |
@mainpart_height[width] ||= height - subparts_height - icon_margin |
| 55 |
end |
| 56 |
|
| 57 |
def reset_height |
| 58 |
if !@sid_modified && tree |
| 59 |
@sid_modified ||= ssc_atonce(:modified, tree) do |
| 60 |
tree.get_column(0).queue_resize |
| 61 |
signal_handler_disconnect(@sid_modified) if signal_handler_is_connected?(@sid_modified) |
| 62 |
@sid_modified = nil |
| 63 |
false |
| 64 |
end |
| 65 |
@height&.clear |
| 66 |
@mainpart_height&.clear |
| 67 |
on_modify |
| 68 |
end |
| 69 |
self |
| 70 |
rescue Gdk::MiraclePainter::DestroyedError |
| 71 |
self |
| 72 |
end |
| 73 |
|
| 74 |
def width=(new) |
| 75 |
if(@width != new) |
| 76 |
@width = [new, 1].max |
| 77 |
on_modify(true) end |
| 78 |
new |
| 79 |
end |
| 80 |
|
| 81 |
def scale(val) |
| 82 |
Gdk.scale(val) |
| 83 |
end |
| 84 |
|
| 85 |
protected |
| 86 |
|
| 87 |
の初期化 |
| 88 |
def coordinator(width) |
| 89 |
@width, @color, @icon_width, @icon_height, @icon_margin = [width, 1].max, DEPTH, scale(48), scale(48), scale(2) |
| 90 |
end |
| 91 |
|
| 92 |
構造体にまとめて返す |
| 93 |
def coordinate |
| 94 |
@coordinate ||= Coordinate.new( |
| 95 |
Region.new(icon_margin, ンアイコン |
| 96 |
icon_margin, |
| 97 |
icon_width, |
| 98 |
icon_height), |
| 99 |
Region.new(icon_width + icon_margin * 2, やき本文 |
| 100 |
lambda{ pos.header_text.bottom }, |
| 101 |
width - icon_width - icon_margin * 4, |
| 102 |
0), |
| 103 |
Region.new(icon_width + icon_margin * 2, ッダ |
| 104 |
icon_margin, |
| 105 |
width - (icon_width + icon_margin * 4), |
| 106 |
lambda{ header_left.size[1] / Pango::SCALE }) |
| 107 |
) |
| 108 |
end |
| 109 |
alias :pos :coordinate |
| 110 |
|
| 111 |
end |