[Prev][Next][Index][Thread]

Re: <text-field>, size, GDI context...



Scott Ribe <sribe@miqs.com> writes:

> How and when do I call this? What context is required for text-size to
> function correctly? I tried just calling this from a button on the form,
> where the text field in question is fully instantiated and displayed,
> and it just returns: #f, #f, #f, #f, #f.

What did the get-default-text-style call return? Perhaps that failed
for some reason. 

I've copied the code I used in HD 1.2 to test it below.

-----------------8<-----------------
  define frame <a-frame> (<simple-frame>)
    pane text-pane (frame)
      make(<text-field>);

    pane button-pane (frame)
      make(<push-button>, activate-callback: on-push);

    layout (frame)
      vertically()
       frame.text-pane;
       frame.button-pane;
      end;
  end frame;

  define method on-push(g)
    let text-gadget = g.sheet-frame.text-pane;
    let _port = g.port;
    let style = get-default-text-style(_port, text-gadget);
    let largest-x = 
      with-sheet-medium( medium = text-gadget )
      text-size(medium, "Hello World", text-style: style);  
    end;
    notify-user(format-to-string("%d", largest-x));
  end method;

  define method main () => ()
    start-frame(make(<a-frame>));
  end method main;
-----------------8<-----------------

Hope that helps,
Chris.
-- 
http://www.double.co.nz/dylan



Follow-Ups: References: