Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

widget#can_focus is not evaluated when #set_focus is given #91

Open
Chimrod opened this issue May 9, 2020 · 0 comments
Open

widget#can_focus is not evaluated when #set_focus is given #91

Chimrod opened this issue May 9, 2020 · 0 comments

Comments

@Chimrod
Copy link

Chimrod commented May 9, 2020

In the following example :

open Lwt
open LTerm_widget

let main () =
  let waiter, wakener = wait () in

  let selected = ref 1 in

  let vbox = new vbox in
  let group_int = new radiogroup in
  let callback_int = function
    | Some n ->
        selected := n

    | None -> ()
  in
  group_int#on_state_change callback_int;

  let button = new button "exit" in
  button#on_click (wakeup wakener);
  vbox#add ~expand:false button;
  vbox#add ~expand:false (new hline);

  let button = object
    inherit button "reset radiobuttons"

    (* The button should be selectable only when the group_box value is set to 1 *)
    method! can_focus = !selected = 1
  end in

  let reset = fun () ->
    group_int#switch_to 1;
  in
  button#on_click reset;
  vbox#add ~expand:false button;
  vbox#add ~expand:false (new hline);

  let group_box = new vbox in
  let radio_1 = new radiobutton group_int "Allow reset" 1 in
  group_box#add radio_1;
  group_box#add (new radiobutton group_int "Disable reset" 2);


    (* Disable thoses lines to get the malfunctionning *)

    (*
  radio_1#set_focus LTerm_geom.({
      left = None;
      right = None;
      up = Some (button :> LTerm_widget.t);
      down = None
  });
    *)
  vbox#add group_box;

  let frame = new frame in
  frame#set vbox;

  Lazy.force LTerm.stdout >>= fun term ->
  LTerm.enable_mouse term >>= fun () ->
  Lwt.finalize
    (fun () -> run term frame waiter)
    (fun () -> LTerm.disable_mouse term)

let () = Lwt_main.run (main ())

The button "reset" as overriden the method get_focus for being disabled when the second radio button is selected.

But if you uncomment the lines 46-53 which define the focus rules for one radio button, the button becomes always enabled. The method can_focus is not evaluated at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant