Skip to content

Commit

Permalink
add size lock (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdaqo committed Feb 4, 2024
1 parent 4afc86a commit eb7d2a4
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mpv-subs-popout"
version = "0.4.0"
version = "0.3.2"
edition = "2021"
description = "Popout Mpv's Subs"
readme = "README.md"
Expand Down
45 changes: 44 additions & 1 deletion src/app/ctxmenu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,44 @@ pub fn build_ctxmenu(window: &MpvSubsWindow) -> ContextMenu {
None,
);

let sizelock_btn = CheckButton::builder()
.label("Lock Size")
.active(config.size_lock != None)
.build();

ctxmenu.add_item(
&sizelock_btn,
Box::new(
clone!(@weak window => @default-return Inhibit(true), move |wg, _ev| {
let state = wg.is_active();

wg.set_active(!state);

let mut config = AppConfig::new();
let label_box = window.imp().label_box.get().unwrap();
if !state {
let width = label_box.allocated_width();
let height = label_box.allocated_height();

label_box.set_size_request(width, height);
window.imp().sub_label.get().unwrap().set_wrap(true);
window.imp().sub_label.get().unwrap().set_wrap(true);

config.size_lock = Some((width, height));
} else {
label_box.set_size_request(0, 0);
window.imp().sub_label.get().unwrap().set_wrap(false);
window.imp().sub_label.get().unwrap().set_wrap(false);
config.size_lock = None;
}

config.save();
Inhibit(true)
}),
),
None,
);

let auto_tl_btn = CheckButton::builder()
.label("Auto Translate")
.active(config.auto_tl)
Expand All @@ -110,13 +148,18 @@ pub fn build_ctxmenu(window: &MpvSubsWindow) -> ContextMenu {
clone!(@weak window => @default-return Inhibit(true), move |wg, _ev| {
let state = wg.is_active();


wg.set_active(!state);

let _ = window.imp().channel_sender.get().unwrap().send(Message::SetTlLabelVisibilty(!state));
let _ = window.imp().channel_sender.get().unwrap().send(Message::UpdateTlLabel("".to_string()));

let mut config = AppConfig::new();
if let Some(size) = config.size_lock {
window.imp().label_box.get().unwrap().set_size_request(size.0, size.1);
window.imp().sub_label.get().unwrap().set_wrap(true);
window.imp().sub_label.get().unwrap().set_wrap(true);
}

config.auto_tl = !state;
config.save();

Expand Down
20 changes: 12 additions & 8 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,38 @@ pub fn build_window(app: &gtk::Application) -> MpvSubsWindow {
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);

let cfg = AppConfig::new();

let ctx_menu = build_ctxmenu(&window);

let label_box = gtk::Box::new(gtk::Orientation::Vertical, 6);

let label_box = gtk::Box::new(gtk::Orientation::Vertical, 6);
label_box.set_homogeneous(true);

let sub_label = Label::builder()
.name("sub_label")
.selectable(true)
.build();

sub_label.style_context().add_class("sub_label");

ctx_menu.attach_to_widget(&sub_label);

window.imp().sub_label.set(sub_label).ok();
label_box.add(window.imp().sub_label.get().unwrap());

let cfg = AppConfig::new();

let tl_label = Label::builder()
.name("tl_label")
.build();

tl_label.style_context().add_class("sub_label");

ctx_menu.attach_to_widget(&tl_label);
if let Some(size) = cfg.size_lock {
label_box.set_size_request(size.0, size.1);
sub_label.set_wrap(true);
tl_label.set_wrap(true);
}

window.imp().sub_label.set(sub_label).ok();
label_box.add(window.imp().sub_label.get().unwrap());

ctx_menu.attach_to_widget(&tl_label);
window.imp().tl_label.set(tl_label).ok();

if cfg.auto_tl {
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct AppConfig {
pub borders: bool,
pub bg_col: String,
pub text_col: String,
pub size_lock: Option<(i32, i32)>,
pub auto_tl: bool,
pub default_tl_engine: String,
pub translators: Vec<TlEngineConfig>
Expand All @@ -32,6 +33,7 @@ impl AppConfig {
docked: false,
ontop: true,
borders: true,
size_lock: None,
bg_col: "rgb(42, 46, 50)".to_owned(),
text_col: "rgb(255, 255, 255)".to_owned(),
auto_tl: false,
Expand Down

0 comments on commit eb7d2a4

Please sign in to comment.