Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clear method to LTerm_widget.box #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/lTerm_widget.mli
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ class type box = object

method remove : #t -> unit
(** [remove widget] remove a widget from the box. *)

method clear : unit
(** [clear] removes all widgets from the box. *)
end

(** A widget displaying a list of widgets, listed horizontally. *)
Expand Down
8 changes: 8 additions & 0 deletions src/widget_impl/lTerm_containers_impl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class type box = object
inherit t
method add : ?position : int -> ?expand : bool -> #t -> unit
method remove : #t -> unit
method clear : unit
end

class virtual abox rc = object(self)
Expand Down Expand Up @@ -68,6 +69,13 @@ class virtual abox rc = object(self)
self#compute_size_request;
self#compute_allocations;
self#queue_draw

method clear =
List.iter (fun child -> child.widget#set_parent None) children;
children <- [];
self#compute_size_request;
self#compute_allocations;
Copy link
Contributor Author

@bonkf bonkf Oct 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calls to #compute_size_request and #compute_allocations are currently not needed since children is empty at this point; I wasn't sure if I could leave them out since some boxes may have custom implementations that depend on values other than children.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch that, they are still necessary, although they could theoretically be replaced with default values there is not much to be gained here.

self#queue_draw
end

class hbox = object(self)
Expand Down