Skip to content

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

Description

@Chimrod

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions