mirror of
https://gitlab.com/liyaowhen/youtubecollector-git.git
synced 2026-10-01 01:12:59 +00:00
added focus stuff, still needs tweaking
This commit is contained in:
@@ -3,7 +3,6 @@ using Gtk;
|
||||
namespace Song {
|
||||
|
||||
|
||||
public delegate void EventQueue();
|
||||
/* to ensure that doing things on the main_view_content or sidebar_content
|
||||
in this SongController allows for those objects to exist, instead of
|
||||
doing functions related to this controller in the bare construct {},
|
||||
@@ -14,6 +13,7 @@ namespace Song {
|
||||
public static SideBarContent sidebar_content;
|
||||
public static SideBar side_bar;
|
||||
public static Adw.OverlaySplitView split_view;
|
||||
public static MainView main_view;
|
||||
|
||||
public static SongControls song_controls;
|
||||
|
||||
@@ -23,5 +23,18 @@ namespace Song {
|
||||
|
||||
}
|
||||
|
||||
public class SignalHub : Object {
|
||||
private static SignalHub? instance = null;
|
||||
|
||||
public signal void mouse_clicked();
|
||||
|
||||
public static SignalHub get_instance () {
|
||||
if (instance == null) {
|
||||
instance = new SignalHub();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,12 +5,17 @@ namespace Song {
|
||||
public Settings settings = new Settings("com.liyaowhen.Song.playlists");
|
||||
public MainViewContent main_content;
|
||||
public PlaylistObject current_playlist;
|
||||
private Gtk.Revealer add_button_revealer = new Gtk.Revealer();
|
||||
|
||||
public signal void enter_yt_search_mode();
|
||||
public signal void exit_yt_search_mode();
|
||||
|
||||
public MainView(Window _window) {
|
||||
this.window = _window;
|
||||
}
|
||||
|
||||
construct {
|
||||
SongController.main_view = this;
|
||||
|
||||
// make ui
|
||||
var toolbar_view = new Adw.ToolbarView ();
|
||||
@@ -32,6 +37,9 @@ namespace Song {
|
||||
add_button_content.set_label("Add Item");
|
||||
add_button.set_child(add_button_content);
|
||||
add_button.valign = Gtk.Align.CENTER;
|
||||
add_button_revealer.set_child(add_button);
|
||||
add_button_revealer.set_reveal_child(true);
|
||||
add_button_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_RIGHT;
|
||||
|
||||
add_button.clicked.connect(() => {
|
||||
var popover = new NewMusicPopover();
|
||||
@@ -42,7 +50,7 @@ namespace Song {
|
||||
action_bar.show_back_button = false;
|
||||
action_bar.title_widget = new YtSearchBar();
|
||||
action_bar.pack_start(collapse_button);
|
||||
action_bar.pack_start(add_button);
|
||||
action_bar.pack_start(add_button_revealer);
|
||||
action_bar.margin_start = 5;
|
||||
|
||||
collapse_button.clicked.connect(() => {
|
||||
@@ -80,6 +88,18 @@ namespace Song {
|
||||
this.child = toolbar_view;
|
||||
this.title = "main_view";
|
||||
|
||||
instanciate_signals();
|
||||
|
||||
}
|
||||
|
||||
private void instanciate_signals() {
|
||||
enter_yt_search_mode.connect(() => {
|
||||
add_button_revealer.set_reveal_child(false);
|
||||
});
|
||||
|
||||
exit_yt_search_mode.connect(() => {
|
||||
add_button_revealer.set_reveal_child(true);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +121,9 @@ namespace Song {
|
||||
halign = Gtk.Align.FILL;
|
||||
yt_search_bar.hexpand = true;
|
||||
|
||||
|
||||
can_focus = true;
|
||||
focusable = true;
|
||||
focus_on_click = true;
|
||||
}
|
||||
|
||||
public void new_music_popover_show() {
|
||||
|
||||
+62
-17
@@ -17,13 +17,27 @@ namespace Song {
|
||||
private YtSearchBarStates state = YtSearchBarStates.NONE;
|
||||
private bool isEnlarged = false;
|
||||
|
||||
private bool isMouseInside = false;
|
||||
private YtSearchBarStates? requesting_state = null;
|
||||
|
||||
private Adw.TimedAnimation? enlarge_animation = null;
|
||||
private Adw.TimedAnimation? shrink_animation = null;
|
||||
private Adw.AnimationTarget size_animation_target;
|
||||
|
||||
construct {
|
||||
var gesture = new Gtk.GestureClick();
|
||||
add_controller(gesture);
|
||||
var motion_sensor = new Gtk.EventControllerMotion();
|
||||
search_entry.add_controller(motion_sensor);
|
||||
|
||||
motion_sensor.leave.connect(() => {
|
||||
isMouseInside = false;
|
||||
});
|
||||
|
||||
motion_sensor.enter.connect(() => {
|
||||
isMouseInside = true;
|
||||
});
|
||||
|
||||
var focus_event = new Gtk.EventControllerFocus();
|
||||
add_controller(focus_event);
|
||||
|
||||
add_css_class ("toolbar");
|
||||
hexpand = true;
|
||||
@@ -40,20 +54,53 @@ namespace Song {
|
||||
|
||||
instanciate_signals();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void instanciate_signals() {
|
||||
search_entry.changed.connect((e) => {
|
||||
if (e.get_text() != null && state == YtSearchBarStates.NONE) {
|
||||
if (e.get_text() != "" && !isEnlarged) {
|
||||
/*focus_event.enter.connect(() => {
|
||||
enlarge();
|
||||
} else if (e.get_text() == "" && isEnlarged) {
|
||||
shrink();
|
||||
}
|
||||
}
|
||||
SongController.main_view.enter_yt_search_mode();
|
||||
});
|
||||
|
||||
focus_event.leave.connect(() => {
|
||||
shrink();
|
||||
SongController.main_view.exit_yt_search_mode();
|
||||
});*/
|
||||
}
|
||||
|
||||
|
||||
private void instanciate_signals() {
|
||||
var signal_hub = SignalHub.get_instance();
|
||||
signal_hub.mouse_clicked.connect(() => {
|
||||
if (!isMouseInside && isEnlarged) {
|
||||
shrink();
|
||||
SongController.main_view.exit_yt_search_mode();
|
||||
} else if (!isEnlarged && isMouseInside) {
|
||||
enlarge();
|
||||
SongController.main_view.enter_yt_search_mode();
|
||||
} else if (!isEnlarged && !isMouseInside && state == YtSearchBarStates.ENLARGING) {
|
||||
requesting_state = YtSearchBarStates.SHRINKING;
|
||||
Timeout.add(1, () => {
|
||||
if (requesting_state != YtSearchBarStates.SHRINKING) return false;
|
||||
if (isEnlarged) {
|
||||
shrink();
|
||||
SongController.main_view.exit_yt_search_mode();
|
||||
requesting_state = null;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} else if (isEnlarged && isMouseInside && state == YtSearchBarStates.SHRINKING) {
|
||||
requesting_state = YtSearchBarStates.ENLARGING;
|
||||
Timeout.add(1, () => {
|
||||
if (requesting_state != YtSearchBarStates.ENLARGING) return false;
|
||||
if (!isEnlarged) {
|
||||
enlarge();
|
||||
SongController.main_view.enter_yt_search_mode();
|
||||
requesting_state = null;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void enlarge() {
|
||||
@@ -62,8 +109,7 @@ namespace Song {
|
||||
enlarge_animation.done.connect(() => {
|
||||
isEnlarged = true;
|
||||
state = YtSearchBarStates.NONE;
|
||||
print(state.to_string() + "\n");
|
||||
print(isEnlarged.to_string() + "\n");
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -77,8 +123,6 @@ namespace Song {
|
||||
shrink_animation.done.connect(() => {
|
||||
isEnlarged = false;
|
||||
state = YtSearchBarStates.NONE;
|
||||
print(state.to_string() + "\n");
|
||||
print(isEnlarged.to_string() + "\n");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -86,4 +130,5 @@ namespace Song {
|
||||
state = YtSearchBarStates.SHRINKING;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -93,7 +93,14 @@ namespace Song {
|
||||
|
||||
set_content(_content);
|
||||
|
||||
var click_monitor = new Gtk.GestureClick ();
|
||||
_content.add_controller(click_monitor);
|
||||
click_monitor.set_propagation_phase(Gtk.PropagationPhase.CAPTURE);
|
||||
|
||||
var signal_hub = SignalHub.get_instance();
|
||||
click_monitor.begin.connect(() => {
|
||||
signal_hub.mouse_clicked();
|
||||
});
|
||||
}
|
||||
|
||||
public void new_music_popover_show() {
|
||||
|
||||
Reference in New Issue
Block a user