mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
implement append button as trait
This commit is contained in:
parent
680bf0f0aa
commit
81cea44302
3 changed files with 19 additions and 44 deletions
|
|
@ -3,6 +3,7 @@ mod append;
|
||||||
use super::WindowAction;
|
use super::WindowAction;
|
||||||
use adw::{TabBar, TabView};
|
use adw::{TabBar, TabView};
|
||||||
use append::Append;
|
use append::Append;
|
||||||
|
use gtk::Button;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub trait Tab {
|
pub trait Tab {
|
||||||
|
|
@ -14,7 +15,7 @@ impl Tab for TabBar {
|
||||||
TabBar::builder()
|
TabBar::builder()
|
||||||
.autohide(false)
|
.autohide(false)
|
||||||
.expand_tabs(false)
|
.expand_tabs(false)
|
||||||
.end_action_widget(&Append::build(window_action).widget.button) // @TODO find solution to append after tabs
|
.end_action_widget(&Button::append(window_action)) // @TODO find solution to append after tabs
|
||||||
.view(view)
|
.view(view)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,25 @@
|
||||||
mod widget;
|
|
||||||
|
|
||||||
use widget::Widget;
|
|
||||||
|
|
||||||
use super::WindowAction;
|
use super::WindowAction;
|
||||||
|
use gtk::{prelude::ButtonExt, Align, Button};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub struct Append {
|
pub trait Append {
|
||||||
pub widget: Rc<Widget>,
|
fn append(window_action: &Rc<WindowAction>) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Append {
|
impl Append for Button {
|
||||||
// Constructors
|
fn append(window_action: &Rc<WindowAction>) -> Self {
|
||||||
|
let button = Button::builder()
|
||||||
|
.icon_name("tab-new-symbolic")
|
||||||
|
.css_classes(["flat"])
|
||||||
|
.valign(Align::Center)
|
||||||
|
.tooltip_text("New tab")
|
||||||
|
.build();
|
||||||
|
|
||||||
/// Build new `Self`
|
button.connect_clicked({
|
||||||
pub fn build(window_action: &Rc<WindowAction>) -> Self {
|
let window_action = window_action.clone();
|
||||||
Self {
|
move |_| window_action.append.activate_default_once()
|
||||||
widget: Rc::new(Widget::build(window_action)),
|
});
|
||||||
}
|
|
||||||
|
button
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
use super::WindowAction;
|
|
||||||
use gtk::{prelude::ButtonExt, Align, Button};
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
pub struct Widget {
|
|
||||||
pub button: Button,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Widget {
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
/// Build new `Self`
|
|
||||||
pub fn build(window_action: &Rc<WindowAction>) -> Self {
|
|
||||||
// Init gobject
|
|
||||||
let button = Button::builder()
|
|
||||||
.icon_name("tab-new-symbolic")
|
|
||||||
.css_classes(["flat"])
|
|
||||||
.valign(Align::Center)
|
|
||||||
.tooltip_text("New tab")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// Init events
|
|
||||||
button.connect_clicked({
|
|
||||||
let window_action = window_action.clone();
|
|
||||||
move |_| window_action.append.activate_default_once()
|
|
||||||
});
|
|
||||||
|
|
||||||
Self { button }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue