Skip to content

Commit b588f73

Browse files
committed
feat: allow widgets to control the visibility of objects
1 parent 5dd1310 commit b588f73

11 files changed

Lines changed: 40 additions & 22 deletions

File tree

src/app/tray_menu.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,17 @@ impl AppTrayMenu {
6868

6969
init(&mut menu_item);
7070
menu.append(&*menu_item);
71-
menu_item.show();
7271
}
7372
AppTrayMenuItem::Item { value, mut init } => {
7473
let mut menu_item = ViIconMenuItem::new((), value);
7574

7675
init(&mut menu_item);
7776
menu.append(&*menu_item);
78-
menu_item.show();
7977
}
8078
AppTrayMenuItem::Separator => {
8179
let separator = gtk::SeparatorMenuItem::new();
8280
menu.append(&separator);
83-
separator.show();
81+
separator.set_visible(true);
8482
}
8583
}
8684
}

src/main.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ fn main() -> anyhowResult<ExitCode> {
166166

167167
let name_window = app_config.get_name_or_default();
168168

169-
let mut is_keyboard_allowed = false;
170-
build_ui(app, name_window, &app_config, &c_display, &defcss, &mut is_keyboard_allowed, tx_appevents.clone(), rx_appevents.clone());
169+
build_ui(app, name_window, &app_config, &c_display, &defcss, tx_appevents.clone(), rx_appevents.clone());
171170
}));
172171

173172
Ok(application.run())
@@ -197,7 +196,6 @@ fn build_ui(
197196
app_config: &Rc<AppConfig>,
198197
c_display: &Rc<ViGraphDisplayInfo>,
199198
defcss: &CssProvider,
200-
is_keyboard_allowed: &mut bool,
201199

202200
sender: Sender<AppEvents>,
203201
receiver: Rc<Receiver<AppEvents>>,
@@ -229,6 +227,9 @@ fn build_ui(
229227
);
230228

231229
let vbox = Rc::new(GtkBox::new(gtk::Orientation::Vertical, 0));
230+
vbox.set_valign(gtk::Align::Start);
231+
vbox.set_halign(gtk::Align::Baseline);
232+
232233
vbox.pack_start(
233234
&ViDockHead::new(
234235
app_config.clone(),
@@ -241,11 +242,10 @@ fn build_ui(
241242
0,
242243
); // expand: true, fill: true
243244

244-
let sensors: LMSensors =
245-
lm_sensors::Initializer::default()
246-
.initialize()
247-
.map_err(|e| anyhow!("{:?}", e))
248-
.unwrap(); // TODO REFACTORING ME?;
245+
let sensors: LMSensors = lm_sensors::Initializer::default()
246+
.initialize()
247+
.map_err(|e| anyhow!("{:?}", e))
248+
.unwrap(); // TODO REFACTORING ME?;
249249

250250
{
251251
vbox.pack_start(
@@ -399,6 +399,7 @@ fn build_ui(
399399
});
400400
}
401401
dock_window.set_child(Some(&*vbox));
402+
vbox.set_visible(true);
402403

403404
std::thread::spawn(enc!((sender)move || {
404405
let keyboard_listener = KeyboardListenerBuilder::with_len::<6>()
@@ -466,6 +467,7 @@ fn build_ui(
466467

467468
dock_window.set_pos_inscreen(&*c_display, pos_inscreen);
468469
}));
470+
469471
dock_window.connect_resize_mode_notify(enc!((pos_inscreen, c_display, dock_window) move |_| {
470472
let pos_inscreen: PosINScreen = *pos_inscreen.borrow();
471473

@@ -496,7 +498,7 @@ fn build_ui(
496498
}),
497499
);
498500
glib::timeout_add_local(
499-
std::time::Duration::from_millis(500),
501+
std::time::Duration::from_millis(1500),
500502
enc!((sender)move || {
501503
let _e = sender.send_blocking(AppEvents::KeyboardListenerState(false));
502504

@@ -572,9 +574,9 @@ fn build_ui(
572574
},
573575
AppEvents::KeyboardListenerState(false) => {
574576
if let Some(vihotkey) = wdock_vihotkey {
575-
vihotkey.hide();
577+
vihotkey.set_visible(false);
576578
vbox.remove(&vihotkey);
577-
579+
578580
wdock_vihotkey = None;
579581
}
580582
},
@@ -584,6 +586,6 @@ fn build_ui(
584586
);
585587

586588
glib::MainContext::default().spawn_local(enc!((dock_window) async move {
587-
dock_window.show_all();
589+
dock_window.present();
588590
}));
589591
}

src/widgets/dock_head.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ impl ViDockHead {
4444
let head = Box::new(gtk::Orientation::Horizontal, 0);
4545
head.style_context().add_class("namehead");
4646
head.set_valign(gtk::Align::Start);
47-
47+
4848
head.connect_draw(enc!((app_config)move |window, cr| {
4949
let head_color = app_config.get_window_app_config().get_head_color();
5050

5151
if head_color.is_notblack(transparent) {
5252
let (r, g, b, a) = head_color.into_rgba(transparent);
5353
let (width, height) = {
5454
let allocation = window.allocation();
55-
55+
5656
(allocation.width().into(), allocation.height().into())
5757
};
58-
58+
5959
cr.set_source_rgba(r, g, b, a);
6060
cr.rectangle(
6161
0.0,
@@ -80,6 +80,7 @@ impl ViDockHead {
8080

8181
head.pack_start(&version_label, true, true, 0); // expand: true, fill: true
8282
});
83+
head.set_visible(true);
8384

8485
Self(head)
8586
}

src/widgets/hotkeys.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ops::Deref;
2+
13
use crate::__gen_transparent_gtk_type;
24
use crate::app::config::FontAppConfig;
35
use crate::core::maybe::Maybe;
@@ -68,3 +70,12 @@ impl ViHotkeyItems {
6870
Self(all)
6971
}
7072
}
73+
74+
impl Deref for ViHotkeyItems {
75+
type Target = Box;
76+
77+
#[inline]
78+
fn deref(&self) -> &Self::Target {
79+
&self.0
80+
}
81+
}

src/widgets/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ impl ViMeter {
7676
let graphsender = ViGraph::new_graphsender(app_config.clone(), width, 42, len, transparent);
7777
vbox.pack_start(&*graphsender, true, true, 0);
7878

79+
vbox.set_visible(true);
80+
7981
ViMeterSender {
8082
app_config,
8183
color_and_text: textmeter_sender,
@@ -105,14 +107,11 @@ impl ViMeterSender {
105107
maybe!((graph_v) {
106108
if !self.graph.is_visible() {
107109
self.graph.set_visible(true);
108-
self.graph.show();
109110
}
110111
self.graph.push_next(graph_v);
111112
}else {
112113
if self.graph.is_visible() {
113114
self.graph.set_visible(false);
114-
115-
self.graph.hide();
116115
}
117116
});
118117

src/widgets/primitives/color_block.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ impl ViColorBlock {
3333
let drawing_area = DrawingArea::new();
3434
drawing_area.style_context().add_class("vicolorblock");
3535
drawing_area.set_size_request(width, height);
36+
drawing_area.set_visible(true);
3637

3738
Self(drawing_area)
3839
}

src/widgets/primitives/graph.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ impl Deref for ViGraphSender {
168168
impl ViGraphSender {
169169
pub fn push_next_and_queue_draw(&self, v: f64) {
170170
self.push_next(v);
171+
171172
self.queue_draw();
172173
}
173174

src/widgets/primitives/hotkeyitem.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl ViHotkeyItem {
4141
.set_margin_top(4)
4242
.set_margin_start(3);
4343
hbox.pack_start(&label, false, false, 0);
44+
hbox.set_visible(true);
4445

4546
Self(hbox)
4647
}

src/widgets/primitives/icon_menuitem.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::maybe;
22
use crate::{__gen_transparent_gtk_type, core::maybe::Maybe};
33
use gtk::MenuItem;
44
use gtk::ffi::GtkMenuItem;
5-
use gtk::traits::ContainerExt;
5+
use gtk::traits::{ContainerExt, WidgetExt};
66
use std::ops::Deref;
77

88
#[repr(transparent)]
@@ -49,6 +49,7 @@ impl ViIconMenuItem {
4949
} else {
5050
menu_item.set_child(Some(&gtk::Label::new(Some(label))));
5151
});
52+
menu_item.set_visible(true);
5253

5354
Self(menu_item)
5455
}

src/widgets/primitives/label.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl ViLabel {
5959
style.add_class("vilabel");
6060
maybe!((class) style.add_class(class));
6161
}
62+
label.set_visible(true);
6263

6364
Self(label)
6465
}

0 commit comments

Comments
 (0)