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

TextInput: Multiline editor #25

Open
Lesenr1 opened this issue Feb 11, 2024 · 3 comments
Open

TextInput: Multiline editor #25

Lesenr1 opened this issue Feb 11, 2024 · 3 comments

Comments

@Lesenr1
Copy link

Lesenr1 commented Feb 11, 2024

Hello !

I am trying to make the cursor move to the next line in a text input.
For that, on shift+enter keyboard presses, I use Widget.set_text and the "\r\n" escape seq.

After hitting shift+enter, the cursor disappear from the screen, but the TextInput widget does not seem to lose the focus.
Here is a small example:

let main () =
  let input = W.text_input ~max_size:200 ~prompt:"Enter your name" () in
  let label = W.label ~size:40 "Hello!" in
  let layout =
    L.tower [ L.resident ~w:400 ~h:400 input; L.resident ~w:400 ~h:200 label ]
  in
  let action ti l ev =
    let open Tsdl.Sdl in
    let () =
      match Trigger.event_kind ev with
      | `Key_down
        when Event.(get ev keyboard_keycode) = K.return
             && Event.(get ev keyboard_keymod) land Kmod.shift <> 0 ->
        W.set_text ti (W.get_text ti ^ "\r\n");
        W.update ti
      | _ -> ()
    in
    W.set_text l ("Hello " ^ W.get_text ti ^ "!")
  in
  let c = W.connect input label action Trigger.[ text_input; key_down ] in
  let board = Bogue.of_layout ~connections:[ c ] layout in
  Bogue.run board
@sanette
Copy link
Owner

sanette commented Feb 12, 2024

Hi, not sure exactly what you are trying to achieve. A Text_input has only one line, so you can't move to the next line.

@sanette
Copy link
Owner

sanette commented Feb 12, 2024

Some info:

  1. if you have several text_inputs in your GUI, you can move to the next one by pressing the TAB key
  2. yes, it would be nice to have a multiline editor in Bogue...

@Lesenr1
Copy link
Author

Lesenr1 commented Feb 12, 2024

not sure exactly what you are trying to achieve

Pretty much what I am doing on Github right now 😊.. Now I will hit shift+enter
and I can write to the next line

Thanks for the answer anyways

@Lesenr1 Lesenr1 changed the title CRLF in TextInput TextInput: Multiline editor Feb 12, 2024
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

2 participants