Browse Source

draft multiline input

master
yggverse 1 month ago
parent
commit
1972438da6
  1. 29
      src/app/browser/window/tab/item/page.rs
  2. 4
      src/app/browser/window/tab/item/page/input.rs
  3. 17
      src/app/browser/window/tab/item/page/input/content.rs
  4. 8
      src/app/browser/window/tab/item/page/input/content/response.rs
  5. 21
      src/app/browser/window/tab/item/page/input/content/response/widget.rs
  6. 31
      src/app/browser/window/tab/item/page/input/content/title.rs
  7. 38
      src/app/browser/window/tab/item/page/input/content/title/widget.rs
  8. 7
      src/app/browser/window/tab/item/page/input/content/widget.rs
  9. 2
      src/app/browser/window/tab/item/page/meta.rs

29
src/app/browser/window/tab/item/page.rs

@ -272,32 +272,27 @@ impl Page { @@ -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}");
// Show input request
input.show(Some(&description));
input.show(&placeholder, false);
// 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" => {

4
src/app/browser/window/tab/item/page/input.rs

@ -26,8 +26,8 @@ impl Input { @@ -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);
}

17
src/app/browser/window/tab/item/page/input/content.rs

@ -1,15 +1,18 @@ @@ -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 { @@ -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 { @@ -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

8
src/app/browser/window/tab/item/page/input/content/response.rs

@ -2,7 +2,7 @@ mod widget; @@ -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 { @@ -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()
}
}

21
src/app/browser/window/tab/item/page/input/content/response/widget.rs

@ -1,31 +1,30 @@ @@ -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
}
}

31
src/app/browser/window/tab/item/page/input/content/title.rs

@ -0,0 +1,31 @@ @@ -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()
}
}

38
src/app/browser/window/tab/item/page/input/content/title/widget.rs

@ -0,0 +1,38 @@ @@ -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
}
}

7
src/app/browser/window/tab/item/page/input/content/widget.rs

@ -1,4 +1,4 @@ @@ -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 { @@ -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);

2
src/app/browser/window/tab/item/page/meta.rs

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

Loading…
Cancel
Save