Thread Rating:
  • 372 Vote(s) - 2.92 Average
  • 1
  • 2
  • 3
  • 4
  • 5
文字が表示しきれない場合に、右端に「...」と表示するには?
07-17-2013, 05:11 PM,
#3
RE: 文字が表示しきれない場合に、右端に「...」と表示するには?
とりあえず、こんな実装なのかな、という想像です。

Code:
{define-class public CustomTextFrame {inherits HBox}
  field tfb:TextFlowBox
  field sufix-text:Frame = {Frame}
  field cut?:bool = false
  {constructor public {default ...}
    set self.tfb = {DefaultTextFlowBox {splice ...}}
    set self.tfb.height= self.tfb.font-size + 1pt
    {construct-super
        height= self.tfb.font-size + 1pt,
        self.tfb,
        self.sufix-text
    }
  }
  {method public {set-size lc:LayoutContext, bounds:GRect}:void
    def font-w = {self.calc-text-width self.tfb, {self.tfb.get-text} }
    {if font-w > bounds.width then
        {if not self.cut? then
            set self.cut? = true
            {self.sufix-text.add replace? = true, "..."}
        }
     else
        set self.cut? = false
        {self.sufix-text.clear}
    }
    {super.set-size lc, bounds}
  }
  {method {calc-text-width fr:Graphic, txt:String }:FloatDistance
    def font = {Font
                   fr.font-family,
                   fr.font-size * 1pt,
                   weight = fr.font-weight,
                   style = fr.font-style
               }
    def d =
        {fr.display-context.get-string-advance-width
            font,
            txt
        }
    {return d}
  }
}
{CustomTextFrame "あいうえおかきくけこさしすせそたちつてと"}


Messages In This Thread
RE: 文字が表示しきれない場合に、右端に「...」と表示するには? - by umemura - 07-17-2013, 05:11 PM
Forum Jump:


Users browsing this thread:
2 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('941')