Skip to content

Commit 383581f

Browse files
committed
Minor optimization to CLICKABLE_TEXT (it still needs performance improvements, reuse font, ...)
Delayed computation for JSON_FORMATTED_TEXT
1 parent e365057 commit 383581f

File tree

2 files changed

+61
-14
lines changed

2 files changed

+61
-14
lines changed

src/gui/clickable_text.e

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,25 @@ feature {NONE} -- Properties
207207

208208
apply_custom_properties (a_style: STRING)
209209
local
210-
f: like current_format
210+
f: detachable like current_format
211211
do
212-
f := new_format_from_current
213-
if attached foreground_color (a_style) as fg then
214-
f.set_color (fg)
215-
end
216-
if attached background_color (a_style) as bg then
217-
f.set_background_color (bg)
218-
end
219-
if attached font (a_style) as ft then
220-
f.set_font (ft)
212+
if properties.has (a_style) then
213+
f := new_format_from_current
214+
215+
if attached foreground_color (a_style) as fg then
216+
f.set_color (fg)
217+
end
218+
if attached background_color (a_style) as bg then
219+
f.set_background_color (bg)
220+
end
221+
if attached font (a_style) as ft then
222+
f.set_font (ft)
223+
end
221224
end
222225
record_properties (a_style)
223-
widget.set_current_format (f)
226+
if f /= Void then
227+
widget.set_current_format (f)
228+
end
224229
end
225230

226231
apply_link_properties
@@ -338,6 +343,17 @@ feature -- Properties
338343

339344
feature {NONE} -- Implementation
340345

346+
parent_window_of (w: detachable EV_WIDGET): detachable EV_WINDOW
347+
do
348+
if w /= Void then
349+
if attached {like parent_window_of} w as win then
350+
Result := win
351+
else
352+
Result := parent_window_of (w.parent)
353+
end
354+
end
355+
end
356+
341357
properties: HASH_TABLE [TUPLE [foreground_color, background_color: detachable EV_COLOR; font: detachable EV_FONT], STRING]
342358

343359
invariant

src/gui/json_formatted_text.e

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ feature {NONE} -- Initialization
3434
ft.set_weight ({EV_FONT_CONSTANTS}.Weight_bold)
3535
set_font ("name", ft)
3636

37-
set_foreground_color ("string", create {EV_COLOR}.make_with_8_bit_rgb (0, 90, 0))
37+
set_foreground_color ("string", create {EV_COLOR}.make_with_8_bit_rgb (0, 0, 0))
3838
create ft
3939
ft.set_shape ({EV_FONT_CONSTANTS}.Shape_italic)
4040
set_font ("string", ft)
@@ -45,20 +45,51 @@ feature -- Change
4545
set_json (j: detachable JSON_VALUE)
4646
do
4747
wipe_out
48+
json := j
4849
if j /= Void then
50+
widget.set_text ("Click to get formatted body ...")
51+
widget.focus_in_actions.extend_kamikaze (agent set_text_from_json)
52+
end
53+
end
54+
55+
json: detachable JSON_VALUE
56+
57+
set_text_from_json
58+
local
59+
win: like parent_window_of
60+
p: detachable like {EV_WINDOW}.pointer_style
61+
do
62+
wipe_out
63+
if attached json as j then
64+
win := parent_window_of (widget)
65+
if win /= Void then
66+
p := win.pointer_style
67+
win.set_pointer_style (stock_pixmaps.busy_cursor)
68+
end
4969
j.accept (Current)
70+
if win /= Void then
71+
if p = Void then
72+
p := stock_pixmaps.standard_cursor
73+
end
74+
win.set_pointer_style (p)
75+
end
5076
end
5177
end
5278

79+
stock_pixmaps: EV_STOCK_PIXMAPS
80+
once
81+
create Result
82+
end
83+
5384
feature -- Json
5485

5586
initialize_visitor
5687
-- Create a new instance
5788
do
5889
create indentation.make_empty
59-
indentation_step := "%T"
90+
indentation_step := " "
6091

61-
object_count_inlining := 1
92+
object_count_inlining := 3
6293
array_count_inlining := 1
6394
end
6495

0 commit comments

Comments
 (0)