mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-12 05:31:06 +00:00
draft multiline input
This commit is contained in:
parent
d1c8afd83f
commit
1972438da6
@ -272,32 +272,27 @@ impl Page {
|
|||||||
Some(code) => match code.as_str() {
|
Some(code) => match code.as_str() {
|
||||||
// Input expected
|
// Input expected
|
||||||
"10" => {
|
"10" => {
|
||||||
match parts.get(4) {
|
match parts.get(3) {
|
||||||
Some(placeholder) => {
|
Some(placeholder) => {
|
||||||
// Format response
|
// Format response
|
||||||
meta.borrow_mut().status = Some(Status::Input);
|
let status = Status::Input;
|
||||||
meta.borrow_mut().description = None; // @TODO
|
let title = gformat!("Input expected");
|
||||||
meta.borrow_mut().title = Some(gformat!("Input expected"));
|
let description = gformat!("{placeholder}");
|
||||||
|
|
||||||
input.show(&placeholder, false);
|
// Show input request
|
||||||
|
input.show(Some(&description));
|
||||||
|
|
||||||
|
// Update meta
|
||||||
|
meta.borrow_mut().status = Some(status);
|
||||||
|
meta.borrow_mut().description = Some(description);
|
||||||
|
meta.borrow_mut().title = Some(title);
|
||||||
},
|
},
|
||||||
None => todo!(),
|
None => todo!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
// Sensitive input expected
|
// Sensitive input expected
|
||||||
"11" => {
|
"11" => {
|
||||||
match parts.get(4) {
|
todo!()
|
||||||
Some(placeholder) => {
|
|
||||||
// Format response
|
|
||||||
meta.borrow_mut().status = Some(Status::SensitiveInput);
|
|
||||||
meta.borrow_mut().description = None; // @TODO
|
|
||||||
meta.borrow_mut().title = Some(gformat!("Input expected"));
|
|
||||||
|
|
||||||
input.show(&placeholder, true);
|
|
||||||
},
|
|
||||||
None => todo!(),
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
// Success
|
// Success
|
||||||
"20" => {
|
"20" => {
|
||||||
|
@ -26,8 +26,8 @@ impl Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn show(&self, placeholder: &str, sensitive: bool) {
|
pub fn show(&self, title: Option<&str>) {
|
||||||
self.content.set(placeholder, sensitive);
|
self.content.set(title);
|
||||||
self.widget.show(true);
|
self.widget.show(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
mod response;
|
mod response;
|
||||||
mod send;
|
mod send;
|
||||||
|
mod title;
|
||||||
mod widget;
|
mod widget;
|
||||||
|
|
||||||
use response::Response;
|
use response::Response;
|
||||||
use send::Send;
|
use send::Send;
|
||||||
|
use title::Title;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use gtk::Box;
|
use gtk::Box;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Content {
|
pub struct Content {
|
||||||
|
title: Arc<Title>,
|
||||||
response: Arc<Response>,
|
response: Arc<Response>,
|
||||||
widget: Arc<Widget>,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
@ -18,11 +21,12 @@ impl Content {
|
|||||||
// Construct
|
// Construct
|
||||||
pub fn new_arc() -> Arc<Self> {
|
pub fn new_arc() -> Arc<Self> {
|
||||||
// Init components
|
// Init components
|
||||||
|
let title = Title::new_arc();
|
||||||
let response = Response::new_arc();
|
let response = Response::new_arc();
|
||||||
let send = Send::new_arc();
|
let send = Send::new_arc();
|
||||||
|
|
||||||
// Init widget
|
// Init widget
|
||||||
let widget = Widget::new_arc(response.gobject(), send.gobject());
|
let widget = Widget::new_arc(title.gobject(), response.gobject(), send.gobject());
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
/* @TODO
|
/* @TODO
|
||||||
@ -30,12 +34,17 @@ impl Content {
|
|||||||
send.gobject().connect_clicked(|_| {}); */
|
send.gobject().connect_clicked(|_| {}); */
|
||||||
|
|
||||||
// Return activated struct
|
// Return activated struct
|
||||||
Arc::new(Self { response, widget })
|
Arc::new(Self {
|
||||||
|
title,
|
||||||
|
response,
|
||||||
|
widget,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn set(&self, placeholder: &str, sensitive: bool) {
|
pub fn set(&self, title: Option<&str>) {
|
||||||
self.response.set(placeholder, sensitive);
|
self.title.set(title);
|
||||||
|
self.response.grab_focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
@ -2,7 +2,7 @@ mod widget;
|
|||||||
|
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use gtk::Entry;
|
use gtk::TextView;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
@ -20,12 +20,12 @@ impl Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn set(&self, placeholder: &str, sensitive: bool) {
|
pub fn grab_focus(&self) {
|
||||||
self.widget.set(placeholder, sensitive);
|
self.widget.grab_focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn gobject(&self) -> &Entry {
|
pub fn gobject(&self) -> &TextView {
|
||||||
&self.widget.gobject()
|
&self.widget.gobject()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,30 @@
|
|||||||
use gtk::{
|
use gtk::{prelude::WidgetExt, TextView};
|
||||||
prelude::{EditableExt, EntryExt, WidgetExt},
|
|
||||||
Entry,
|
|
||||||
};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Widget {
|
pub struct Widget {
|
||||||
gobject: Entry,
|
gobject: TextView,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new_arc() -> Arc<Self> {
|
pub fn new_arc() -> Arc<Self> {
|
||||||
let gobject = Entry::builder().editable(true).hexpand(true).build();
|
let gobject = TextView::builder()
|
||||||
|
.left_margin(8)
|
||||||
|
.pixels_above_lines(8)
|
||||||
|
.pixels_below_lines(8)
|
||||||
|
.right_margin(8)
|
||||||
|
.build();
|
||||||
|
|
||||||
Arc::new(Self { gobject })
|
Arc::new(Self { gobject })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn set(&self, placeholder_text: &str, sensitive: bool) {
|
pub fn grab_focus(&self) {
|
||||||
self.gobject.set_text(&""); // reset
|
|
||||||
self.gobject.set_placeholder_text(Some(placeholder_text));
|
|
||||||
// self.gobject.set_sensitive(sensitive);
|
|
||||||
self.gobject.grab_focus();
|
self.gobject.grab_focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn gobject(&self) -> &Entry {
|
pub fn gobject(&self) -> &TextView {
|
||||||
&self.gobject
|
&self.gobject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
src/app/browser/window/tab/item/page/input/content/title.rs
Normal file
31
src/app/browser/window/tab/item/page/input/content/title.rs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
mod widget;
|
||||||
|
|
||||||
|
use widget::Widget;
|
||||||
|
|
||||||
|
use gtk::Label;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub struct Title {
|
||||||
|
widget: Arc<Widget>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Title {
|
||||||
|
// Construct
|
||||||
|
pub fn new_arc() -> Arc<Self> {
|
||||||
|
// Init widget
|
||||||
|
let widget = Widget::new_arc();
|
||||||
|
|
||||||
|
// Result
|
||||||
|
Arc::new(Self { widget })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
pub fn set(&self, text: Option<&str>) {
|
||||||
|
self.widget.set(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
pub fn gobject(&self) -> &Label {
|
||||||
|
&self.widget.gobject()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
use gtk::{prelude::WidgetExt, Align, Label};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub struct Widget {
|
||||||
|
gobject: Label,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Widget {
|
||||||
|
// Construct
|
||||||
|
pub fn new_arc() -> Arc<Self> {
|
||||||
|
let gobject = Label::builder()
|
||||||
|
.halign(Align::Start)
|
||||||
|
.margin_end(8)
|
||||||
|
.margin_start(8)
|
||||||
|
.visible(false)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Arc::new(Self { gobject })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
pub fn set(&self, text: Option<&str>) {
|
||||||
|
match text {
|
||||||
|
Some(value) => {
|
||||||
|
self.gobject.set_label(value);
|
||||||
|
self.gobject.set_visible(!value.is_empty());
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
self.gobject.set_visible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
pub fn gobject(&self) -> &Label {
|
||||||
|
&self.gobject
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
use gtk::{prelude::BoxExt, Box, Button, Entry, Orientation};
|
use gtk::{prelude::BoxExt, Box, Button, Label, Orientation, TextView};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
const MARGIN: i32 = 6;
|
const MARGIN: i32 = 6;
|
||||||
@ -10,16 +10,17 @@ pub struct Widget {
|
|||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new_arc(response: &Entry, send: &Button) -> Arc<Self> {
|
pub fn new_arc(title: &Label, response: &TextView, send: &Button) -> Arc<Self> {
|
||||||
let gobject = Box::builder()
|
let gobject = Box::builder()
|
||||||
.margin_bottom(MARGIN)
|
.margin_bottom(MARGIN)
|
||||||
.margin_end(MARGIN)
|
.margin_end(MARGIN)
|
||||||
.margin_start(MARGIN)
|
.margin_start(MARGIN)
|
||||||
.margin_top(MARGIN)
|
.margin_top(MARGIN)
|
||||||
.spacing(SPACING)
|
.spacing(SPACING)
|
||||||
.orientation(Orientation::Horizontal)
|
.orientation(Orientation::Vertical)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
gobject.append(title);
|
||||||
gobject.append(response);
|
gobject.append(response);
|
||||||
gobject.append(send);
|
gobject.append(send);
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ pub enum Status {
|
|||||||
Reload,
|
Reload,
|
||||||
Request,
|
Request,
|
||||||
Response,
|
Response,
|
||||||
SensitiveInput,
|
// @TODO SensitiveInput,
|
||||||
Success,
|
Success,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user