Closes #16 : Reusable tileset properties widget

This commit is contained in:
2014-05-06 23:47:50 -07:00
parent 3feee8cb8e
commit 15f731461c
2 changed files with 43 additions and 11 deletions

View File

@@ -3,13 +3,12 @@ require 'wx'
module Tailor
module GUI
class TilesetProperties < Wx::Panel
def initialize(parent = nil,
id = Wx::ID_ANY,
pos = Wx::DEFAULT_POSITION,
size = Wx::DEFAULT_SIZE,
style = Wx::TAB_TRAVERSAL,
name = "TilesetProperties")
super(parent, id, pos, size, style, name)
def create_method( name, &block )
self.class.send( :define_method, name, &block )
end
def initialize(*args)
super(*args)
values = {
"Tile X" => 32,
"Tile Y" => 32,
@@ -19,12 +18,28 @@ module Tailor
"Space Y" => 0
}
@sizer = Wx::BoxSizer.new(Wx::VERTICAL)
self.set_sizer(@sizer)
values.each_pair do |elem, value|
tmpsizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
Wx::StaticText.new(tmpsizer, Wx::ID_ANY, elem)
self.send(elem.gsub(/ /, ''), Wx::TextCtrl.new(tmpsizer, Wx::ID_ANY, value.to_s))
tmpsizer.add(Wx::StaticText.new(self,
Wx::ID_ANY,
elem),
flag = Wx::EXPAND|Wx::ALIGN_LEFT)
elemCtrl = Wx::TextCtrl.new(self,
Wx::ID_ANY,
value.to_s)
tmpsizer.add(elemCtrl, flag = Wx::EXPAND|Wx::ALIGN_RIGHT)
rubyname = elem.gsub(/ /, '')
create_method( "@#{rubyname}=".to_sym ) { |val|
elemCtrl.set_value(val)
}
create_method( "#{rubyname}".to_sym ) {
elemCtrl.get_value
}
@sizer.add(tmpsizer)
end
@sizer.set_size_hints(self)
end
end
end