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

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



If I take that code that you have provided, and copy and paste directly
into my frame in Dylan Beta 2.0, it works. I tried to call your function
of yesterday through my own method invoked via an existing button and it
didn't work. The core of your two samples has not changed at all, so I
am doing something wrong.

Anyway, to your question, in the non-functioning version the text style
I'm getting is filled in with reasonable values. I'm sure that I can
figure it out, now that I have a working version. Thanks.

Now, when to call this? Ideally, I would like to intervene in the pane
creation after the GDI context is available and before sizing and layout
are calculated. What I'm really aming for is something like, for
instance:

pane my-text (frame)
  make (<my-text-field>, string-size: "00/00/0000");

which would create a text field just wide enough for a date. (Well,
really you'd do string-size: "00/00/00000" so that if the user
accidentally enters an extra digit they'll be able to SEE that the date
is bogus. I learned that lesson, the hard way, a long long time ago.)

I don't know for sure if this is possible in DUIM without modifying the
existing classes or substantially replicating the logic. (Thus the
possibility of keeping around a single global offscreen GDI for making
these calculations. Of course that GDI has to be set into the correct
state in order to get correct values.)

Chris Double wrote:
> 
> 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: