draft multiline input

This commit is contained in:
yggverse 2024-10-16 10:15:13 +03:00
parent d1c8afd83f
commit 1972438da6
9 changed files with 115 additions and 42 deletions

View File

@ -272,32 +272,27 @@ impl Page {
Some(code) => match code.as_str() {
// Input expected
"10" => {
match parts.get(4) {
match parts.get(3) {
Some(placeholder) => {
// Format response
meta.borrow_mut().status = Some(Status::Input);
meta.borrow_mut().description = None; // @TODO
meta.borrow_mut().title = Some(gformat!("Input expected"));
let status = Status::Input;
let title = 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!(),
}
},
// Sensitive input expected
"11" => {
match parts.get(4) {
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!(),
}
todo!()
},
// Success
"20" => {

View File

@ -26,8 +26,8 @@ impl Input {
}
// Actions
pub fn show(&self, placeholder: &str, sensitive: bool) {
self.content.set(placeholder, sensitive);
pub fn show(&self, title: Option<&str>) {
self.content.set(title);
self.widget.show(true);
}

View File

@ -1,15 +1,18 @@
mod response;
mod send;
mod title;
mod widget;
use response::Response;
use send::Send;
use title::Title;
use widget::Widget;
use gtk::Box;
use std::sync::Arc;
pub struct Content {
title: Arc<Title>,
response: Arc<Response>,
widget: Arc<Widget>,
}
@ -18,11 +21,12 @@ impl Content {
// Construct
pub fn new_arc() -> Arc<Self> {
// Init components
let title = Title::new_arc();
let response = Response::new_arc();
let send = Send::new_arc();
// Init widget
let widget = Widget::new_arc(response.gobject(), send.gobject());
let widget = Widget::new_arc(title.gobject(), response.gobject(), send.gobject());
// Init events
/* @TODO
@ -30,12 +34,17 @@ impl Content {
send.gobject().connect_clicked(|_| {}); */
// Return activated struct
Arc::new(Self { response, widget })
Arc::new(Self {
title,
response,
widget,
})
}
// Actions
pub fn set(&self, placeholder: &str, sensitive: bool) {
self.response.set(placeholder, sensitive);
pub fn set(&self, title: Option<&str>) {
self.title.set(title);
self.response.grab_focus();
}
// Getters

View File

@ -2,7 +2,7 @@ mod widget;
use widget::Widget;
use gtk::Entry;
use gtk::TextView;
use std::sync::Arc;
pub struct Response {
@ -20,12 +20,12 @@ impl Response {
}
// Actions
pub fn set(&self, placeholder: &str, sensitive: bool) {
self.widget.set(placeholder, sensitive);
pub fn grab_focus(&self) {
self.widget.grab_focus();
}
// Getters
pub fn gobject(&self) -> &Entry {
pub fn gobject(&self) -> &TextView {
&self.widget.gobject()
}
}

View File

@ -1,31 +1,30 @@
use gtk::{
prelude::{EditableExt, EntryExt, WidgetExt},
Entry,
};
use gtk::{prelude::WidgetExt, TextView};
use std::sync::Arc;
pub struct Widget {
gobject: Entry,
gobject: TextView,
}
impl Widget {
// Construct
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 })
}
// Actions
pub fn set(&self, placeholder_text: &str, sensitive: bool) {
self.gobject.set_text(&""); // reset
self.gobject.set_placeholder_text(Some(placeholder_text));
// self.gobject.set_sensitive(sensitive);
pub fn grab_focus(&self) {
self.gobject.grab_focus();
}
// Getters
pub fn gobject(&self) -> &Entry {
pub fn gobject(&self) -> &TextView {
&self.gobject
}
}

View 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()
}
}

View File

@ -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
}
}

View File

@ -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;
const MARGIN: i32 = 6;
@ -10,16 +10,17 @@ pub struct Widget {
impl Widget {
// 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()
.margin_bottom(MARGIN)
.margin_end(MARGIN)
.margin_start(MARGIN)
.margin_top(MARGIN)
.spacing(SPACING)
.orientation(Orientation::Horizontal)
.orientation(Orientation::Vertical)
.build();
gobject.append(title);
gobject.append(response);
gobject.append(send);

View File

@ -18,7 +18,7 @@ pub enum Status {
Reload,
Request,
Response,
SensitiveInput,
// @TODO SensitiveInput,
Success,
}