Skip to content

Commit 40a0ebe

Browse files
authored
checkBox.js: Use the new checkBox object (#13564)
Remove all the old checkbox code and move to the use of the new one. Removes a use of CinnamonGenericContainer. This is hardly used in any spices so shouldn't have many side effects. Most themes should also just work.
1 parent fd057af commit 40a0ebe

6 files changed

Lines changed: 25 additions & 183 deletions

File tree

data/theme/cinnamon-sass/widgets/_menus.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ $menuitem_border_radius: $base_border_radius * 1;
2828
color: $insensitive_fg_color;
2929
background: none;
3030
}
31+
32+
.check-box {
33+
StBoxLayout { spacing: 0; }
34+
}
3135
}
3236

3337
// Used in the battery applet for the status

data/theme/cinnamon-sass/widgets/_switch-check.scss

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,9 @@ $check_width: 20px;
1616
&:checked { background-image: url("toggle-on.svg"); }
1717
}
1818

19-
// check
19+
// CheckBoxes
2020

2121
.check-box {
22-
CinnamonGenericContainer { spacing: 0.8em; }
23-
24-
StBin {
25-
width: $check_width;
26-
height: $check_height;
27-
background-image: url("checkbox-off.svg");
28-
}
29-
&:focus StBin { background-image: url("checkbox-off.svg"); }
30-
&:checked StBin { background-image: url("checkbox.svg"); }
31-
&:focus:checked StBin { background-image: url("checkbox.svg"); }
32-
}
33-
34-
// New CheckBoxes
35-
36-
.check-box-2 {
3722
StBoxLayout { spacing: 0.8em; }
3823

3924
StBin {

js/ui/checkBox.js

Lines changed: 3 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,14 @@
11
const Clutter = imports.gi.Clutter;
22
const GObject = imports.gi.GObject;
33
const Pango = imports.gi.Pango;
4-
const Cinnamon = imports.gi.Cinnamon;
54
const St = imports.gi.St;
6-
const Params = imports.misc.params;
75

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 {
1588
_init(label) {
1599
let container = new St.BoxLayout();
16010
super._init({
161-
style_class: 'check-box-2',
11+
style_class: 'check-box',
16212
important: true,
16313
child: container,
16414
button_mask: St.ButtonMask.ONE,

js/ui/keyringPrompt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class KeyringDialog extends ModalDialog.ModalDialog {
8787
passwordBox.add_child(warningBox);
8888
content.add_child(passwordBox);
8989

90-
this._choice = new CheckBox.CheckBox2();
90+
this._choice = new CheckBox.CheckBox();
9191
this.prompt.bind_property('choice-label', this._choice.getLabelActor(),
9292
'text', GObject.BindingFlags.SYNC_CREATE);
9393
this.prompt.bind_property('choice-chosen', this._choice,

js/ui/popupMenu.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,16 @@ var PopupMenuItem = class PopupMenuItem extends PopupBaseMenuItem {
498498
setOrnament(ornamentType, state) {
499499
switch (ornamentType) {
500500
case OrnamentType.CHECK:
501-
if ((this._ornament.child)&&(!(this._ornament.child._delegate instanceof CheckBox.CheckButton))) {
501+
if ((this._ornament.child) && (!(this._ornament.child._delegate instanceof CheckBox.CheckBox))) {
502502
this._ornament.child.destroy();
503503
this._ornament.child = null;
504504
}
505505
if (!this._ornament.child) {
506-
let switchOrn = new CheckBox.CheckButton(state);
507-
this._ornament.child = switchOrn.actor;
506+
let switchOrn = new CheckBox.CheckBox();
507+
switchOrn.set_checked(state);
508+
this._ornament.child = switchOrn;
508509
} else {
509-
this._ornament.child._delegate.setToggleState(state);
510+
this._ornament.child.set_checked(state);
510511
}
511512
this._icon = null;
512513
break;
@@ -1164,15 +1165,16 @@ var PopupIndicatorMenuItem = class PopupIndicatorMenuItem extends PopupBaseMenuI
11641165
setOrnament(ornamentType, state) {
11651166
switch (ornamentType) {
11661167
case OrnamentType.CHECK:
1167-
if ((this._ornament.child)&&(!(this._ornament.child._delegate instanceof CheckBox.CheckButton))) {
1168+
if ((this._ornament.child)&&(!(this._ornament.child._delegate instanceof CheckBox.CheckBox))) {
11681169
this._ornament.child.destroy();
11691170
this._ornament.child = null;
11701171
}
11711172
if (!this._ornament.child) {
1172-
let switchOrn = new CheckBox.CheckButton(null, {}, state);
1173-
this._ornament.child = switchOrn.actor;
1173+
let switchOrn = new CheckBox.CheckBox();
1174+
switchOrn.set_checked(state);
1175+
this._ornament.child = switchOrn;
11741176
} else {
1175-
this._ornament.child._delegate.setToggleState(state);
1177+
this._ornament.child.set_checked(state);
11761178
}
11771179
this._icon = null;
11781180
break;

js/ui/windowMenu.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,17 @@ var MnemonicLeftOrnamentedMenuItem = class MnemonicLeftOrnamentedMenuItem extend
8181
setOrnament(ornamentType, state) {
8282
switch (ornamentType) {
8383
case PopupMenu.OrnamentType.CHECK:
84-
if ((this._ornament.child)&&(!(this._ornament.child._delegate instanceof CheckBox.CheckButton))) {
84+
if ((this._ornament.child) && (!(this._ornament.child._delegate instanceof CheckBox.CheckBox))) {
8585
this._ornament.child.destroy();
8686
this._ornament.child = null;
8787
}
8888
if (!this._ornament.child) {
89-
let switchOrn = new CheckBox.CheckButton(state);
90-
this._ornament.child = switchOrn.actor;
91-
switchOrn.actor.reactive = false;
89+
let switchOrn = new CheckBox.CheckBox();
90+
switchOrn.set_checked(state);
91+
this._ornament.child = switchOrn;
92+
switchOrn.reactive = false;
9293
} else {
93-
this._ornament.child._delegate.setToggleState(state);
94+
this._ornament.child.set_checked(state);
9495
}
9596
this._icon = null;
9697
break;

0 commit comments

Comments
 (0)