mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-29 20:44:25 +00:00
replace GestureClick with StateFlags implementation
This commit is contained in:
parent
c8fb59988d
commit
6a04692ad3
@ -3,11 +3,10 @@ mod database;
|
|||||||
use database::Database;
|
use database::Database;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gdk::BUTTON_PRIMARY,
|
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
glib::{timeout_add_local, ControlFlow, GString, SourceId},
|
glib::{timeout_add_local, ControlFlow, GString, SourceId},
|
||||||
prelude::{ActionExt, EditableExt, EntryExt, ToVariant, WidgetExt},
|
prelude::{ActionExt, EditableExt, EntryExt, ToVariant, WidgetExt},
|
||||||
Entry, GestureClick,
|
Entry, StateFlags,
|
||||||
};
|
};
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
use std::{cell::RefCell, sync::Arc, time::Duration};
|
use std::{cell::RefCell, sync::Arc, time::Duration};
|
||||||
@ -40,20 +39,12 @@ impl Widget {
|
|||||||
source_id: RefCell::new(None),
|
source_id: RefCell::new(None),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Init additional controllers
|
|
||||||
let primary_button_controller = GestureClick::builder().button(BUTTON_PRIMARY).build();
|
|
||||||
|
|
||||||
// Init widget
|
// Init widget
|
||||||
let gobject = Entry::builder()
|
let gobject = Entry::builder()
|
||||||
.placeholder_text(PLACEHOLDER_TEXT)
|
.placeholder_text(PLACEHOLDER_TEXT)
|
||||||
.hexpand(true)
|
.hexpand(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
gobject
|
|
||||||
.first_child()
|
|
||||||
.unwrap() // text widget should be there
|
|
||||||
.add_controller(primary_button_controller.clone());
|
|
||||||
|
|
||||||
// Connect events
|
// Connect events
|
||||||
gobject.connect_changed(move |_| {
|
gobject.connect_changed(move |_| {
|
||||||
action_update.activate(Some(&"".to_variant())); // @TODO
|
action_update.activate(Some(&"".to_variant())); // @TODO
|
||||||
@ -63,20 +54,17 @@ impl Widget {
|
|||||||
action_page_reload.activate(None);
|
action_page_reload.activate(None);
|
||||||
});
|
});
|
||||||
|
|
||||||
primary_button_controller.connect_pressed({
|
gobject.connect_state_flags_changed(|this, state| {
|
||||||
let gobject = gobject.clone();
|
// Select entire text on key release
|
||||||
move |_, _, _, _| {
|
// this behavior implemented in most web-browsers,
|
||||||
let gobject = gobject.clone();
|
// to simply overwrite current request with new value
|
||||||
// Select entire text on first focus at entry
|
// Note:
|
||||||
// this behavior implemented in most web-browsers,
|
// * Custom GestureClick is not option here, as GTK Entry already has default one
|
||||||
// to simply overwrite current request with new value
|
println!("{:?}", state);
|
||||||
if !gobject.first_child().unwrap().has_focus() {
|
if state.contains(StateFlags::ACTIVE) && state.contains(StateFlags::FOCUS_WITHIN) {
|
||||||
// Small trick to overwrite default GTK behavior
|
// Continue on first focus event
|
||||||
// @TODO find another way to prevent defaults but with timeout
|
if this.selection_bounds().is_none() {
|
||||||
timeout_add_local(Duration::from_millis(100), move || {
|
this.select_region(0, this.text_length().into());
|
||||||
gobject.select_region(0, gobject.text_length().into());
|
|
||||||
ControlFlow::Break
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user