Changeset 213

Show
Ignore:
Timestamp:
09/28/2007 18:13:45 (11 months ago)
Author:
why
Message:

* shoes/ruby.c: adding a span inline, which does just like HTML, for applying adhoc styles.
* samples/: updating some samples with the new methods, still needs lots of work obviously.

Location:
trunk
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • trunk/samples/anim.rb

    r96 r213  
    11Shoes.app do 
    22  stack :top => 0.5, :left => 0.5 do 
    3     text "Counting up:" 
    4     l = text "0" 
     3    para "Counting up:" 
     4    l = para "0" 
    55    animate(24) do |i| 
    66      f = ['Arial 14px', 'Serif 34px', 'Monospace 18px', 'Arial 48px'][rand(3)] 
    7       l.replace "<span font_desc='#{f}'>#{i}</span>" 
     7      l.replace "#{i}", :font => f 
    88    end 
    99    motion do |x, y| 
  • trunk/samples/book.rb

    r194 r213  
    1010 
    1111  def table_of_contents 
    12     toc = "<span font_desc='Arial 11px'>" 
     12    toc = [] 
    1313    INCIDENTS.each_with_index do |(title, story), i| 
    14       toc += "(#{i + 1}) <a href='/incidents/#{i}'>#{title}</a> " 
     14      toc.push "(#{i + 1}) ", 
     15        link(title, :url => "/incidents/#{i}"), 
     16        " / " 
    1517    end 
    16     toc + "</span>" 
     18    toc.pop 
     19    span *toc 
    1720  end 
    1821 
     
    2023    num = num.to_i 
    2124    flow :margin => 10, :margin_left => 190, :margin_top => 20 do 
    22       text "<span font_desc='Arial 46px'>Incident</span>\n" + 
    23         "<b>No. #{num + 1}: #{INCIDENTS[num][0]}</b>" 
     25      banner "Incident\n" 
     26      para strong("No. #{num + 1}: #{INCIDENTS[num][0]}") 
    2427    end 
    2528    flow :width => 180, :margin_left => 10, :margin_top => 10 do 
    26       text table_of_contents 
     29      para table_of_contents, :font => "Arial 12px" 
    2730    end 
    2831    flow :width => -190, :margin => 10 do 
    29       text INCIDENTS[num][1] 
     32      para INCIDENTS[num][1] 
    3033    end 
    3134  end 
  • trunk/samples/calc.rb

    r172 r213  
    4646 
    4747    stack :margin => 8 do 
    48       number_field = text "<b>#{number}</b>" 
     48      number_field = para strong(number) 
    4949    end 
    5050 
     
    6363           
    6464          number.send(method) 
    65           number_field.replace "<b>#{number} </b>" 
     65          number_field.replace strong(number) 
    6666        end 
    6767      end 
  • trunk/samples/dialogs.rb

    r24 r213  
    2020  end 
    2121 
    22   @answer = text "Answers appear here" 
     22  @answer = para "Answers appear here" 
    2323end 
  • trunk/samples/edit.rb

    r127 r213  
    33  background rgb(77, 77, 77) 
    44  stack :margin => 10 do 
    5     text "<span color='white'><span color='red' background='white'>TEXT EDITOR</span> * USE ALT-Q TO QUIT</span>" 
     5    para span("TEXT EDITOR", :stroke => red, :fill => white), " * USE ALT-Q TO QUIT", :stroke => white 
    66  end 
    77  stack :margin => 10 do 
    8     t = text "" 
     8    t = para "", :font => "Monospace 12px", :stroke => white 
    99    t.cursor = -1 
    1010  end 
     
    2424      str += self.clipboard 
    2525    end 
    26     s = Shoes.escape(str).gsub(/^def /, "<span color='#FFDDAA'>def</span> ") 
    27     t.replace "<span font_desc='Monospace 12' color='white'>#{s}</span>" 
     26    t.replace str 
    2827  end 
    2928end 
  • trunk/samples/form.rb

    r186 r213  
    99  stack :margin => 40 do 
    1010    stack :margin => 10 do 
    11       text "Name" 
     11      para "Name" 
    1212      @name = list_box :items => ["Yes, please!", "NO.  No thankyou."] 
    1313    end 
    1414    stack :margin => 10 do 
    15       text "Address" 
     15      para "Address" 
    1616      @address = edit_line 
    1717    end 
    1818    stack :margin => 10 do 
    19       text "Phone" 
     19      para "Phone" 
    2020      @phone = edit_line 
    2121    end 
  • trunk/shoes/canvas.c

    r212 r213  
    579579MARKUP_DEF(ins, INLINE, cIns); 
    580580MARKUP_DEF(link, INLINE, cLinkText); 
     581MARKUP_DEF(span, INLINE, cSpan); 
    581582MARKUP_DEF(strong, INLINE, cStrong); 
    582583 
  • trunk/shoes/canvas.h

    r212 r213  
    206206VALUE shoes_canvas_ins(int argc, VALUE *argv, VALUE self); 
    207207VALUE shoes_canvas_link(int argc, VALUE *argv, VALUE self); 
     208VALUE shoes_canvas_span(int argc, VALUE *argv, VALUE self); 
    208209VALUE shoes_canvas_strong(int argc, VALUE *argv, VALUE self); 
    209210VALUE shoes_canvas_background(int, VALUE *, VALUE); 
  • trunk/shoes/ruby.c

    r212 r213  
    1010#include <math.h> 
    1111 
    12 VALUE cShoes, cApp, cCanvas, cFlow, cStack, cMask, cPath, cImage, cAnim, cPattern, cBorder, cBackground, cTextBlock, cPara, cBanner, cTitle, cSubtitle, cTagline, cCaption, cInscription, cTextClass, cStrong, cCode, cEm, cIns, cLinkText, cNative, cButton, cEditLine, cEditBox, cListBox, cProgress, cColor, cColors, cLink; 
     12VALUE cShoes, cApp, cCanvas, cFlow, cStack, cMask, cPath, cImage, cAnim, cPattern, cBorder, cBackground, cTextBlock, cPara, cBanner, cTitle, cSubtitle, cTagline, cCaption, cInscription, cTextClass, cSpan, cStrong, cCode, cEm, cIns, cLinkText, cNative, cButton, cEditLine, cEditBox, cListBox, cProgress, cColor, cColors, cLink; 
    1313VALUE reHEX_SOURCE, reHEX3_SOURCE, reRGB_SOURCE, reRGBA_SOURCE, reGRAY_SOURCE, reGRAYA_SOURCE; 
    1414ID s_aref, s_perc, s_bind, s_new, s_run, s_to_pattern, s_to_i, s_to_s, s_angle, s_arrow, s_begin, s_call, s_center, s_change, s_click, s_corner, s_downcase, s_draw, s_end, s_font, s_hand, s_hidden, s_href, s_insert, s_items, s_scroll, s_match, s_text, s_title, s_top, s_right, s_bottom, s_left, s_height, s_resizable, s_remove, s_strokewidth, s_width, s_margin, s_margin_left, s_margin_right, s_margin_top, s_margin_bottom, s_radius; 
     
    13531353shoes_textblock_replace(int argc, VALUE *argv, VALUE self) 
    13541354{ 
    1355   VALUE texts; 
     1355  long i; 
     1356  VALUE texts, attr; 
    13561357  shoes_textblock *self_t; 
    13571358  Data_Get_Struct(self, shoes_textblock, self_t); 
    1358   rb_scan_args(argc, argv, "*", &texts); 
     1359 
     1360  attr = Qnil; 
     1361  texts = rb_ary_new(); 
     1362  for (i = 0; i < argc; i++) 
     1363  { 
     1364    if (rb_obj_is_kind_of(argv[i], rb_cHash)) 
     1365      attr = argv[i]; 
     1366    else 
     1367      rb_ary_push(texts, argv[i]); 
     1368  } 
     1369 
    13591370  self_t->texts = texts; 
     1371  if (!NIL_P(attr)) self_t->attr = attr; 
     1372 
    13601373  shoes_canvas_repaint_all(self_t->parent); 
    13611374  return self; 
     
    16101623    else 
    16111624    { 
    1612       StringValue(v); 
     1625      v = rb_funcall(v, s_to_s, 0); 
    16131626      k->len += RSTRING_LEN(v);  
    16141627      g_string_append_len(k->text, RSTRING_PTR(v), RSTRING_LEN(v)); 
     
    26292642  cLinkText  = rb_define_class_under(cShoes, "LinkText", cTextClass); 
    26302643  cIns       = rb_define_class_under(cShoes, "Ins", cTextClass); 
     2644  cSpan      = rb_define_class_under(cShoes, "Span", cTextClass); 
    26312645  cStrong    = rb_define_class_under(cShoes, "Strong", cTextClass); 
    26322646 
  • trunk/shoes/ruby.h

    r212 r213  
    2323#endif 
    2424 
    25 extern VALUE cShoes, cApp, cCanvas, cFlow, cStack, cMask, cNative, cPath, cImage, cAnim, cPattern, cBorder, cBackground, cPara, cBanner, cTitle, cSubtitle, cTagline, cCaption, cInscription, cLinkText, cTextClass, cStrong, cCode, cEm, cIns, cButton, cEditLine, cEditBox, cListBox, cProgress, cColor, cColors, cLink; 
     25extern VALUE cShoes, cApp, cCanvas, cFlow, cStack, cMask, cNative, cPath, cImage, cAnim, cPattern, cBorder, cBackground, cPara, cBanner, cTitle, cSubtitle, cTagline, cCaption, cInscription, cLinkText, cTextClass, cSpan, cStrong, cCode, cEm, cIns, cButton, cEditLine, cEditBox, cListBox, cProgress, cColor, cColors, cLink; 
    2626extern VALUE reHEX_SOURCE, reHEX3_SOURCE, reRGB_SOURCE, reRGBA_SOURCE, reGRAY_SOURCE, reGRAYA_SOURCE; 
    2727extern ID s_aref, s_bind, s_new, s_run, s_to_pattern, s_to_i, s_to_s, s_angle, s_arrow, s_begin, s_call, s_center, s_change, s_click, s_corner, s_downcase, s_draw, s_end, s_font, s_hand, s_hidden, s_href, s_insert, s_items, s_match, s_scroll, s_text, s_title, s_top, s_right, s_bottom, s_left, s_height, s_remove, s_resizable, s_strokewidth, s_width, s_margin, s_margin_left, s_margin_right, s_margin_top, s_margin_bottom, s_radius; 
     
    115115  f("ins", ins, -1); \ 
    116116  f("link", link, -1); \ 
     117  f("span", span, -1); \ 
    117118  f("strong", strong, -1); \ 
    118119  f("background", background, -1); \