123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140(*********************************************************************************)(* OCaml-Stk *)(* *)(* Copyright (C) 2023-2024 INRIA All rights reserved. *)(* Author: Maxence Guesdon, INRIA Saclay *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU General Public License as *)(* published by the Free Software Foundation, version 3 of the License. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU General Public License for more details. *)(* *)(* You should have received a copy of the GNU General Public *)(* License along with this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* As a special exception, you have permission to link this program *)(* with the OCaml compiler and distribute executables, as long as you *)(* follow the requirements of the GNU GPL in regard to all of the *)(* software in the executable aside from the OCaml compiler. *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(*********************************************************************************)(** Indicators, change aspect according to property value of an object. *)(** {2 Properties} *)(** The single-char text used by {!class-indicator#connect_to_active} when
[active] property is [true].*)letprop_active_char=Props.uchar_prop~after:[Props.Resize]~inherited:false~default:(Uchar.of_int9724)"indicator_active_char"letcss_prop_active_char=Theme.uchar_propprop_active_char(** The single-char text used by {!class-indicator#connect_to_active} when
[active] property is [false].*)letprop_inactive_char=Props.uchar_prop~after:[Props.Resize]~inherited:false~default:(Uchar.of_int9723)"indicator_inactive_char"letcss_prop_inactive_char=Theme.uchar_propprop_inactive_char(** {2 Widget} *)(**/**)letmap_activeself=function|true->(Utf8.string_of_ucharself#active_char,Props.empty())|false->(Utf8.string_of_ucharself#inactive_char,Props.empty())(**/**)(** The indicator widget. *)classindicator?classes?name?props?wdata()=object(self)inheritText.label?classes?name?props?wdata()assuper(**/**)valmutablecb_id=Nonevalmutablecb_id_destroy=Nonevalmutableupdate__=fun()->()method!kind="indicator"(**/**)methodactive_char=self#get_pprop_active_charmethodset_active_char=self#set_pprop_active_charmethodinactive_char=self#get_pprop_inactive_charmethodset_inactive_char=self#set_pprop_inactive_char(**/**)method!do_apply_theme~root~parentparent_pathrules=(* we need to update the label after theming, since
theming does not trigger callbacks for property changes *)super#do_apply_theme~root~parentparent_pathrules;update__()methodprivateset__:'a.('a->string*Props.props)->'a->unit=funmapv->update__<-(fun()->lettext,props=mapvinself#set_texttext;self#set_propsprops);update__()(**/**)(** [#connect_to obj prop f] adds a handler to [obj] so that when its [prop]
changes, [f] is called. The result [text, props] of the call to [f]
is used to set the text in the indicator label, and apply [props] to the label.*)methodconnect_to:'a.Object.o->'aProps.prop->('a->string*Props.props)->unit=funobjpropmap->(matchobj#opt_ppropwith|Somev->self#set__mapv|None->matchProps.default_valuepropwith|Somev->self#set__mapv|None->());Option.iterEvents.unregistercb_id;Option.iterEvents.unregistercb_id_destroy;letid=obj#connect(Object.Prop_changedprop)(fun~prev:_~now->self#set__mapnow)inletid_destroy=obj#connectWidget.Destroy(fun()->self#set_text"";false)incb_id<-Someid;cb_id_destroy<-Someid_destroy(** Same as [#connect_to] but the property is always {!Props.active}
and the indicator properties {!prop_active_char} and {!prop_inactive_char}
to set the label text. *)methodconnect_to_activeobj=self#connect_toobjProps.active(map_activeself)initializerignore(self#connect(Object.Prop_changedprop_active_char)(fun~prev:_~now:_->update__()));ignore(self#connect(Object.Prop_changedprop_inactive_char)(fun~prev:_~now:_->update__()));endtypeWidget.widget_type+=Indicatorofindicator(** Convenient function to create a {!class-indicator}.
See {!Widget.widget_arguments} for arguments. *)letindicator?classes?name?props?wdata?group?pack()=letw=newindicator?classes?name?props?wdata()inw#set_typ(Indicatorw);Widget.may_pack?packw#coerce;w