VisualuRuby - レイアウトマネージャ

ようやくレイアウトマネージャのコツがつかめてきたかな。
レイアウトマネージャを使うと等分割されちゃうけど
もっと細かく調節したいなぁ・・・。
かといって絶対座標でやるのは嫌だ。


もっと簡単にレイアウト制御したい!
肝心のロジック書くよりもレイアウト作る方が時間かかる!


あと、テキストエリアにデータを追加しまくる場合に
うまくバッファリングする方法を探さないといけないです。
サイズの大きいファイルを指定すると暴走する(^^;


ちなみに、初めて extend を使ったけど便利だ。

#!ruby -Ks
require 'vr/vrcontrol'
require 'vr/vrlayout'

# Version情報
VER = 0.1
# VRTextにメソッド追加
module TextEdit
  # 改行付きでテキストを追加する
  def add(text)
    self.text += (text.chomp + "\n")
    self.refresh
  end
  # 全て削除
  def clear 
    self.text = ""
  end
end

class MyForm < VRForm
  include VRGridLayoutManager
  # コンストラクタ
  def construct
    self.caption = "FRAME_TEST - V#{VER}"
    # 横10、縦20に分割する
    setDimension(10,20)
    # demension を使っているので x,yはグリッドの位置座標、
    # w,h はグリッドを何個使って表示するか
    addControl VREdit   , "file_edit"    , "" , 0,0,10,1
    addControl VREdit   , "id_edit"      , "" , 0,1, 5,1
    addControl VREdit   , "pass_edit"    , "" , 5,1, 5,1 ,WStyle::ES_PASSWORD
    addControl VRButton , "button_check" , "" , 0,2,10,2
    addControl VRText   , "text_result"  , "" , 0,4,10,16,WStyle::WS_VSCROLL
    # デフォルトメッセージを設定
    @file_edit.text       = "D:/sample.txt"
    @id_edit.text         = "please input your id"
    @pass_edit.text       = "please input your password"
    @button_check.caption = "check start"
    # 出力エリアを拡張
    @text_result.extend TextEdit
  end
  # チェックボタンが押された
  def button_check_clicked
    # ボタンを無効
    @button_check.enabled=false
    # 空にする
    @text_result.clear
    # ファイル読み込み
    loadText
    # ボタンを有効
    @button_check.enabled=true
  end

  def loadText
    @text_result.clear
    begin
      open(@file_edit.text , "r").each {|text|
        @text_result.add(text)
      }
    rescue => e
      @text_result.clear
      @text_result.add("error:#{e}")
    end
  end
end

frm=VRLocalScreen.showForm(MyForm,100,100,700,500)
VRLocalScreen.messageloop