<commit_before>class RecitePoemLayout < MotionKit::Layout
  BUTTON_IMAGE_SIZE = CGSizeMake(30, 30)
  HEADER_BUTTON_SIZE = 25

  def layout
    background_color UIColor.whiteColor

    add UIView, :header do
      add UILabel, :header_title do
        text '序歌'
      end
      add UIButton, :gear_button
      add UIButton, :exit_button
    end

    # header
    # play_button
    # progress_bar
  end

  def header_style
    background_color AppDelegate::BAR_TINT_COLOR
    frame [[0, 0], ['100%', 60]]
  end

  def header_title_style
    text_alignment UITextAlignmentCenter
    size [100, 40]
    center ['50%', '50% + 10']
  end

  def gear_button_style
    image self.class.gear_image, state: UIControlStateNormal
    frame w: HEADER_BUTTON_SIZE, h: HEADER_BUTTON_SIZE
    center ['50%', '50% + 10']
    frame x: 10
  end

  def exit_button_style
    image self.class.exit_image, state: UIControlStateNormal
    frame w: HEADER_BUTTON_SIZE, h: HEADER_BUTTON_SIZE
    center ['50%', '50% + 10']
    frame x: "100% - 35"
  end

  class << self
    def gear_image
      @gear_image ||=
          ResizeUIImage.resizeImage(UIImage.imageNamed('gear-520.png'),
                                    newSize: BUTTON_IMAGE_SIZE).
              imageWithRenderingMode(UIImageRenderingModeAlwaysTemplate)
    end

    def exit_image
      @exit_image ||=
          ResizeUIImage.resizeImage(UIImage.imageNamed('exit_square_org.png'),
                                    newSize: BUTTON_IMAGE_SIZE).
              imageWithRenderingMode(UIImageRenderingModeAlwaysTemplate)
    end
  end

end<commit_msg>MotionKit導入: 読み上げ画面のヘッダボタン配置をリファクタリング<commit_after>class RecitePoemLayout < MotionKit::Layout
  STATUS_BAR_HEIGHT = 20 # これはシステムのステータスバーの値そのまま。好きに変えていいわけではない。
  HEADER_HEIGHT = 40
  HEADER_BUTTON_SIZE = 25
  HEADER_BUTTON_MARGIN = 10
  BUTTON_IMAGE_SIZE = CGSizeMake(HEADER_BUTTON_SIZE, HEADER_BUTTON_SIZE)

  weak_attr :delegate

  def layout
    background_color UIColor.whiteColor

    add UIView, :status_area
    add UIView, :header_container do
      add UILabel, :header_title do
        text '序歌'
      end
      add UIButton, :gear_button
      add UIButton, :exit_button
      # add UIView, :test_view
    end

    # play_button
    # progress_bar
  end

  def status_area_style
    background_color AppDelegate::BAR_TINT_COLOR
    size ['100%', STATUS_BAR_HEIGHT]
  end

  def header_container_style
    background_color AppDelegate::BAR_TINT_COLOR
    frame below(:status_area)
    size ['100%', HEADER_HEIGHT]
  end

  def header_title_style
    text_alignment UITextAlignmentCenter
    size ['80%', '80%']
    center ['50%', '50%']
  end

  def gear_button_style
    image self.class.gear_image, state: UIControlStateNormal
    set_header_button_size
    center y: '50%'
    frame x: HEADER_BUTTON_MARGIN
  end

  def exit_button_style
    image self.class.exit_image, state: UIControlStateNormal
    set_header_button_size
    frame from_top_right(left: HEADER_BUTTON_MARGIN)
    center y: '50%'
  end

  def test_view_style
    background_color UIColor.brownColor
    size [30, 30]
    frame from_top_right(left: 5)
  end

  private

  def set_header_button_size
    frame w: HEADER_BUTTON_SIZE, h: HEADER_BUTTON_SIZE
  end


  class << self
    def gear_image
      @gear_image ||= header_button_from_image_file('gear-520.png')
    end

    def exit_image
      @exit_image ||= header_button_from_image_file('exit_square_org.png')
    end

    def header_button_from_image_file(file_path)
      ResizeUIImage.resizeImage(UIImage.imageNamed(file_path),
                                newSize: BUTTON_IMAGE_SIZE).
          imageWithRenderingMode(UIImageRenderingModeAlwaysTemplate)
    end
  end

end
{'fraction_non_alphanumeric': 0.07246767241379311, 'fraction_numerical': 0.021551724137931036, 'mean_word_length': 3.120976692563818, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4870955', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1270, 'n_words': 261}