diff --git a/ogui.ml b/ogui.ml index 02b93ee..ef6a89b 100644 --- a/ogui.ml +++ b/ogui.ml @@ -5,7 +5,7 @@ module Str = Re.Str type stroke = { width : float; color : Gv.Color.t } -let debugsec = ref false +let debuglayout = ref false let stroke_none = { width = 0.; color = Gv.Color.transparent } let pp_text_row : Gv.Text.text_row F.t = @@ -23,7 +23,7 @@ let pp_text_row : Gv.Text.text_row F.t = let pp_color : Gv.Color.t Fmt.t = F.( hbox - @@ record + @@ record ~sep:sp [ field "r" (fun (s : Gv.Color.t) -> s.r) float; field "g" (fun (s : Gv.Color.t) -> s.g) float; @@ -485,7 +485,7 @@ module TextLayout = struct wrap = default_text_wrapping (); halign = Min; justify = false; - line_height = Some 18.; + line_height = Some 20.; } let pp_text_row : Format.formatter -> Gv.Text.text_row -> unit = @@ -537,7 +537,7 @@ module TextLayout = struct List.fold_left (fun (l : section list) sec -> let s, e = sec.byte_range in - if !debugsec then + if !debuglayout then F.epr "with_range section cs=%d ce=%d s=%d e=%d@." cs ce s e; @@ -574,7 +574,7 @@ module TextLayout = struct let with_cursor (cur : cursor) ?(format = default_cursor_formatter) layout : layout = let c = with_range (cur.index, cur.index + 1) ~format layout in - if !debugsec then + if !debuglayout then F.epr "with_cursor %a@." F.(brackets @@ list ~sep:cut pp_section) c.sections; @@ -631,7 +631,8 @@ module Style = struct spacing = { item_spacing = Size2.v 10. 10.; - window_margin = Margin.symmetric 5. 5.; + window_margin = + Margin.{ (symmetric 5. 5.) with bottom = 0. }; indent = 5.; slider_width = 5.; text_edit_width = 500.; @@ -826,7 +827,7 @@ module TextEdit = struct (String.length s) t.cursor.index t.scroll (cursor.index - t.scroll) rows; - debugsec := true) + debuglayout := true) let cursor_update (t : t) (f : int -> int) : unit Lwt.t = col t >>= fun last_col -> @@ -1172,7 +1173,7 @@ module Painter = struct Option.value ~default:(Gv.Text.metrics t).line_height g.line_height in - let max_rows = Int.of_float (Box2.h rect /. line_height) in + let max_rows = Int.of_float (Box2.h rect /. line_height) + 1 in te.rows <- max_rows; let lines = Gv.Text.make_empty_rows max_rows in TextBuffer.contents g.text >>= fun contents -> @@ -1183,11 +1184,10 @@ module Painter = struct in Seq.fold_left (fun ((cur, start) : p2 * int) (row : Gv.Text.text_row) -> - if !debugsec then + if !debuglayout then F.epr "start=%d row=%a %a @." start pp_text_row row F.(brackets @@ list TextLayout.pp_section) g.sections; - debugsec := false; let sections = List.filter (fun (r : TextLayout.section) -> @@ -1242,6 +1242,7 @@ module Painter = struct let rec layout (box : box2) (ui : Ui.t) (frame : frame) : box2 Lwt.t = let box' = Margin.inner frame.style.margin box in + if !debuglayout then F.epr "layout box'=%a@." Gg.Box2.pp box'; (match frame.t with | `Box (dir, ll) -> Lwt_list.fold_left_s @@ -1269,4 +1270,9 @@ module Painter = struct let r' = Margin.outer frame.style.margin r in draw_box ui.gv ~box:r' ~style:frame.style; Lwt.return r' + + let layout a b c = + let r = layout a b c in + debuglayout := false; + r end diff --git a/oplevel.ml b/oplevel.ml index 2a0c8ba..0d83aa9 100644 --- a/oplevel.ml +++ b/oplevel.ml @@ -103,6 +103,8 @@ let () = ref Layout.( vbox + ~style: + Style.{ default with margin = Margin.symmetric 10.0 10.0 } [ textedit (TextEdit.multiline ui @@ -153,12 +155,10 @@ let () = Gl.enable Gl.cull_face_enum; Gl.disable Gl.depth_test; - let width, height = - ( float win_w, - float (win_h - 50) - (* TKTK might be an artifact of exwm or something *) ) + let width, height = (float win_w, float win_h) in + let box = + Gg.(Box2.v V2.zero Size2.(v width (height -. 20.))) in - let box = Gg.(Box2.v V2.zero Size2.(v width height)) in Gv.begin_frame ctx ~width ~height ~device_ratio:1.; Perfgraph.render graph ctx (width -. 205.) 5.; (* F.epr "box=%a@." Gg.Box2.pp box;