From: Ville-Pertti Keinonen <will@exomi.com>
To: skaller <skaller@users.sourceforge.net>
Cc: Matt Gushee <mgushee@havenrock.com>, caml-list@inria.fr
Subject: Re: [Caml-list] Re: Feeding the OCaml GUI troll
Date: Fri, 02 Sep 2005 10:40:41 +0300 [thread overview]
Message-ID: <1125646841.735.57.camel@acerf.exomi.com> (raw)
In-Reply-To: <1125580528.7192.23.camel@localhost.localdomain>
[-- Attachment #1: Type: text/plain, Size: 1732 bytes --]
On Thu, 2005-09-01 at 23:15 +1000, skaller wrote:
> I am. My idea is this: GET RID OF CALLBACKS.
> The idea is to use (user space) threads instead.
>
> The big problem with GUI's is that they're passive.
> You write 'event handlers' and have to store the current
> state manually. By control inverting the code, you can
> just use a thread for each widget.
Have you actually done this in a GUI context, or do you just find it
conceptually attractive?
I've experimented with GUI concepts and event mechanisms in OCaml, and
created an event mechanism that could relatively easily be used in a
sort-of control inverted form by manually wrapping things into
continuations. I never ended up making use of that form of events for
the actual low-level GUI functionality, because it always seemed easier
to just use methods or attach callbacks to events and use explicit
state. Now that could simply be because I was sort-of porting a GUI
library that I had written earlier (in C++ and Scheme) and I'm rather
used to GUI mechanisms layered around inheritance (one of the few places
where it actually seems natural to me).
> For example for a button something like:
>
> let rec wait_down () =
...
> and wait_up () =
...
> is purely functional: it uses the program counter
> to maintain state, instead of a mutable state variable.
But consider that the state of a button isn't quite that simple.
Tracking the state explicitly isn't difficult - attached is an actual
push button class implementation in a traditional imperative/OO style.
There's 3 boolean variables (8 states, although half of them are
impossible) tracked locally by the simplest stateful widget. It also
has keyboard focus state, tracked by a superclass.
[-- Attachment #2: ws_button.ml --]
[-- Type: text/plain, Size: 2262 bytes --]
(* Push button type *)
open Ws_widget_types
open Ws_types
type events =
[ Ws_swidget.events
| `ButtonClicked ]
class ['a] t parent (style_init : Ws_style.button_style) =
object (self)
inherit ['a] Ws_swidget.t parent as super
constraint 'a = [> events ]
val style = style_init
val mutable is_pressed = false
val mutable is_down = false
val mutable is_in = false
method redraw d =
let mode =
if is_down then `ButtonPressed
else
if is_active then
if is_in then `ActiveMouseOver else `Active
else
if is_in then `MouseOver else `Default
in
style#draw d mode
method size_changed =
style#set_size (r_size region)
method enter_notify =
is_in <- true;
if is_pressed then
is_down <- true;
self#need_redraw
method leave_notify =
is_in <- false;
if is_pressed then
is_down <- false;
self#need_redraw
method button_press b p m =
if b = 1 then
begin
is_pressed <- true;
is_down <- true;
self#need_redraw
end
else
super#button_press b p m
method button_release b p m =
if b = 1 then
begin
if is_down && is_pressed then self#clicked;
is_pressed <- false;
is_down <- false;
self#need_redraw
end
else
super#button_release b p m
method clicked =
self#post_event `ButtonClicked
initializer
let _ = self#request_notify ButtonNotify
and _ = self#request_notify CrossingNotify in
self#set_bg style#bg;
self#bind_key (1, 0, (Ws_key.Kchar 32)) (fun _ -> self#clicked; true)
end
let on_click f =
function
`ButtonClicked -> f ()
| _ -> ()
let create ?region ?text ?label ?pos ?size ?onclick parent =
let style = parent#get_app#style in
let bs = style#button_style in
let (bt : events t) = new t parent bs
and set_opt f = function Some x -> f x | _ -> () in
set_opt bt#set_pos pos;
set_opt (fun f -> bt#connect (on_click f)) onclick;
begin
match text with
Some t -> bs#set_label (style#button_textlabel t)
| None -> set_opt bs#set_label label
end;
set_opt bt#set_region region;
if region = None then begin
match size with
Some x -> bt#set_size x
| None -> bt#set_size (bs#size_hint)
end;
bt
next prev parent reply other threads:[~2005-09-02 8:30 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-28 15:38 Does LablTk have a future? Matt Gushee
[not found] ` <aefe758210f7fa0b9846b0ea4278cf3a@rouaix.org>
2005-08-28 23:21 ` [Caml-list] " Matt Gushee
2005-08-29 22:33 ` Jon Harrop
2005-08-30 4:39 ` Matt Gushee
2005-08-30 11:39 ` Yaron Minsky
2005-08-30 11:48 ` Jon Harrop
2005-08-30 12:22 ` David MENTRE
2005-08-30 13:45 ` Jon Harrop
2005-08-30 15:47 ` David MENTRE
2005-08-30 16:08 ` Jon Harrop
2005-09-01 4:25 ` Matt Gushee
2005-09-01 11:20 ` Matt Gushee
2005-09-01 11:26 ` Matt Gushee
2005-09-01 14:09 ` Chris Campbell
2005-08-30 16:21 ` Bardur Arantsson
2005-08-30 17:47 ` [Caml-list] " David Thomas
2005-08-30 18:06 ` Tyler Eaves
2005-08-30 19:01 ` Jon Harrop
2005-08-30 22:55 ` Chris Campbell
[not found] ` <c22844d10508301553b54841b@mail.gmail.com>
2005-08-30 22:56 ` Fwd: " Chris Campbell
2005-08-30 23:04 ` Doug Kirk
2005-08-31 0:08 ` Fwd: " Jon Harrop
2005-08-31 0:31 ` Olivier Andrieu
2005-08-31 8:48 ` Feeding the OCaml GUI troll (was: Re: [Caml-list] Does LablTk have a future?) David MENTRE
2005-08-31 9:06 ` Proposal a GUI from Ocamlsdl Christophe Raffalli
2005-08-31 14:39 ` [Caml-list] " Jon Harrop
2005-09-01 19:27 ` Nathaniel Gray
2005-08-31 14:27 ` Feeding the OCaml GUI troll (was: Re: [Caml-list] Does LablTk have a future?) Jon Harrop
2005-09-01 4:49 ` Feeding the OCaml GUI troll Matt Gushee
2005-09-01 13:15 ` [Caml-list] " skaller
2005-09-01 13:28 ` David MENTRE
2005-09-01 13:50 ` skaller
2005-09-01 14:43 ` Chris Campbell
2005-09-02 7:40 ` Ville-Pertti Keinonen [this message]
2005-09-02 12:39 ` skaller
2005-09-03 10:34 ` Damien Bobillot
2005-09-03 12:30 ` skaller
2005-09-04 14:08 ` Richard Jones
2005-09-03 11:10 ` yoann padioleau
2005-09-03 11:30 ` Jonathan Roewen
2005-09-03 17:23 ` Doug Kirk
2005-09-04 14:01 ` Richard Jones
2005-09-01 19:23 ` Feeding the OCaml GUI troll (was: Re: [Caml-list] Does LablTk have a future?) Nathaniel Gray
2005-09-01 4:31 ` [Caml-list] Does LablTk have a future? Matt Gushee
2005-09-01 4:17 ` Matt Gushee
2005-09-01 13:25 ` Jon Harrop
2005-08-30 7:16 ` GUI for OCaml (was: Re: [Caml-list] Does LablTk have a future?) David MENTRE
2005-08-30 9:53 ` GUI for OCaml Christophe Raffalli
2005-08-30 10:28 ` [Caml-list] " David MENTRE
2005-08-30 13:04 ` Bünzli Daniel
2005-08-30 17:13 ` David Thomas
2005-08-30 11:18 ` Mark Shinwell
2005-08-30 14:22 ` Jacques Carette
2005-08-30 23:12 ` Pietro Abate
2005-08-30 14:14 ` GUI for OCaml (was: Re: [Caml-list] Does LablTk have a future?) Richard Jones
2005-08-30 15:33 ` mmzeeman
2005-08-30 15:44 ` Jon Harrop
2005-08-30 22:34 ` yoann padioleau
2005-09-01 4:58 ` Matt Gushee
2005-08-30 16:01 ` Jon Harrop
2005-08-30 16:25 ` Chris Campbell
2005-08-30 22:49 ` yoann padioleau
2005-08-30 16:03 ` Chris Campbell
2005-08-30 22:31 ` yoann padioleau
2005-08-31 8:19 ` About Lablgtk2 (was: e: GUI for OCaml) David MENTRE
2005-09-03 11:41 ` yoann padioleau
2005-08-30 17:35 ` [Caml-list] Does LablTk have a future? Olivier Andrieu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1125646841.735.57.camel@acerf.exomi.com \
--to=will@exomi.com \
--cc=caml-list@inria.fr \
--cc=mgushee@havenrock.com \
--cc=skaller@users.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox