* policylist_view: GUI the user will interact with (orbtk Widget) will act on policy lists, that combines the policy data elements. * policydata_state: rust code with helper methods Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
280 lines
6.8 KiB
Rust
280 lines
6.8 KiB
Rust
use orbtk::prelude::*;
|
|
|
|
use crate::{
|
|
data::PolicyList,
|
|
keys::*,
|
|
policylist_state::{Action, PolicyListState},
|
|
};
|
|
|
|
type ListIndex = Option<usize>;
|
|
|
|
widget!(
|
|
/// Starter page that offers the dialog to enter an identifier of a policy.
|
|
/// This identifier is checked agains a map of valid policy codes.
|
|
PolicyListView<PolicyListState> {
|
|
policy_list: PolicyList,
|
|
policy_list_count: u32
|
|
}
|
|
);
|
|
|
|
impl Template for PolicyListView {
|
|
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
|
|
// all items of our policy lists
|
|
let items_widget = ItemsWidget::new()
|
|
.id(ID_POLICY_LIST_ITEMS_WIDGET)
|
|
.v_align("start")
|
|
.items_builder(move |ctx, index| {
|
|
let mut name = "".to_string();
|
|
let mut selected = false;
|
|
|
|
if let Some(policy_list) = ctx
|
|
.get_widget(id)
|
|
.get::<PolicyList>(PROP_POLICY_LIST)
|
|
.get(index)
|
|
{
|
|
name = policy_list.name.clone();
|
|
}
|
|
|
|
// plus button: open new policy
|
|
let helper_button = Button::new()
|
|
.min_height(48.0)
|
|
.class(CLASS_ITEM_BUTTON)
|
|
.attach(Grid::column(0))
|
|
.attach(Grid::row(0))
|
|
.attach(Grid::column_span(1))
|
|
.on_click(move |ctx, _| {
|
|
ctx.get_mut::<PolicyListState>(id)
|
|
.action(Action::OpenPolicyList(index));
|
|
true
|
|
})
|
|
.build(ctx);
|
|
|
|
let text_block = TextBlock::new()
|
|
.foreground(helper_button)
|
|
.margin((14.0, 0.0, 0.0, 0.0))
|
|
.v_align("center")
|
|
.attach(Grid::column(0))
|
|
.text(name)
|
|
.element("text-box")
|
|
.build(ctx);
|
|
|
|
let text_box = TextBox::new()
|
|
.margin((8.0, 0.0, 0.0, 0.0))
|
|
.visibility("collapsed")
|
|
.v_align("center")
|
|
.water_mark("Insert policy name...")
|
|
.attach(Grid::column(0))
|
|
.text(text_block)
|
|
.on_changed(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyListState>(id)
|
|
.action(Action::TextChanged(entity, index));
|
|
})
|
|
.on_activate(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyListState>(id)
|
|
.action(Action::RemoveFocus(entity));
|
|
})
|
|
.build(ctx);
|
|
|
|
Grid::new()
|
|
.height(48.0)
|
|
.columns(
|
|
Columns::new()
|
|
.add("*")
|
|
.add(8.0)
|
|
.add(32.0)
|
|
.add(4.0)
|
|
.add(32.0)
|
|
.add(8.0)
|
|
.build(),
|
|
)
|
|
.child(helper_button)
|
|
.child(text_box)
|
|
.child(text_block)
|
|
.child(
|
|
ToggleButton::new()
|
|
.selected(("focused", text_box))
|
|
.class(CLASS_ICON_ONLY)
|
|
.attach(Grid::column(2))
|
|
.min_size(32.0, 32.0)
|
|
.v_align("center")
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
Button::new()
|
|
// .selected(("focused", text_box))
|
|
.class(CLASS_ICON_ONLY)
|
|
.attach(Grid::column(2))
|
|
.min_size(32.0, 32.0)
|
|
.v_align("center")
|
|
// todo use remove from icons
|
|
// .icon(material_font_icons::DELETE_FONT_ICON)
|
|
.icon("")
|
|
.on_mouse_down(|_, _| true)
|
|
.on_click(move |ctx, _| {
|
|
ctx.get_mut::<PolicyListState>(id)
|
|
.action(Action::SetEntry(text_box));
|
|
true
|
|
})
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
Button::new()
|
|
.class("icon_only")
|
|
.attach(Grid::column(4))
|
|
.min_size(32.0, 32.0)
|
|
.v_align("center")
|
|
// todo use Tray icon for action remove
|
|
// .icon(material_font_icons::DELETE_FONT_ICON)
|
|
.icon("")
|
|
.on_mouse_down(|_, _| true)
|
|
.on_click(move |ctx, _| {
|
|
ctx.get_mut::<PolicyListState>(id)
|
|
.action(Action::RemoveEntry(index));
|
|
true
|
|
})
|
|
.build(ctx),
|
|
)
|
|
.build(ctx)
|
|
})
|
|
.policy_list_count(PROP_POLICY_LIST_COUNT, id)
|
|
.build(ctx);
|
|
|
|
// create new policy list element
|
|
let policy_list_text_box = TextBox::new()
|
|
.id(ID_POLICY_LIST_TEXT_BOX)
|
|
.attach(Grid::row(4))
|
|
.v_align("center")
|
|
.margin((4.0, 0.0, 0.0, 2.0))
|
|
.lost_focus_on_activation(false)
|
|
.on_activate(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyListState>(id)
|
|
.action(Action::NewEntry(entity));
|
|
})
|
|
.on_changed(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyListState>(id)
|
|
.action(Action::InputTextChanged(entity));
|
|
})
|
|
.build(ctx);
|
|
|
|
let scroll_viewer = ScrollViewer::new()
|
|
.scroll_viewer_mode(("disabled", "auto"))
|
|
.child(items_widget)
|
|
.build(ctx);
|
|
|
|
self.name("Policy Lists")
|
|
.policy_list(PolicyList::default())
|
|
.policy_list_count(0)
|
|
.child(
|
|
Grid::new()
|
|
.rows(
|
|
Rows::new()
|
|
.add(52.0)
|
|
.add(1.0)
|
|
.add("*")
|
|
.add(1.0)
|
|
.add(40.0)
|
|
.build(),
|
|
)
|
|
.columns(
|
|
Columns::new()
|
|
.add("*")
|
|
.add(4.0)
|
|
.add(36.0)
|
|
.build(),
|
|
)
|
|
// Content
|
|
.child(
|
|
Container::new()
|
|
.attach(Grid::row(2))
|
|
.attach(Grid::column(0))
|
|
.attach(Grid::column_span(3))
|
|
.child(scroll_viewer)
|
|
.child(
|
|
ScrollIndicator::new()
|
|
.padding((0.0, 4.0, 0.0, 0.0))
|
|
.content_id(items_widget.0)
|
|
.scroll_offset(scroll_viewer)
|
|
.build(ctx),
|
|
)
|
|
.build(ctx),
|
|
)
|
|
// Top Bar
|
|
.child(
|
|
Container::new()
|
|
.class(CLASS_TOP_BAR)
|
|
.attach(Grid::row(0))
|
|
.attach(Grid::column(0))
|
|
.attach(Grid::column_span(3))
|
|
.child(
|
|
Grid::new()
|
|
.child(
|
|
TextBlock::new()
|
|
.class(CLASS_HEADER)
|
|
.v_align("center")
|
|
.h_align("center")
|
|
.text("Lists with policy data collections")
|
|
.build(ctx),
|
|
)
|
|
.build(ctx),
|
|
)
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
Container::new()
|
|
.class("separator")
|
|
.attach(Grid::row(1))
|
|
.attach(Grid::column_span(3))
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
Container::new()
|
|
.class("separator")
|
|
.attach(Grid::row(3))
|
|
.attach(Grid::column_span(3))
|
|
.build(ctx),
|
|
)
|
|
// Bottom bar
|
|
.child(
|
|
Container::new()
|
|
.class(CLASS_BOTTOM_BAR)
|
|
.attach(Grid::row(4))
|
|
.attach(Grid::column(0))
|
|
.attach(Grid::column_span(3))
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
// workaround, todo fix scroll viewer mouse behavior in OrbTk
|
|
Button::new()
|
|
.attach(Grid::row(4))
|
|
.attach(Grid::column(0))
|
|
.attach(Grid::column_span(3))
|
|
.on_mouse_down(|_, _| true)
|
|
.on_mouse_up(|_, _| true)
|
|
.on_click(|_, _| true)
|
|
.class(CLASS_TRANSPARENT)
|
|
.build(ctx),
|
|
)
|
|
.child(policy_list_text_box)
|
|
.child(
|
|
Button::new()
|
|
.id(ID_POLICY_LIST_ADD_BUTTON)
|
|
.class(CLASS_ICON_ONLY)
|
|
.attach(Grid::row(4))
|
|
.attach(Grid::column(2))
|
|
.margin((0.0, 0.0, 4.0, 0.0))
|
|
.enabled(false)
|
|
.min_size(32.0, 32.0)
|
|
.v_align("center")
|
|
.icon(material_font_icons::ADD_FONT_ICON)
|
|
.on_click(move |ctx, _| {
|
|
ctx.get_mut::<PolicyListState>(id)
|
|
.action(Action::NewEntry(policy_list_text_box));
|
|
true
|
|
})
|
|
.build(ctx),
|
|
)
|
|
.build(ctx),
|
|
)
|
|
}
|
|
}
|