luikore-cici 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -6,6 +6,8 @@ No other prepared libraries needed, that is -- No Qt, Gtk, Mfc ...
6
6
 
7
7
  Light and small with nice efficiency.
8
8
 
9
+ API still in change.
10
+
9
11
  == install
10
12
 
11
13
  Require ruby 1.9.1, either ruby-1.9.1-mswin32_90 or ruby-1.9.1-mingw32 is OK.
@@ -24,11 +26,16 @@ Currently the mingw32 version does not support images.
24
26
  == example
25
27
 
26
28
  require 'cici'
27
- include Cici::View
28
- view [100, 30] do
29
- button('hello').onclick = -> this { alert 'world' }
29
+ app = Cici.app 'hello world'
30
+
31
+ app.paint [100, 30] do |v|
32
+ v.button 'hello' do
33
+ app.alert 'world'
34
+ end
30
35
  end
31
36
 
37
+ app.message_loop
38
+
32
39
  Find more in examples folder.
33
40
 
34
41
  == document
@@ -1,23 +1,24 @@
1
1
  require 'cici'
2
- include Cici::View
2
+ app = Cici.app 'common dialogs'
3
+ c = app.paint [200, 100]
3
4
 
4
- view [200, 100] do
5
- button 'choose file' do
6
- f = choose_file 'all'=>'*.*', 'ruby'=>'*.rb'
7
- alert(f || 'nil')
8
- end
9
- button 'save file' do
10
- f = save_file 'all'=>'*.*', 'ruby'=>'*.rb'
11
- alert(f || 'nil')
12
- end
13
- br
14
- button 'choose font' do
15
- f = choose_font
16
- alert(f || 'nil')
17
- end
18
- button 'choose color' do
19
- c = choose_color
20
- alert(c || 'nil')
21
- end
22
- br
5
+ c.button 'choose file' do
6
+ f = app.choose_file 'all'=>'*.*', 'ruby'=>'*.rb'
7
+ app.alert(f || 'nil')
23
8
  end
9
+ c.button 'save file' do
10
+ f = app.save_file 'all'=>'*.*', 'ruby'=>'*.rb'
11
+ app.alert(f || 'nil')
12
+ end
13
+ c.br
14
+ c.button 'choose font' do
15
+ f = app.choose_font
16
+ app.alert(f || 'nil')
17
+ end
18
+ c.button 'choose color' do
19
+ co = app.choose_color
20
+ app.alert(co || 'nil')
21
+ end
22
+ c.br
23
+ app.message_loop
24
+
data/examples/destroy.rb CHANGED
@@ -1,17 +1,16 @@
1
1
  require 'cici.rb'
2
- include Cici::View
3
2
 
4
- view [300, 300] do
5
- @p = paint [40, 30] do |p|
6
- p.bkcolor = RGB[100,100,100]
3
+ app = Cici.app 'click a button to destroy a child window'
7
4
 
8
- paint [10, 10] do
9
- end
10
- end
5
+ v = app.paint [300, 300]
11
6
 
12
- @b = button 'destroy' do
13
- @p.destroy
14
- @b.onclick = nil
15
- end
7
+ p = v.paint [40, 30]
8
+ p.bkcolor = RGB[100,100,100]
9
+ p.paint [10, 10]
10
+
11
+ @b = v.button 'destroy' do
12
+ p.destroy
13
+ @b.onclick = nil
16
14
  end
17
15
 
16
+ app.message_loop
data/examples/flow.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'cici'
2
- include Cici::View
2
+ app = Cici.app 'flow layout'
3
3
 
4
- view [300, 200], layout: :flow, title: 'flow layout' do |v|
4
+ app.paint [300, 200], Cici::FlowLayout do |v|
5
5
  v.flow_width = 200
6
- [80, 100, 80, 300].each do |i|
7
- e = edit [i, 20]
6
+ [80, 50, 25, 100, 20, 20, 80, 30, 300].each do |i|
7
+ e = v.edit [i, 20]
8
8
  e
9
9
  end
10
10
 
@@ -13,11 +13,13 @@ view [300, 200], layout: :flow, title: 'flow layout' do |v|
13
13
  if t.respond_to? :to_i
14
14
  v.flow_width = t.to_i
15
15
  else
16
- alert 'flow width not valid'
16
+ app.alert 'flow width not valid'
17
17
  end
18
18
  end
19
- button 'change flow width:', &@change_flow_width
20
- @e = edit [80, 20]
19
+ v.button 'change flow width:', &@change_flow_width
20
+ @e = v.edit [80, 20]
21
21
  @e.text = v.flow_width.toString
22
22
  @e.onenter = @change_flow_width
23
23
  end
24
+
25
+ app.message_loop
@@ -1,7 +1,11 @@
1
1
  require 'cici'
2
- include Cici::View
3
- view [100, 80] do
4
- button 'hello' do
5
- alert 'world'
2
+
3
+ app = Cici.app 'hello world'
4
+
5
+ app.paint [100, 80] |v|
6
+ v.button 'hello' do
7
+ app.alert 'world'
6
8
  end
7
9
  end
10
+
11
+ app.message_loop
data/examples/img.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require 'cici.rb'
2
- include Cici::View
3
2
 
4
- view [600, 400], :title => 'img' do |v|
5
- image 'collective intelligence.png'
6
- @neko = image 'quantummi7.jpg', [50, 100]
7
- br
8
- button 'make full size of neko shojo' do
9
- @neko.size = nil
10
- end
3
+ app = Cici.app 'image'
4
+ box = app.paint [600, 400]
5
+
6
+ box.image 'collective intelligence.png'
7
+ @neko = box.image 'quantummi7.jpg', [50, 100]
8
+ box.br
9
+ box.button 'make full size of neko shojo' do
10
+ @neko.size = nil
11
11
  end
12
+ app.message_loop
data/examples/key.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'cici'
2
- include Cici::View
2
+ app = Cici.app 'key'
3
+ c = app.paint [100, 100]
4
+
5
+ c.text 'press ctrl+A'
6
+
7
+ app.keymap('A', :ctrl) { app.alert 'hi' }
8
+ app.message_loop
3
9
 
4
- view [100, 100] do
5
- text 'press ctrl+A'
6
- keymap 'A', :ctrl do
7
- alert 'hi'
8
- end
9
- end
data/examples/list.rb CHANGED
@@ -1,19 +1,18 @@
1
1
  require 'cici'
2
- include Cici::View
2
+ app = Cici.app 'list demo'
3
+ v = app.paint [300, 300]
4
+ v.marginx = 5
5
+ v.br 10
3
6
 
4
- view [300,300] do |v|
5
- v.marginx = 5
6
- br 10
7
+ v.text 'listbox:'
8
+ v.br
9
+ @l = v.listbox [200, 130]
10
+ @l.onchange = proc{ |l| @d.cur_select = l.cur_select }
11
+ @l.items = (1..9).map{ |e| "listbox item #{e}"}
12
+ v.br 10
7
13
 
8
- text 'listbox:'
9
- br
10
- @l = listbox [200, 130]
11
- @l.onchange = proc{ |l| @d.cur_select = l.cur_select }
12
- @l.items = (1..9).map{ |e| "listbox item #{e}"}
13
- br 10
14
-
15
- text 'droplist:'
16
- br
17
- @d = droplist
18
- @d.items = (1..9).map{ |e| "combobox item #{e}"}
19
- end
14
+ v.text 'droplist:'
15
+ v.br
16
+ @d = v.droplist
17
+ @d.items = (1..9).map{ |e| "combobox item #{e}"}
18
+ app.message_loop
data/examples/menu.rb CHANGED
@@ -1,17 +1,22 @@
1
1
  require 'cici.rb'
2
- include Cici::View
3
2
 
4
- @cost = proc{|money, this| alert "cost #{money}"}.curry
3
+ app = Cici.app 'menu'
4
+ @cost = proc{|money, this| app.alert "cost #{money}"}.curry
5
5
 
6
- view [200, 100] do |v|
7
- v.menu '&bread' => @cost[0.2],
8
- 'soup' => {
9
- 'salty' => @cost[0.1],
10
- 'line' => nil,
11
- 'sw&eety' => @cost[0.1]
6
+ app.paint [200, 100] do |v|
7
+ v.menubar {|m|
8
+ m.item '&bread', &@cost[0.2]
9
+ m.menu('soup') {|m|
10
+ m.item 'salty', &@cost[0.1]
11
+ m.line
12
+ m.item 'sw&eety', &@cost[0.1]
12
13
  }
14
+ }
13
15
 
14
- @t = text 'r-click to popup menu'
15
- @t.menu 'exit' => proc{ exit }
16
+ @t = v.text 'r-click to popup menu'
17
+ @t.popupmenu {|m|
18
+ m.item('exit'){ exit }
19
+ }
16
20
  end
17
21
 
22
+ app.message_loop
data/examples/position.rb CHANGED
@@ -1,15 +1,18 @@
1
- require 'cici.rb'
2
- include Cici::View
3
-
4
- view [500,500] do |v|
5
- b = button 'move(relative to parent)' do |this|
6
- this.pos = [nil, 80]
7
- puts this.pos
8
- end
9
- br
10
- button 'move(absolute position)' do |this|
11
- this.absolute_pos = [320, 320]
12
- puts this.absolute_pos
13
- end
1
+ require 'cici'
2
+ app = Cici.app 'positioning'
3
+ c = app.paint [500, 500]
4
+
5
+ b = c.button 'move(relative to parent)' do |this|
6
+ this.pos = [nil, 80]
7
+ puts this.pos
14
8
  end
15
9
 
10
+ c.br
11
+
12
+ c.button 'move(absolute position)' do |this|
13
+ this.absolute_pos = [320, 320]
14
+ puts this.absolute_pos
15
+ end
16
+
17
+ app.message_loop
18
+
@@ -1,9 +1,6 @@
1
1
  require 'cici.rb'
2
- include Cici::View
3
2
 
4
- Cici::Config << {
5
- :default_font => Font['Courier New', 12, '', 0],
6
- }
3
+ Cici::Config[:default_font] = Font['Courier New', 12, '', 0]
7
4
 
8
5
  @check_reg = proc do
9
6
  begin
@@ -21,53 +18,52 @@ Cici::Config << {
21
18
  end
22
19
  end
23
20
 
24
- view [890, 245], :title => 'Regular Expression Test' do |v|
25
- v.bkcolor = RGB[0xaabbff]
26
- v.marginx = 8
27
- br 10
21
+ app = Cici.app 'Regular Expression Test'
22
+ v = app.paint [890, 245]
23
+ v.bkcolor = RGB[0xaabbff]
24
+ v.marginx = 8
25
+ v.br 10
28
26
 
29
- sz1 = [780, 20]
27
+ sz1 = [780, 20]
30
28
 
31
- text 'regexp:/'
32
- @reg = edit sz1
33
- @reg.ontab = proc { @txt.focus; @check_reg[] }
34
- text '/'
35
- br
29
+ v.text 'regexp:/'
30
+ @reg = v.edit sz1
31
+ @reg.ontab = proc { @txt.focus; @check_reg[] }
32
+ v.text '/'
33
+ v.br
36
34
 
37
- text 'string: '
38
- @txt = edit sz1
39
- @txt.ontab = proc { @reg.focus; @check_reg[] }
40
- br
35
+ v.text 'string: '
36
+ @txt = v.edit sz1
37
+ @txt.ontab = proc { @reg.focus; @check_reg[] }
38
+ v.br
41
39
 
42
- text 'result: '
43
- @result = edit sz1
44
- br 10
40
+ v.text 'result: '
41
+ @result = v.edit sz1
42
+ v.br 10
45
43
 
46
- paint [780, 115] do
47
- @globals = (1..9).map do |i|
48
- text " $#{i}", Font['Monaco', 12]
49
- e = edit [210, 20]
50
- br if (i==3 or i==6)
51
- e
52
- end
53
- end
54
-
55
- paint [60, 115] do
56
- sz = [60, 22]
57
- button('match', sz).onclick = @check_reg
58
- br 8
59
-
60
- button('copy', sz).onclick = proc do
61
- @reg.copy
62
- alert "\"#{@reg.text}\" copied."
63
- end
64
- br 8
65
-
66
- button('escape', sz).onclick = proc do
67
- @reg.text = Regexp.escape @reg.text
68
- end
69
- end
44
+ # match groups
45
+ gs = v.paint [780, 115]
46
+ @globals = (1..9).map do |i|
47
+ gs.text " $#{i}", Font['Monaco', 12]
48
+ e = gs.edit [210, 20]
49
+ gs.br if (i==3 or i==6)
50
+ e
51
+ end
70
52
 
71
- @reg.focus
53
+ # control buttons
54
+ gs = v.paint [60, 115]
55
+ sz = [60, 22]
56
+ gs.button('match', sz).onclick = @check_reg
57
+ gs.br 8
58
+ gs.button 'copy', sz do
59
+ @reg.copy
60
+ app.alert "\"#{@reg.text}\" copied."
72
61
  end
62
+ gs.br 8
63
+ gs.button 'escape', sz do
64
+ @reg.text = Regexp.escape @reg.text
65
+ end
66
+
67
+ @reg.focus
68
+ app.message_loop
73
69
 
@@ -1,29 +1,5 @@
1
- # Coding: utf-8
2
1
  require 'cici'
3
- include Cici::View
4
-
5
- SysMenu = {
6
- '&File' => {
7
- '&Open' => proc{ (fn = choose_file 'ruby file'=>'*.rb', 'all'=>'*.*') and (@s.text = File.read(fn).encode 'utf-8') },
8
- '&Save' => proc{ puts 'ss'; (fn = save_file) and File.open(fn,'w'){ |f| f << @s.text } },
9
- 'E&xit' => proc{ exit },
10
- }
11
- }
12
-
13
- cx = 800
14
- cy = 600
15
- view [cx, cy], title: 'Scintilla', layout: :zoom do |v|
16
- v.menu SysMenu
17
- @s = scintilla [cx - 8, cy - 46]
18
- @s.style_set_default_font Font['Monaco',9]
19
- @s.line_margin = 1 # show line number
20
- @s.fold_margin = 2
21
- @s.text = File.read(__FILE__).encode 'utf-8' # read in self
22
- @s.indent = 2 # auto indent 2 chars when needed
23
- @s.onstyle = proc do |sci, startp, endp|
24
- sci.set_styling endp - startp, 1
25
- end
26
- @s.oncharadded = proc do |sci, c|
27
- puts c
28
- end
29
- end
2
+ app = Cici.app 'scintilla'
3
+ c = app.paint [600, 600], Cici::ZoomLayout
4
+ c.scintilla [500, 500]
5
+ app.message_loop
data/examples/style.rb CHANGED
@@ -1,33 +1,33 @@
1
1
  # coding: utf-8
2
2
  require 'cici'
3
- include Cici::View
4
3
 
5
- view [400, 400] do |v|
6
- v.bkcolor = RGB[0xffff66]
7
- v.marginx = 5
4
+ app = Cici.app 'style demo'
5
+ v = app.paint [400, 400]
6
+ v.bkcolor = RGB[0xffff66]
7
+ v.marginx = 5
8
8
 
9
- text 'Arial', Font['Arial', 22 ,'si']
10
- br
9
+ v.text 'Arial', Font['Arial', 22 ,'si']
10
+ v.br
11
11
 
12
- @t1 = text 'Courier New', Font['Courier New', 18, 'u']
13
- @t1.color = RGB[18, 128, 0]
14
- br
12
+ @t1 = v.text 'Courier New', Font['Courier New', 18, 'u']
13
+ @t1.color = RGB[18, 128, 0]
14
+ v.br
15
15
 
16
- text 'AvQest', Font['AvQest', 33]
17
- br
16
+ v.text 'AvQest', Font['AvQest', 33]
17
+ v.br
18
18
 
19
- @t2 = text '黑体', Font['黑体', 22 ,'b', Cici::GB2312_CHARSET]
20
- @t2.color = RGB[0xff3300]
21
- br
19
+ @t2 = v.text '黑体', Font['黑体', 22 ,'b', Cici::GB2312_CHARSET]
20
+ @t2.color = RGB[0xff3300]
21
+ v.br
22
22
 
23
- b = button '宋体'
24
- b.font_size = 15
25
- b.size = [80, 20]
26
- br
23
+ b = v.button '宋体'
24
+ b.font_size = 15
25
+ b.size = [80, 20]
26
+ v.br
27
27
 
28
- paint [250, 80] do |c|
29
- c.bkcolor = RGB[0x99ccff]
30
- c.border_stroke = Stroke[RGB[0x00cc00], dot:2]
31
- c.border_radius = 5
32
- end
33
- end
28
+ c = v.paint [250, 80]
29
+ c.bkcolor = RGB[0x99ccff]
30
+ c.border_stroke = Stroke[RGB[0x00cc00], dot:2]
31
+ c.border_radius = 5
32
+
33
+ app.message_loop