ashbb / green_shoes

Green Shoes is one of the colorful Shoes written in pure Ruby.
Other
204 stars 37 forks source link

Adapted width so that a float value will be used as percentage #20

Closed eargollo closed 13 years ago

ashbb commented 13 years ago

Hi eargollo,

Thank you for the pull request. Looks cool!

I tried to merge your pull request and tested some sample snippets.
Sample1-8 worked very well, but sample9 got an error.

Try to run the following:

Shoes.app do
  flow(width: 300){para 'hello'}
end

I think we need to debug a little bit for your request. ;-)

Cheers,
ashbb

eargollo commented 13 years ago

Sory ashbb, the patch was done but I made a mistake on using git (first time using it), and made a wrong rollback.

ashbb commented 13 years ago

Tried out your latest commit. Almost all 46 samples worked well.
Okay, last one is sample44. I got the following error:

green_shoes/lib/shoes/app.rb:373:in `initialize': out of memory (NoMemoryError)

Umm,... this may not be your problem, but your commit may expose a hidden bug.
We need one more debugging. ;-)

eargollo commented 13 years ago

I found out what causes the problem but not the problem itself.

The cause of this is on initially setting up a width both on application and slots.

So, this example would go ok if in main.rb:19 you comment the width set up

app.top_slot = Flow.new app.slot_attributes(app: app, left: 0, top: 0) #, width: args[:width])

And on slot.rb you also do not set width up at the beginning. So the getter would become a calculator for the future as: ... def initialize args={} @initials = args args.each do |k, v| instance_variable_set "@#{k}", v #if k != :width end

  Slot.class_eval do
    attr_accessor *(args.keys - [:app])#, :width])
  end

  set_margin

  @masked = false
  @parent = @app.cslot
  @app.cslot = self
  @contents = []
  (@parent.contents << self) unless @nocontrol
  if block_given?
    yield
    @app.cslot = @parent
  else
    @left = @top = 0
  end
end

attr_accessor :contents, :masked
attr_reader :parent, :initials
attr_writer :app

def calc_width
  value = case 
    when @initials[:width] == nil then @parent.width 
    when @initials[:width].is_a?(Float) then (@parent.width * @initials[:width]).to_i
    when @initials[:width] < 0 then (@parent.width + @initials[:width])
    else @initials[:width]
  end
  return(value - (margin_left + margin_right))
end

#def width=(value)
  #@initials[:width] = value
#end

def app &blk
  blk ? @app.instance_eval(&blk) : @app
end

def move3 x, y
  @left, @top = x, y
end

def positioning x, y, max
  @width = calc_width
  if parent.is_a?(Flow) and x + @width <= parent.left + parent.width
  #if parent.is_a?(Flow) and x + self.width <= parent.left + parent.width
    move3 x + parent.margin_left, max.top + parent.margin_top
    @height = Shoes.contents_alignment self
    max = self if max.height < @height
  else
    move3 parent.left + parent.margin_left, max.top + max.height + parent.margin_top
    @height = Shoes.contents_alignment self
    max = self
  end
  max.height = @height = @initials[:height] unless @initials[:height].zero?
  max
end

...

Problem is that with those two modifications, it is not possible to set proportional width.

Do you have any idea on what setting width at the initialize may cause a memory allocation problem?

Well, I will keep on searching the cause.

Regards

ashbb commented 13 years ago

eargollo,

Thank you for the great hack. :)

Problem is that with those two modifications, it is not possible to set proportional width.

You are right. I've no idea to solve this problem so far.

If user uses float number for an element's width/height value, user expects that the element will be also resized when Green Shoes app window is resized by hand.

Umm,... it may be better to find another different approach....

ashbb

ashbb commented 13 years ago

This is a solution. It doesn't work for all kind of elements, but works for EditBox, EditLine, ListBox and Button.

eargollo commented 13 years ago

Thanks ashbb. Despite it is not the most elegant one, this is a solution. I decided to take a look on what happens with the line that it is taking so much memory whenever the width is set. Anyway, in parallel I will keep porting my app.