<html><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Does mercury have anything like a reference type?<div><br></div><div>Having now overcome the obstacles required to render things using a graphics library called raylib, I am beginning to focus on exactly how I am going to represent an eventually complex tree of UI components; each component may be comprised of nested components etc etc.</div><div><br></div><div>My first problem is how to update a single arbitrary object e.g. keyboard events are routed to the object 'with focus' and will cause it to change state, case in point, my simple line input edit controller, as you type, it adds the key code to the end of the buffer and the renderer will then show the current contents etc That was the plan. My first attempt was to have a list of UI objects, then render them, that's fine. The object with focus is kept in the world object as a maybe(ui_object), and when I update it, the screen doesn't change because the object I have kept in the maybe record is not the same instance as the one being updated.</div><div><br></div><div>My creation code is like this:</div><div><br></div><div><div> some [ !World ] (</div><div> mk_world(144, !:World, !IO),</div><div> INPUT = mk_input_line("*", 20, 200, 20, color(green)),</div><div> ui_focus(yes(INPUT), !World),</div><div> A0 = app_state(</div><div> AppFont,</div><div> [</div><div> mk_kbdmon(100, 0, 20, color(red)),</div><div> mk_mousemon(0, 35, 20, color(white)),</div><div> mk_timermon(0, 70, 20, color(yellow)),</div><div> mk_cursor(144, 105, color(green)),</div><div> INPUT</div><div> ]</div><div> ),</div><div> ui_run_loop(A0, _, !.World, _, !IO),</div><div> unload_font(AppFont, !IO),</div><div> close_window(!IO)</div><div> ).</div></div><div><br></div><div>In the loop updating code, I check for any key pressed, and pass it to the currently focused input object:</div><div><br></div><div><div>consume_keyboard(!W, !IO) :-</div><div> get_key_pressed_int(Key, !IO),</div><div> ( if Key > 0 then</div><div> (</div><div> w_focus(!.W) = yes(Target),</div><div> trace_info("ui_object:keyboard:%s", [ s(string(Key)) ], !IO),</div><div><b> ( if key_pressed_to(Key, Target, Out, !W) then</b></div><div><b> !:W = !.W ^w_focus := yes(Out)</b></div><div><b> else</b></div><div><b> true</b></div><div><b> )</b></div><div> ;</div><div> w_focus(!.W) = no,</div><div> trace_info("desktop:keyboard:%s", [ s(string(Key)) ], !IO)</div><div> )</div><div> else true).</div></div><div><br></div><div>The lines in bold show that, having passed the key to the object, it is expected to return a modified instance, this is all fine, it works, </div><div><br></div><div><div>INFO: ui_object:keyboard:84</div><div>chars2:['*']</div><div>INFO: ui_object:keyboard:69</div><div>chars2:['T', '*']</div><div>INFO: ui_object:keyboard:83</div><div>chars2:['E', 'T', '*']</div><div>INFO: ui_object:keyboard:84</div><div>chars2:['S', 'E', 'T', '*']</div></div><div><br></div><div>The reason that the screen is not showing the new keys (reversed, I know) is because the INPUT in the list is, after the first event update, no longer the same object now held in the 'focus' slot in the world state.</div><div><br></div><div>I apologise for the lengthy description thus far but I am just trying to give some background in my though processes, or lack thereof so far I guess.</div><div>I am currently reading the docs for thread.mvar as it seems like it might be what I need but then again maybe not as I am not threading per se.</div><div><br></div><div>Presumably I now have to find a scheme whereby I can iterate a tree of objects, and then update the one with event focus but there other problems to solve to like finding out which component is uder a mouse down event etc. I have a suspicion that my long time owned and once read copy of Purely Functional Data Structures (Okasaki) might be useful?</div><div><br></div><div>If I was writing code in pure C it wouldn't be an issue, I've done things like this before, but never in a language like Mercury,</div><div><br></div><div>So...any idea, hints, sources of things to read etc will be most welcome. I think this will be a most interesting problem to solve,</div><div><br></div><div>:)</div><div><br></div><div><br></div></body></html>