added focus stuff, still needs tweaking

This commit is contained in:
liyaowhen
2024-07-31 22:59:10 -07:00
parent eb3cd17617
commit 0b9c61144b
4 changed files with 106 additions and 19 deletions
+14 -1
View File
@@ -3,7 +3,6 @@ using Gtk;
namespace Song { namespace Song {
public delegate void EventQueue();
/* to ensure that doing things on the main_view_content or sidebar_content /* to ensure that doing things on the main_view_content or sidebar_content
in this SongController allows for those objects to exist, instead of in this SongController allows for those objects to exist, instead of
doing functions related to this controller in the bare construct {}, doing functions related to this controller in the bare construct {},
@@ -14,6 +13,7 @@ namespace Song {
public static SideBarContent sidebar_content; public static SideBarContent sidebar_content;
public static SideBar side_bar; public static SideBar side_bar;
public static Adw.OverlaySplitView split_view; public static Adw.OverlaySplitView split_view;
public static MainView main_view;
public static SongControls song_controls; 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;
}
}
} }
+24 -2
View File
@@ -5,12 +5,17 @@ namespace Song {
public Settings settings = new Settings("com.liyaowhen.Song.playlists"); public Settings settings = new Settings("com.liyaowhen.Song.playlists");
public MainViewContent main_content; public MainViewContent main_content;
public PlaylistObject current_playlist; 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) { public MainView(Window _window) {
this.window = _window; this.window = _window;
} }
construct { construct {
SongController.main_view = this;
// make ui // make ui
var toolbar_view = new Adw.ToolbarView (); var toolbar_view = new Adw.ToolbarView ();
@@ -32,6 +37,9 @@ namespace Song {
add_button_content.set_label("Add Item"); add_button_content.set_label("Add Item");
add_button.set_child(add_button_content); add_button.set_child(add_button_content);
add_button.valign = Gtk.Align.CENTER; 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(() => { add_button.clicked.connect(() => {
var popover = new NewMusicPopover(); var popover = new NewMusicPopover();
@@ -42,7 +50,7 @@ namespace Song {
action_bar.show_back_button = false; action_bar.show_back_button = false;
action_bar.title_widget = new YtSearchBar(); action_bar.title_widget = new YtSearchBar();
action_bar.pack_start(collapse_button); action_bar.pack_start(collapse_button);
action_bar.pack_start(add_button); action_bar.pack_start(add_button_revealer);
action_bar.margin_start = 5; action_bar.margin_start = 5;
collapse_button.clicked.connect(() => { collapse_button.clicked.connect(() => {
@@ -80,6 +88,18 @@ namespace Song {
this.child = toolbar_view; this.child = toolbar_view;
this.title = "main_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; halign = Gtk.Align.FILL;
yt_search_bar.hexpand = true; yt_search_bar.hexpand = true;
can_focus = true;
focusable = true;
focus_on_click = true;
} }
public void new_music_popover_show() { public void new_music_popover_show() {
+63 -18
View File
@@ -17,13 +17,27 @@ namespace Song {
private YtSearchBarStates state = YtSearchBarStates.NONE; private YtSearchBarStates state = YtSearchBarStates.NONE;
private bool isEnlarged = false; private bool isEnlarged = false;
private bool isMouseInside = false;
private YtSearchBarStates? requesting_state = null;
private Adw.TimedAnimation? enlarge_animation = null; private Adw.TimedAnimation? enlarge_animation = null;
private Adw.TimedAnimation? shrink_animation = null; private Adw.TimedAnimation? shrink_animation = null;
private Adw.AnimationTarget size_animation_target; private Adw.AnimationTarget size_animation_target;
construct { construct {
var gesture = new Gtk.GestureClick(); var motion_sensor = new Gtk.EventControllerMotion();
add_controller(gesture); 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"); add_css_class ("toolbar");
hexpand = true; hexpand = true;
@@ -40,20 +54,53 @@ namespace Song {
instanciate_signals(); instanciate_signals();
/*focus_event.enter.connect(() => {
} enlarge();
SongController.main_view.enter_yt_search_mode();
private void instanciate_signals() {
search_entry.changed.connect((e) => {
if (e.get_text() != null && state == YtSearchBarStates.NONE) {
if (e.get_text() != "" && !isEnlarged) {
enlarge();
} else if (e.get_text() == "" && isEnlarged) {
shrink();
}
}
}); });
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() { private void enlarge() {
@@ -62,8 +109,7 @@ namespace Song {
enlarge_animation.done.connect(() => { enlarge_animation.done.connect(() => {
isEnlarged = true; isEnlarged = true;
state = YtSearchBarStates.NONE; state = YtSearchBarStates.NONE;
print(state.to_string() + "\n");
print(isEnlarged.to_string() + "\n");
}); });
} }
@@ -77,8 +123,6 @@ namespace Song {
shrink_animation.done.connect(() => { shrink_animation.done.connect(() => {
isEnlarged = false; isEnlarged = false;
state = YtSearchBarStates.NONE; state = YtSearchBarStates.NONE;
print(state.to_string() + "\n");
print(isEnlarged.to_string() + "\n");
}); });
} }
@@ -86,4 +130,5 @@ namespace Song {
state = YtSearchBarStates.SHRINKING; state = YtSearchBarStates.SHRINKING;
} }
} }
} }
+7
View File
@@ -93,7 +93,14 @@ namespace Song {
set_content(_content); 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() { public void new_music_popover_show() {