|
1 | 1 | const Clutter = imports.gi.Clutter; |
2 | 2 | const GObject = imports.gi.GObject; |
3 | 3 | const Pango = imports.gi.Pango; |
4 | | -const Cinnamon = imports.gi.Cinnamon; |
5 | 4 | const St = imports.gi.St; |
6 | | -const Params = imports.misc.params; |
7 | 5 |
|
8 | | -const Lang = imports.lang; |
9 | | - |
10 | | -var CheckBoxContainer = class { |
11 | | - constructor() { |
12 | | - this.actor = new Cinnamon.GenericContainer({ y_align: St.Align.MIDDLE }); |
13 | | - this.actor.connect('get-preferred-width', |
14 | | - Lang.bind(this, this._getPreferredWidth)); |
15 | | - this.actor.connect('get-preferred-height', |
16 | | - Lang.bind(this, this._getPreferredHeight)); |
17 | | - this.actor.connect('allocate', |
18 | | - Lang.bind(this, this._allocate)); |
19 | | - this.actor.connect('style-changed', Lang.bind(this, |
20 | | - function() { |
21 | | - let node = this.actor.get_theme_node(); |
22 | | - this._spacing = Math.round(node.get_length('spacing')); |
23 | | - })); |
24 | | - this.actor.request_mode = Clutter.RequestMode.HEIGHT_FOR_WIDTH; |
25 | | - |
26 | | - this._box = new St.Bin(); |
27 | | - this.actor.add_actor(this._box); |
28 | | - |
29 | | - this.label = new St.Label(); |
30 | | - this.label.clutter_text.set_line_wrap(false); |
31 | | - this.label.clutter_text.set_ellipsize(Pango.EllipsizeMode.NONE); |
32 | | - this.actor.add_actor(this.label); |
33 | | - |
34 | | - this._spacing = 0; |
35 | | - } |
36 | | - |
37 | | - _getPreferredWidth(actor, forHeight, alloc) { |
38 | | - let node = this.actor.get_theme_node(); |
39 | | - forHeight = node.adjust_for_height(forHeight); |
40 | | - |
41 | | - let [minBoxWidth, natBoxWidth] = this._box.get_preferred_width(forHeight); |
42 | | - let boxNode = this._box.get_theme_node(); |
43 | | - [minBoxWidth, natBoxWidth] = boxNode.adjust_preferred_width(minBoxWidth, natBoxWidth); |
44 | | - |
45 | | - let [minLabelWidth, natLabelWidth] = this.label.get_preferred_width(forHeight); |
46 | | - let labelNode = this.label.get_theme_node(); |
47 | | - [minLabelWidth, natLabelWidth] = labelNode.adjust_preferred_width(minLabelWidth, natLabelWidth); |
48 | | - |
49 | | - let min = minBoxWidth + minLabelWidth + this._spacing; |
50 | | - let nat = natBoxWidth + natLabelWidth + this._spacing; |
51 | | - [min, nat] = node.adjust_preferred_width(min, nat); |
52 | | - |
53 | | - alloc.min_size = min; |
54 | | - alloc.natural_size = nat; |
55 | | - } |
56 | | - |
57 | | - _getPreferredHeight(actor, forWidth, alloc) { |
58 | | - let [minBoxHeight, natBoxHeight] = |
59 | | - this._box.get_preferred_height(-1); |
60 | | - let [minLabelHeight, natLabelHeight] = |
61 | | - this.label.get_preferred_height(-1); |
62 | | - |
63 | | - alloc.min_size = Math.max(minBoxHeight, minLabelHeight); |
64 | | - alloc.natural_size = Math.max(natBoxHeight, natLabelHeight); |
65 | | - } |
66 | | - |
67 | | - _allocate(actor, box, flags) { |
68 | | - let availWidth = box.x2 - box.x1; |
69 | | - let availHeight = box.y2 - box.y1; |
70 | | - |
71 | | - let childBox = new Clutter.ActorBox(); |
72 | | - let [minBoxWidth, natBoxWidth] = |
73 | | - this._box.get_preferred_width(-1); |
74 | | - let [minBoxHeight, natBoxHeight] = |
75 | | - this._box.get_preferred_height(-1); |
76 | | - childBox.x1 = box.x1; |
77 | | - childBox.x2 = box.x1 + natBoxWidth; |
78 | | - if (availHeight > natBoxHeight) childBox.y1 = box.y1 + (availHeight-natBoxHeight)/2; |
79 | | - else childBox.y1 = box.y1; |
80 | | - childBox.y2 = childBox.y1 + natBoxHeight; |
81 | | - this._box.allocate(childBox, flags); |
82 | | - |
83 | | - let [minLabelWidth, natLabelWidth] = |
84 | | - this.label.get_preferred_width(-1); |
85 | | - let [minLabelHeight, natLabelHeight] = |
86 | | - this.label.get_preferred_height(-1); |
87 | | - childBox.x1 = box.x1 + natBoxWidth + this._spacing; |
88 | | - childBox.x2 = childBox.x1 + availWidth - natBoxWidth - this._spacing; |
89 | | - if (availHeight > natLabelHeight) childBox.y1 = box.y1 + (availHeight-natLabelHeight)/2; |
90 | | - else childBox.y1 = box.y1; |
91 | | - childBox.y2 = childBox.y1 + natLabelHeight; |
92 | | - this.label.allocate(childBox, flags); |
93 | | - } |
94 | | -} |
95 | | - |
96 | | -var CheckBoxBase = class { |
97 | | - constructor(checkedState, params) { |
98 | | - this._params = { style_class: 'check-box', |
99 | | - button_mask: St.ButtonMask.ONE, |
100 | | - toggle_mode: true, |
101 | | - can_focus: true, |
102 | | - x_fill: true, |
103 | | - y_fill: true, |
104 | | - y_align: St.Align.MIDDLE }; |
105 | | - |
106 | | - if (params != undefined) { |
107 | | - this._params = Params.parse(params, this._params); |
108 | | - } |
109 | | - |
110 | | - this.actor = new St.Button(this._params); |
111 | | - this.actor._delegate = this; |
112 | | - this.actor.checked = checkedState; |
113 | | - } |
114 | | - |
115 | | - setToggleState(checkedState) { |
116 | | - this.actor.checked = checkedState; |
117 | | - } |
118 | | - |
119 | | - toggle() { |
120 | | - this.setToggleState(!this.actor.checked); |
121 | | - } |
122 | | - |
123 | | - destroy() { |
124 | | - this.actor.destroy(); |
125 | | - } |
126 | | -} |
127 | | - |
128 | | -var CheckButton = class extends CheckBoxBase { |
129 | | - constructor(checkedState, params) { |
130 | | - super(checkedState, params); |
131 | | - this.checkmark = new St.Bin(); |
132 | | - this.actor.set_child(this.checkmark); |
133 | | - } |
134 | | -} |
135 | | - |
136 | | -var CheckBox = class extends CheckBoxBase { |
137 | | - constructor(label, params, checkedState) { |
138 | | - super(checkedState, params); |
139 | | - |
140 | | - this._container = new CheckBoxContainer(); |
141 | | - this.actor.set_child(this._container.actor); |
142 | | - |
143 | | - if (label) |
144 | | - this.setLabel(label); |
145 | | - } |
146 | | - |
147 | | - setLabel(label) { |
148 | | - this._container.label.set_text(label); |
149 | | - } |
150 | | - |
151 | | - getLabelActor() { |
152 | | - return this._container.label; |
153 | | - } |
154 | | -} |
155 | | - |
156 | | -var CheckBox2 = GObject.registerClass( |
157 | | -class CheckBox2 extends St.Button { |
| 6 | +var CheckBox = GObject.registerClass( |
| 7 | +class CheckBox extends St.Button { |
158 | 8 | _init(label) { |
159 | 9 | let container = new St.BoxLayout(); |
160 | 10 | super._init({ |
161 | | - style_class: 'check-box-2', |
| 11 | + style_class: 'check-box', |
162 | 12 | important: true, |
163 | 13 | child: container, |
164 | 14 | button_mask: St.ButtonMask.ONE, |
|
0 commit comments