lib/shoes/basic.rb in green_shoes-0.150.0 vs lib/shoes/basic.rb in green_shoes-0.164.0
- old
+ new
@@ -1,9 +1,10 @@
class Shoes
class Basic
include Mod
def initialize args
+ @initials = args
args.each do |k, v|
instance_variable_set "@#{k}", v
end
(@app.order << self) unless @noorder or self.is_a?(EditBox) or self.is_a?(EditLine)
@@ -25,11 +26,11 @@
[:app, :real].each{|k| args.delete k}
@args = args
@hided, @shows, @hovered = false, true, false
end
- attr_reader :parent, :click_proc, :release_proc, :hover_proc, :leave_proc, :args, :shows
+ attr_reader :parent, :click_proc, :release_proc, :hover_proc, :leave_proc, :args, :shows, :initials
attr_accessor :hided, :hovered
def move x, y
@app.cslot.contents -= [self]
@app.canvas.move @real, x, y
@@ -93,10 +94,37 @@
max = self
end
max
end
+ def fix_size
+ flag = false
+ set_margin
+ case self
+ when EditBox, Button
+ if 0 < @initials[:width] and @initials[:width] <= 1.0
+ @width = @parent.width * @initials[:width] - @margin_left - @margin_right
+ flag = true
+ end
+ if 0 < @initials[:height] and @initials[:height] <= 1.0
+ @height = @parent.height * @initials[:height] - @margin_top - @margin_bottom
+ flag = true
+ end
+ when EditLine, ListBox
+ if 0 < @initials[:width] and @initials[:width] <= 1.0
+ @width = @parent.width * @initials[:width] - @margin_left - @margin_right
+ @height = 26
+ flag = true
+ end
+ else
+ end
+ if flag
+ @real.set_size_request @width, @height
+ move @left, @top
+ end
+ end
+
def click &blk
@click_proc = blk
@app.mccs << self
end
@@ -124,11 +152,26 @@
@real = @app.send(m, args, &blk).real
end
end
class Image < Basic; end
- class Button < Basic; end
+ class Button < Basic
+ def click &blk
+ real.signal_connect "clicked", &blk if blk
+ end
+ end
+ class ToggleButton < Button
+ def checked?
+ real.active?
+ end
+
+ def checked=(tof)
+ real.active = tof
+ end
+ end
+ class Check < ToggleButton; end
+ class Radio < ToggleButton; end
class Pattern < Basic
def move2 x, y
return if @hided
clear if @real
@@ -164,9 +207,10 @@
end
def text= s
clear if @real
@width = (@left + parent.width <= @app.width) ? parent.width : @app.width - @left
+ @width = initials[:width] unless initials[:width].zero?
@height = 20 if @height.zero?
m = self.class.to_s.downcase[7..-1]
args = [s, @args.merge({left: @left, top: @top, width: @width, height: @height, create_real: true, nocontrol: true})]
tb = @app.send(m, *args)
@real, @height, @args[:markup] = tb.real, tb.height, tb.markup