mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-05 07:54:14 +00:00
draft limit notification badge
This commit is contained in:
parent
edef963287
commit
88aeab91be
@ -280,7 +280,7 @@ impl Page {
|
||||
let description = gformat!("{placeholder}");
|
||||
|
||||
// Show input request
|
||||
input.show(Some(&description));
|
||||
input.show(Some(&description), Some(&1024));
|
||||
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(status);
|
||||
|
@ -26,8 +26,8 @@ impl Input {
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn show(&self, title: Option<&str>) {
|
||||
self.content.set(title);
|
||||
pub fn show(&self, title: Option<&str>, limit: Option<&i32>) {
|
||||
self.content.update(title, limit);
|
||||
self.widget.show(true);
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
mod control;
|
||||
mod response;
|
||||
mod send;
|
||||
mod title;
|
||||
mod widget;
|
||||
|
||||
use control::Control;
|
||||
use response::Response;
|
||||
use send::Send;
|
||||
use title::Title;
|
||||
use widget::Widget;
|
||||
|
||||
@ -12,8 +12,9 @@ use gtk::Box;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Content {
|
||||
title: Arc<Title>,
|
||||
control: Arc<Control>,
|
||||
response: Arc<Response>,
|
||||
title: Arc<Title>,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
@ -21,29 +22,26 @@ impl Content {
|
||||
// Construct
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
// Init components
|
||||
let title = Title::new_arc();
|
||||
let control = Control::new_arc();
|
||||
let response = Response::new_arc();
|
||||
let send = Send::new_arc();
|
||||
let title = Title::new_arc();
|
||||
|
||||
// Init widget
|
||||
let widget = Widget::new_arc(title.gobject(), response.gobject(), send.gobject());
|
||||
|
||||
// Init events
|
||||
/* @TODO
|
||||
response.gobject().connect_activate(|_| {});
|
||||
send.gobject().connect_clicked(|_| {}); */
|
||||
let widget = Widget::new_arc(title.gobject(), response.gobject(), control.gobject());
|
||||
|
||||
// Return activated struct
|
||||
Arc::new(Self {
|
||||
title,
|
||||
control,
|
||||
response,
|
||||
title,
|
||||
widget,
|
||||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn set(&self, title: Option<&str>) {
|
||||
self.title.set(title);
|
||||
pub fn update(&self, title: Option<&str>, count_limit: Option<&i32>) {
|
||||
self.control.update(&0, count_limit); // @TODO
|
||||
self.title.update(title);
|
||||
self.response.grab_focus();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
mod limit;
|
||||
mod send;
|
||||
mod widget;
|
||||
|
||||
use limit::Limit;
|
||||
use send::Send;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::Box;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Control {
|
||||
limit: Arc<Limit>,
|
||||
send: Arc<Send>,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Control {
|
||||
// Construct
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
// Init components
|
||||
let limit = Limit::new_arc();
|
||||
let send = Send::new_arc();
|
||||
|
||||
// Init widget
|
||||
let widget = Widget::new_arc(limit.gobject(), send.gobject());
|
||||
|
||||
// Return activated struct
|
||||
Arc::new(Self {
|
||||
limit,
|
||||
send,
|
||||
widget,
|
||||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, count: &i32, count_limit: Option<&i32>) {
|
||||
self.limit.update(count, count_limit);
|
||||
// @TODO self.send.update(limit);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Box {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::Label;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Limit {
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Limit {
|
||||
// Construct
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
// Init widget
|
||||
let widget = Widget::new_arc();
|
||||
|
||||
// Result
|
||||
Arc::new(Self { widget })
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, count: &i32, limit: Option<&i32>) {
|
||||
self.widget.update(count, limit);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Label {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
use gtk::{prelude::WidgetExt, Label};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Label,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
let gobject = Label::builder().use_markup(true).build();
|
||||
|
||||
Arc::new(Self { gobject })
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, count: &i32, count_limit: Option<&i32>) {
|
||||
match count_limit {
|
||||
Some(limit) => {
|
||||
// Update color on limit reached
|
||||
self.gobject
|
||||
.set_css_classes(&[if count < limit { "success" } else { "error" }]); // @TODO add warning step?
|
||||
|
||||
// Update text
|
||||
self.gobject
|
||||
.set_markup(&format!("{count} <sup>/ {limit}</sup>"));
|
||||
|
||||
// Toggle visibility if limit provided
|
||||
self.gobject.set_visible(true);
|
||||
}
|
||||
None => self.gobject.set_visible(false),
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Label {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
use gtk::{Align, Button};
|
||||
use gtk::Button;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
@ -10,7 +10,6 @@ impl Widget {
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
let gobject = Button::builder()
|
||||
//.css_classes(["accent"])
|
||||
.halign(Align::End)
|
||||
.label("Send")
|
||||
.build();
|
||||
|
@ -0,0 +1,29 @@
|
||||
use gtk::{prelude::BoxExt, Align, Box, Button, Label, Orientation};
|
||||
use std::sync::Arc;
|
||||
|
||||
const SPACING: i32 = 8;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Box,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc(limit: &Label, send: &Button) -> Arc<Self> {
|
||||
let gobject = Box::builder()
|
||||
.halign(Align::End)
|
||||
.orientation(Orientation::Horizontal)
|
||||
.spacing(SPACING)
|
||||
.build();
|
||||
|
||||
gobject.append(limit);
|
||||
gobject.append(send);
|
||||
|
||||
Arc::new(Self { gobject })
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Box {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
@ -20,8 +20,8 @@ impl Title {
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn set(&self, text: Option<&str>) {
|
||||
self.widget.set(text);
|
||||
pub fn update(&self, text: Option<&str>) {
|
||||
self.widget.update(text);
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
@ -20,7 +20,7 @@ impl Widget {
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn set(&self, text: Option<&str>) {
|
||||
pub fn update(&self, text: Option<&str>) {
|
||||
match text {
|
||||
Some(value) => {
|
||||
self.gobject.set_label(value);
|
||||
|
@ -1,4 +1,4 @@
|
||||
use gtk::{prelude::BoxExt, Box, Button, Label, Orientation, TextView};
|
||||
use gtk::{prelude::BoxExt, Box, Label, Orientation, TextView};
|
||||
use std::sync::Arc;
|
||||
|
||||
const MARGIN: i32 = 6;
|
||||
@ -10,7 +10,7 @@ pub struct Widget {
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc(title: &Label, response: &TextView, send: &Button) -> Arc<Self> {
|
||||
pub fn new_arc(title: &Label, response: &TextView, control: &Box) -> Arc<Self> {
|
||||
let gobject = Box::builder()
|
||||
.margin_bottom(MARGIN)
|
||||
.margin_end(MARGIN)
|
||||
@ -22,7 +22,7 @@ impl Widget {
|
||||
|
||||
gobject.append(title);
|
||||
gobject.append(response);
|
||||
gobject.append(send);
|
||||
gobject.append(control);
|
||||
|
||||
Arc::new(Self { gobject })
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user