Module: CryptopunksGui::View::ImageFrame

Included in:
CryptopunksGui
Defined in:
app/view/image_frame.rb

Instance Method Summary collapse

Instance Method Details

#add_style_options(style_options_container_frame:, image:) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/view/image_frame.rb', line 125

def add_style_options(style_options_container_frame: , image: )
  style_options_container_frame.children.each(&:destroy)
  style_options_container_frame.content {
    case image.style
    when 'Led'
      led_style_options_frame(image: image)
    when 'Sketch'
      sketch_style_options_frame(image: image)
    else
      no_style_options_frame
    end
  }
end

#change_output_location(root:, image:) ⇒ Object



139
140
141
142
# File 'app/view/image_frame.rb', line 139

def change_output_location(root: , image: )
  new_output_location = choose_directory(parent: root)
  image.change_output_location(new_output_location) unless new_output_location.to_s.empty?
end

#image_frame(root:, image:) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/view/image_frame.rb', line 4

def image_frame(root: , image: )
  image_label = output_location_entry = image_index_spinbox = style_options_container_frame = nil
  
  frame {
    label {
      text 'Collection:'
    }
    combobox {
      readonly true
      values <= [image, :collection_options]
      text <=> [image, :collection]
    }
    
    label {
      text 'Image Index:'
    }
    image_index_spinbox = spinbox {
      from 0
      to image.images[image.collection].size - 1
      text <=> [image, :image_index]
    }
    
    label {
      text 'Zoom:'
    }
    spinbox {
      from 1
      to 72
      text <=> [image, :zoom]
    }
    
    label {
      text 'Palette:'
    }
    combobox {
      readonly true
      text <=> [image, :palette]
    }
    
    label {
      text 'Style:'
    }
    combobox {
      readonly true
      text <=> [image, :style, after_write: ->(val) {add_style_options(style_options_container_frame: style_options_container_frame, image: image)}]
    }
    
    style_options_container_frame = frame {
      padding 0
    }
    
    frame {
      padding 0
      
      checkbutton {
        grid row: 0, column: 0, column_weight: 0
        variable <=> [image, :mirror]
      }
      label {
        grid row: 0, column: 1
        text 'Mirror'
        
        on('Button-1') do
          image.mirror = !image.mirror
        end
      }
      
      checkbutton {
        grid row: 0, column: 2
        variable <=> [image, :flip]
      }
      label {
        grid row: 0, column: 3
        text 'Flip'
        
        on('Button-1') do
          image.flip = !image.flip
        end
      }
    }
    
    label {
      text 'Output Location:'
    }
    frame {
      padding 0
      
      output_location_entry = entry {
        grid row: 0, column: 0
        readonly true
        width 47
      }
      button {
        grid row: 0, column: 1
        text '...'
        width 1.1
        
        on('command') do
          change_output_location(root: root, image: image)
        end
      }
    }
    
    image_label = label {
      grid row_weight: 1
    }
  }
  
  register_image_frame_observers(image_label: image_label, output_location_entry: output_location_entry, image_index_spinbox: image_index_spinbox, image: image)
end

#register_image_frame_observers(image_label:, output_location_entry:, image_index_spinbox:, image:) ⇒ Object



115
116
117
118
119
120
121
122
123
# File 'app/view/image_frame.rb', line 115

def register_image_frame_observers(image_label: , output_location_entry: , image_index_spinbox: , image: )
  Glimmer::DataBinding::Observer.proc do
    image_label.image = output_location_entry.text = image.image_location
  end.observe(image, :image_location)
  
  Glimmer::DataBinding::Observer.proc do
    image_index_spinbox.to = image.images[image.collection].size - 1
  end.observe(image, :images)
end