mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55: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 adw::{TabBar, TabView};
|
||||
use append::Append;
|
||||
use gtk::Button;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub trait Tab {
|
||||
|
|
@ -14,7 +15,7 @@ impl Tab for TabBar {
|
|||
TabBar::builder()
|
||||
.autohide(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)
|
||||
.build()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,25 @@
|
|||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use super::WindowAction;
|
||||
use gtk::{prelude::ButtonExt, Align, Button};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Append {
|
||||
pub widget: Rc<Widget>,
|
||||
pub trait Append {
|
||||
fn append(window_action: &Rc<WindowAction>) -> Self;
|
||||
}
|
||||
|
||||
impl Append {
|
||||
// Constructors
|
||||
impl Append for Button {
|
||||
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`
|
||||
pub fn build(window_action: &Rc<WindowAction>) -> Self {
|
||||
Self {
|
||||
widget: Rc::new(Widget::build(window_action)),
|
||||
}
|
||||
button.connect_clicked({
|
||||
let window_action = window_action.clone();
|
||||
move |_| window_action.append.activate_default_once()
|
||||
});
|
||||
|
||||
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