2 * Copyright (C) 2024 Mikulas Patocka
4 * This file is part of Ajla.
6 * Ajla is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
11 * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * Ajla. If not, see <https://www.gnu.org/licenses/>.
19 private unit ui.widget.display;
21 uses ui.widget.common;
25 fn display_init(display_prop : bytes, color_scheme : bytes, w : world, app : appstate, id : wid) : (world, appstate, display_state);
26 fn display_get_width(app : appstate, com : widget_common, st : display_state, x : int) : int;
27 fn display_get_height(app : appstate, com : widget_common, st : display_state, x : int) : int;
28 fn display_redraw(app : appstate, curs : curses, com : widget_common, st : display_state) : curses;
29 fn display_process_event(w : world, app : appstate, com : widget_common, st : display_state, wev : wevent) : (world, appstate, widget_common, display_state);
31 const display_class~flat := widget_class.[
34 is_selectable : false,
35 get_width : display_get_width,
36 get_height : display_get_height,
37 redraw : display_redraw,
38 process_event : display_process_event,
43 record display_state [
48 fn display_init(display_prop : bytes, color_scheme : bytes, implicit w : world, implicit app : appstate, id : wid) : (world, appstate, display_state)
50 property_observe(id, display_prop);
51 return display_state.[
52 display_prop : display_prop,
53 color_scheme : color_scheme,
57 fn display_get_width(app : appstate, com : widget_common, st : display_state, x : int) : int
62 fn display_get_height(app : appstate, com : widget_common, st : display_state, x : int) : int
67 fn display_redraw(implicit app : appstate, implicit curs : curses, com : widget_common, st : display_state) : curses
69 var disp := property_get(st.display_prop).s;
70 if len(disp) > com.size_x then [
71 if com.size_x >= 6 then
72 disp := `...` + disp[len(disp) - (com.size_x - 3) ..];
75 property_set_attrib(property_get_attrib(st.color_scheme + "display", #0000, #0000, #0000, #aaaa, #aaaa, #aaaa, 0, curses_invert));
79 fn display_process_event(implicit w : world, implicit app : appstate, implicit com : widget_common, implicit st : display_state, wev : wevent) : (world, appstate, widget_common, display_state)
81 if wev is property_changed then [
82 widget_enqueue_event(com.self, wevent.redraw.(event_redraw.[