Skip to content

Commit 893c134

Browse files
danirabbitjeremypwzeebok
authored
EventButton: don't subclass Revealer (#854)
* EventButton: don't subclass Revealer * Always show * Fix bug when adding to collapsed list --------- Co-authored-by: Jeremy Wootten <jeremywootten@gmail.com> Co-authored-by: Ryan Kornheisl <ryan@skarva.tech>
1 parent 44d2c0e commit 893c134

2 files changed

Lines changed: 46 additions & 51 deletions

File tree

src/Grid/EventButton.vala

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
/*
2-
* Copyright 2011-2018 elementary, Inc. (https://elementary.io)
3-
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2011-2025 elementary, Inc. (https://elementary.io)
164
*
175
* Authored by: Maxwell Barvian
186
* Corentin Noël <corentin@elementaryos.org>
197
*/
208

21-
public class Maya.View.EventButton : Gtk.Revealer {
9+
public class Maya.View.EventButton : Gtk.Bin {
2210
public ECal.Component comp { get; construct set; }
2311

12+
private Gtk.Revealer revealer;
2413
private Gtk.Label label;
2514
private Gtk.StyleContext grid_style_context;
2615

@@ -34,12 +23,11 @@ public class Maya.View.EventButton : Gtk.Revealer {
3423
}
3524

3625
construct {
37-
transition_type = Gtk.RevealerTransitionType.CROSSFADE;
38-
39-
label = new Gtk.Label (comp.get_summary ().get_value ());
40-
label.hexpand = true;
41-
label.ellipsize = Pango.EllipsizeMode.END;
42-
label.xalign = 0;
26+
label = new Gtk.Label (comp.get_summary ().get_value ()) {
27+
hexpand = true,
28+
ellipsize = END,
29+
xalign = 0
30+
};
4331
label.show ();
4432

4533
var internal_grid = new Gtk.Grid ();
@@ -51,7 +39,12 @@ public class Maya.View.EventButton : Gtk.Revealer {
5139
var event_box = new Gtk.EventBox ();
5240
event_box.add (internal_grid);
5341

54-
add (event_box);
42+
revealer = new Gtk.Revealer () {
43+
child = event_box,
44+
transition_type = CROSSFADE
45+
};
46+
47+
child = revealer;
5548

5649
var context_menu = Maya.EventMenu.build (comp);
5750
context_menu.attach_to_widget (this, null);
@@ -143,10 +136,36 @@ public class Maya.View.EventButton : Gtk.Revealer {
143136
}
144137

145138
public void destroy_button () {
146-
set_reveal_child (false);
147-
Timeout.add (transition_duration, () => {
139+
revealer.reveal_child = false;
140+
Timeout.add (revealer.transition_duration, () => {
148141
destroy ();
149142
return false;
150143
});
151144
}
145+
146+
public void hide_without_animate () {
147+
if (!revealer.child_revealed) {
148+
return;
149+
}
150+
151+
var reveal_duration = revealer.transition_duration;
152+
revealer.transition_duration = 0;
153+
revealer.reveal_child = false;
154+
revealer.transition_duration = reveal_duration;
155+
156+
hide ();
157+
}
158+
159+
public void show_without_animate () {
160+
show ();
161+
162+
if (revealer.child_revealed) {
163+
return;
164+
}
165+
166+
var reveal_duration = revealer.transition_duration;
167+
revealer.transition_duration = 0;
168+
revealer.reveal_child = true;
169+
revealer.transition_duration = reveal_duration;
170+
}
152171
}

src/Grid/VAutoHider.vala

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class Maya.View.VAutoHider : Gtk.Bin {
7373
int child_height;
7474
child.show ();
7575
child.get_preferred_height (out child_height, null);
76-
child.hide ();
76+
((Maya.View.EventButton) child).hide_without_animate ();
7777

7878
bool should_hide;
7979
if (global_height - more_label_height < child_height + height) {
@@ -87,11 +87,9 @@ public class Maya.View.VAutoHider : Gtk.Bin {
8787
}
8888

8989
if (should_hide) {
90-
hide_revealer_now ((Gtk.Revealer)child);
91-
child.hide ();
90+
((Maya.View.EventButton) child).hide_without_animate ();
9291
} else {
93-
show_revealer_now ((Gtk.Revealer)child);
94-
child.show ();
92+
((Maya.View.EventButton) child).show_without_animate ();
9593
shown_children++;
9694
}
9795
}
@@ -105,28 +103,6 @@ public class Maya.View.VAutoHider : Gtk.Bin {
105103
}
106104
}
107105

108-
private void hide_revealer_now (Gtk.Revealer revealer) {
109-
if (revealer.child_revealed == false)
110-
return;
111-
112-
var reveal_duration = revealer.transition_duration;
113-
revealer.transition_duration = 0;
114-
revealer.set_reveal_child (false);
115-
revealer.transition_duration = reveal_duration;
116-
revealer.hide ();
117-
}
118-
119-
private void show_revealer_now (Gtk.Revealer revealer) {
120-
if (revealer.child_revealed == true)
121-
return;
122-
123-
var reveal_duration = revealer.transition_duration;
124-
revealer.transition_duration = 0;
125-
revealer.set_reveal_child (true);
126-
revealer.transition_duration = reveal_duration;
127-
revealer.show ();
128-
}
129-
130106
public override void get_preferred_width (out int minimum_width, out int natural_width) {
131107
base.get_preferred_width (out minimum_width, out natural_width);
132108
more_label.get_preferred_width (out minimum_width, null);

0 commit comments

Comments
 (0)