Skip to content

Commit

Permalink
重构CSS 添加控件属性默认值
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxblade committed Jul 2, 2015
1 parent 85e4b29 commit a456768
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 193 deletions.
14 changes: 13 additions & 1 deletion lib/shenmegui/controls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def self.shortcut(prop)

end

def self.default(params)
@default_properties = params
end

def self.default_properties
@default_properties
end

available_events = %w{click input dblclick mouseover mouseout blur focus mousedown mouseup change select}.collect(&:to_sym)
available_events.each do |x|
define_method("on#{x}") do |&block|
Expand Down Expand Up @@ -72,7 +80,7 @@ def sync_events
end

def initialize(params={})
@properties = {}
@properties = self.class.default_properties || {}
update_properties(params)
@id = ShenmeGUI.elements.size
ShenmeGUI.elements << self
Expand Down Expand Up @@ -109,6 +117,7 @@ def render(material = {})

class Form < Base
property :title
default :width=>'400px'
end

class Button < Base
Expand All @@ -130,6 +139,7 @@ def text=(v)
class Textarea < Base
property :text, :selection
shortcut :text
default :width=>'250px', :height=>'60px'

def <<(t)
text << "\n#{t}"
Expand Down Expand Up @@ -160,6 +170,7 @@ class Checkbox < Base
class Progress < Base
property :percent
shortcut :percent
default :width=>'100%'

def validate(params)
params[:percent] = 0 if params[:percent] < 0
Expand All @@ -185,6 +196,7 @@ class Label < Base
class Table < Base
property :data
shortcut :data
default :width=>'100%', :height=>'150px'

def << row
data << row
Expand Down
74 changes: 27 additions & 47 deletions static/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a456768

Please sign in to comment.