This commit is contained in:
cqc
2024-05-14 22:42:58 -05:00
parent 8ccef92056
commit 51dd25deee
2 changed files with 21 additions and 15 deletions

26
ogui.ml
View File

@ -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