• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂458 (tree)
時間2012-05-02 18:21:13
作者ornse01

Log Message

implement parts layout
- flush left
- flush right
- centering
- justification

Change Summary

差異

--- bchanf/trunk/src/tools/panel_generator.rb (revision 457)
+++ bchanf/trunk/src/tools/panel_generator.rb (revision 458)
@@ -191,6 +191,14 @@
191191 };
192192 end
193193 end
194+ def layout
195+ case @yaml["layout"]
196+ when "flush left", "flush right", "centering", "justification"
197+ return @yaml["layout"];
198+ else
199+ return "flush left"
200+ end
201+ end
194202
195203 def height
196204 h = 0;
@@ -201,10 +209,10 @@
201209 }
202210 return h;
203211 end
204- def width
212+ def width(margin)
205213 w = 0;
206214 @items.each { |item|
207- w += item.width;
215+ w += item.width + margin;
208216 }
209217 return w;
210218 end
@@ -270,7 +278,7 @@
270278 def content_width
271279 w = @margin_left + @margin_right;
272280 @lines.each { |line|
273- w2 = @margin_left + line.width + @margin_right;
281+ w2 = @margin_left + line.width(@margin_left + @margin_right) + @margin_right;
274282 if w2 > w
275283 w = w2
276284 end
@@ -307,18 +315,38 @@
307315 erb.result(binding)
308316 end
309317
318+ def calc_line_layout_left(content_width, line)
319+ case line.layout
320+ when "flush left", "justification"
321+ return @panel_padding_left + @margin_left;
322+ when "flush right"
323+ return @panel_padding_left + content_width - line.width;
324+ when "centering"
325+ return @panel_padding_left + (content_width - line.width) / 2;
326+ end
327+ end
328+ def calc_line_layout_item_margin(content_width, line)
329+ case line.layout
330+ when "justification"
331+ return @margin_right + @margin_left + (content_width - line.width(@margin_left + @margin_right)) / (line.items.length - 1);
332+ else
333+ return @margin_right + @margin_left;
334+ end
335+ end
336+
310337 def generate_source_function_pnl_item_value_each()
338+ cw = self.content_width;
311339 n = 0;
312- left = @panel_padding_left + @margin_left;
313340 top = @panel_padding_top + @margin_top;
314341 @lines.each { |l|
342+ left = self.calc_line_layout_left(cw, l);
343+ margin = self.calc_line_layout_item_margin(cw, l);
315344 l.items.each { |i|
316345 s = i.generate_pnl_item_value(n, left, top);
317346 yield(s);
318347 n += 1;
319- left += i.width + @margin_right + @margin_left;
348+ left += i.width + margin;
320349 }
321- left = @panel_padding_left + @margin_left;
322350 top += l.height + @margin_bottom + @margin_top;
323351 }
324352 end
Show on old repository browser