mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-30 13:04:13 +00:00
draft find widget
This commit is contained in:
parent
02df33428e
commit
db44fff212
@ -1,21 +1,33 @@
|
|||||||
|
mod find;
|
||||||
|
|
||||||
|
use find::Find;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
prelude::WidgetExt, EventControllerMotion, GestureClick, TextBuffer, TextView, WrapMode,
|
prelude::{TextViewExt, WidgetExt},
|
||||||
|
EventControllerMotion, GestureClick, TextBuffer, TextView, TextWindowType, WrapMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MARGIN: i32 = 8;
|
const MARGIN: i32 = 8;
|
||||||
|
|
||||||
pub struct Widget {
|
pub struct Widget {
|
||||||
|
find: Find,
|
||||||
pub text_view: TextView,
|
pub text_view: TextView,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Constructors
|
||||||
|
|
||||||
|
/// Create new `Self`
|
||||||
pub fn new(
|
pub fn new(
|
||||||
buffer: &TextBuffer,
|
buffer: &TextBuffer,
|
||||||
primary_button_controller: GestureClick,
|
primary_button_controller: GestureClick,
|
||||||
middle_button_controller: GestureClick,
|
middle_button_controller: GestureClick,
|
||||||
motion_controller: EventControllerMotion,
|
motion_controller: EventControllerMotion,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
// Init components
|
||||||
|
let find = Find::new();
|
||||||
|
|
||||||
|
// Init main widget
|
||||||
let text_view = TextView::builder()
|
let text_view = TextView::builder()
|
||||||
.bottom_margin(MARGIN)
|
.bottom_margin(MARGIN)
|
||||||
.buffer(buffer)
|
.buffer(buffer)
|
||||||
@ -32,6 +44,20 @@ impl Widget {
|
|||||||
text_view.add_controller(middle_button_controller);
|
text_view.add_controller(middle_button_controller);
|
||||||
text_view.add_controller(motion_controller);
|
text_view.add_controller(motion_controller);
|
||||||
|
|
||||||
Self { text_view }
|
// Done
|
||||||
|
Self { find, text_view }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
|
pub fn find(&self, is_visible: bool) {
|
||||||
|
if is_visible {
|
||||||
|
self.text_view
|
||||||
|
.set_gutter(TextWindowType::Bottom, Some(&self.find.g_box));
|
||||||
|
self.find.g_box.grab_focus();
|
||||||
|
} else {
|
||||||
|
self.text_view
|
||||||
|
.set_gutter(TextWindowType::Bottom, gtk::Widget::NONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
use gtk::{
|
||||||
|
gdk::Cursor,
|
||||||
|
prelude::{BoxExt, EditableExt, EntryExt},
|
||||||
|
Box, Button, Entry, EntryIconPosition, Orientation,
|
||||||
|
};
|
||||||
|
|
||||||
|
const MARGIN: i32 = 6;
|
||||||
|
|
||||||
|
pub struct Find {
|
||||||
|
pub g_box: Box,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Find {
|
||||||
|
// Construct
|
||||||
|
pub fn new() -> Self {
|
||||||
|
// Init components
|
||||||
|
let close = Button::builder()
|
||||||
|
.cursor(&Cursor::from_name("default", None).unwrap())
|
||||||
|
.icon_name("window-close-symbolic")
|
||||||
|
.margin_bottom(MARGIN)
|
||||||
|
.margin_end(MARGIN)
|
||||||
|
.margin_top(MARGIN)
|
||||||
|
.tooltip_text("Close find bar")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let entry = Entry::builder()
|
||||||
|
.hexpand(true)
|
||||||
|
.margin_bottom(MARGIN)
|
||||||
|
.margin_end(MARGIN)
|
||||||
|
.margin_start(MARGIN)
|
||||||
|
.margin_top(MARGIN)
|
||||||
|
.placeholder_text("Find in text..")
|
||||||
|
.primary_icon_activatable(false)
|
||||||
|
.primary_icon_name("system-search-symbolic")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// Init main container
|
||||||
|
let g_box = Box::builder().orientation(Orientation::Horizontal).build();
|
||||||
|
|
||||||
|
g_box.append(&entry);
|
||||||
|
g_box.append(&close);
|
||||||
|
|
||||||
|
// Connect events
|
||||||
|
entry.connect_activate(|_| {}); // @TODO
|
||||||
|
|
||||||
|
entry.connect_changed(move |this| {
|
||||||
|
if this.text().is_empty() {
|
||||||
|
this.set_secondary_icon_name(None);
|
||||||
|
} else {
|
||||||
|
this.set_secondary_icon_name(Some("edit-clear-symbolic"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
entry.connect_icon_release(move |this, position| match position {
|
||||||
|
EntryIconPosition::Secondary => this.delete_text(0, -1),
|
||||||
|
_ => todo!(), // unexpected
|
||||||
|
});
|
||||||
|
|
||||||
|
// Done
|
||||||
|
Self { g_box }
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user