Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guus/UI table2 #1118

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmake/rust/union_Cargo.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
name = "${CARGO_CRATE_NAME}"
version = "${CARGO_CRATE_VERSION}"
edition = "2021"


[features]
tracy = []

[dependencies]
${CARGO_CRATE_DEPS}

Expand Down
36 changes: 19 additions & 17 deletions docs/samples/shards/UI/Table/1.shs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@ GFX.MainWindow(
UI(
UI.CentralPanel(
Contents: {
[
{Name: "Doe" Surname: "John"}
[{Name: "Doe" Surname: "John"}
{Name: "Dough" Surname: "Jane"}
{Name: "Smith" Surname: "Dick"}] | UI.Table(
{Name: "Smith" Surname: "Dick"}] = seq
Count(seq) | UI.Table(
Resizable: true
Striped: true
RowIndex: index
Columns: [
{Initial: 20.0}
{
Header: "Surname"
Initial: 100.0
AtLeast: 60.0
AtMost: 160.0
UI.TableHeader({
"Index" | UI.Label
} WidthType: "exact" Width: 20.0)
ToString | UI.Label
}
{
Header: "Name"
Initial: 80.0
AtLeast: 60.0
AtMost: 160.0
UI.TableHeader({
"Surname" | UI.Label
} WidthType: "initial" Width: 100.0 MinWidth: 60.0 MaxWidth: 160.0)
= i
seq | Take(i) | Take("Surname") | UI.Label
}
{
UI.TableHeader({
"Name" | UI.Label
} WidthType: "initial" Width: 80.0 MinWidth: 60.0 MaxWidth: 160.0)
= i
seq | Take(i) | Take("Name") | UI.Label
}]
Builder: [
{index | ToString | UI.Label}
{Take("Surname") | UI.Label}
{Take("Name") | UI.Label}]
)
}
)
Expand Down
36 changes: 25 additions & 11 deletions docs/samples/shards/UI/Table/2.shs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,33 @@ GFX.MainWindow(
UI(
UI.CentralPanel(
Contents: {
[
@i2(0) @i2(0 1) @i2(1) @i2(1 0)] | UI.Table(
[@i2(0) @i2(0 1) @i2(1) @i2(1 0)] = data
Count(data) | UI.Table(
Columns: [
{Header: "A"}
{Header: "B"}
{Header: "A xor B"}]
Builder: [
{Take(0) | ToString | UI.Label}
{Take(1) | ToString | UI.Label}
{
{Take(0) >= a}
{Take(1) >= b}
a | Math.Xor(b) | ToString | UI.Label
UI.TableHeader({
"A" | UI.Label
} WidthType: "auto")
= i
data | Take(i) | Take(0) | ToString | UI.Label
}
{
UI.TableHeader({
"B" | UI.Label
} WidthType: "auto")
= i
data | Take(i) | Take(1) | ToString | UI.Label
}
{
UI.TableHeader({
"A xor B" | UI.Label
} WidthType: "remainder")
= i
{
data | Take(i) | Take(0) >= a
data | Take(i) | Take(1) >= b
a | Math.Xor(b) | ToString | UI.Label
}
}]
)
}
Expand Down
36 changes: 18 additions & 18 deletions docs/samples/shards/UI/Table/3.shs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ GFX.MainWindow(
UI(
UI.CentralPanel(
Contents: {
[
{Name: "Doe" Surname: "John"}
[{Name: "Doe" Surname: "John"}
{Name: "Dough" Surname: "Jane"}
{Name: "Smith" Surname: "Dick"}] | UI.Table(
{Name: "Smith" Surname: "Dick"}] = seq
Count(seq) | UI.Table(
Resizable: true
Striped: true
RowIndex: index
Columns: [
{Initial: 20.0}
{
Header: "Surname"
Initial: 100.0
AtLeast: 60.0
AtMost: 160.0
UI.TableHeader({
"Index" | UI.Label
} WidthType: "exact" Width: 20.0)
ToString | UI.Label
}
{
Header: {
UI.TableHeader({
"Surname" | UI.Label
} WidthType: "initial" Width: 100.0 MinWidth: 60.0 MaxWidth: 160.0)
= i
seq | Take(i) | Take("Surname") | UI.Label
}
{
UI.TableHeader({
"Name" | UI.Label(Style: {text_style: "Heading"})
UI.Button("Up" Msg("Clicked Up") Style: {text_style: "Small"})
UI.Button("Down" Msg("Clicked Down") Style: {text_style: "Small"})
}
Initial: 120.0
AtLeast: 100.0
AtMost: 160.0
} WidthType: "initial" Width: 120.0 MinWidth: 100.0 MaxWidth: 160.0)
= i
seq | Take(i) | Take("Name") | UI.Label
}]
Builder: [
{index | ToString | UI.Label}
{Take("Surname") | UI.Label}
{Take("Name") | UI.Label}]
)
}
)
Expand Down
1 change: 1 addition & 0 deletions shards/egui/src/bindings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

use egui::epaint;
Expand Down
2 changes: 1 addition & 1 deletion shards/egui/src/bindings/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
use egui::epaint;
use egui::ClippedPrimitive;
use egui::Context;
use egui::TextureId;

use std::ffi::CString;
use std::marker::PhantomData;
use std::ptr;
Expand Down
2 changes: 1 addition & 1 deletion shards/egui/src/containers/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
util::{self, with_possible_panic},
Anchor, EguiId, Order, CONTEXTS_NAME, PARENTS_UI_NAME,
};
use egui::{AreaState, Pos2, Rect, Vec2};
use egui::{Pos2, Rect, Vec2};
use shards::{
core::register_shard,
shard::Shard,
Expand Down
2 changes: 1 addition & 1 deletion shards/egui/src/containers/docking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl LegacyShard for DockArea {
Ok(())
}

fn activate(&mut self, context: &Context, input: &Var) -> Result<Option<Var>, &str> {
fn activate(&mut self, context: &Context, _input: &Var) -> Result<Option<Var>, &str> {
if self.tabs.surfaces_count() == 0 {
return Ok(None);
}
Expand Down
1 change: 0 additions & 1 deletion shards/egui/src/containers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl From<Order> for egui::Order {
Order::Foreground => egui::Order::Foreground,
Order::Tooltip => egui::Order::Tooltip,
Order::Debug => egui::Order::Debug,
_ => unreachable!(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion shards/egui/src/egui_host.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::mem::swap;


use super::util;
use super::CONTEXTS_NAME;
Expand Down
4 changes: 3 additions & 1 deletion shards/egui/src/layouts/disable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ impl LegacyShard for Disable {
if let Some(ui) = util::get_current_parent_opt(self.parents.get())? {
ui.scope(|ui| {
let disabled: bool = self.disable.get().try_into()?;
ui.set_enabled(!disabled);
if disabled {
ui.disable();
}
util::activate_ui_contents(context, input, ui, &mut self.parents, &mut self.contents)
})
.inner?;
Expand Down
64 changes: 32 additions & 32 deletions shards/egui/src/layouts/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ impl Default for Frame {
parents,
requiring: Vec::new(),
contents: ShardsVar::default(),
innerMargin: ParamVar::default(),
outerMargin: ParamVar::default(),
inner_margin: ParamVar::default(),
outer_margin: ParamVar::default(),
rounding: ParamVar::default(),
fillColor: ParamVar::default(),
strokeColor: ParamVar::default(),
strokeWidth: ParamVar::default(),
fill_color: ParamVar::default(),
stroke_color: ParamVar::default(),
stroke_width: ParamVar::default(),
exposing: Vec::new(),
}
}
Expand Down Expand Up @@ -144,25 +144,25 @@ impl LegacyShard for Frame {
fn setParam(&mut self, index: i32, value: &Var) -> Result<(), &str> {
match index {
0 => self.contents.set_param(value),
1 => self.innerMargin.set_param(value),
2 => self.outerMargin.set_param(value),
1 => self.inner_margin.set_param(value),
2 => self.outer_margin.set_param(value),
3 => self.rounding.set_param(value),
4 => self.fillColor.set_param(value),
5 => self.strokeColor.set_param(value),
6 => self.strokeWidth.set_param(value),
4 => self.fill_color.set_param(value),
5 => self.stroke_color.set_param(value),
6 => self.stroke_width.set_param(value),
_ => Err("Invalid parameter index"),
}
}

fn getParam(&mut self, index: i32) -> Var {
match index {
0 => self.contents.get_param(),
1 => self.innerMargin.get_param(),
2 => self.outerMargin.get_param(),
1 => self.inner_margin.get_param(),
2 => self.outer_margin.get_param(),
3 => self.rounding.get_param(),
4 => self.fillColor.get_param(),
5 => self.strokeColor.get_param(),
6 => self.strokeWidth.get_param(),
4 => self.fill_color.get_param(),
5 => self.stroke_color.get_param(),
6 => self.stroke_width.get_param(),
_ => Var::default(),
}
}
Expand Down Expand Up @@ -195,8 +195,8 @@ impl LegacyShard for Frame {
// Add UI.Parents to the list of required variables
util::require_parents(&mut self.requiring);

if self.fillColor.is_variable() {
collect_required_variables(&data.shared, &mut self.requiring, (&self.fillColor).into());
if self.fill_color.is_variable() {
collect_required_variables(&data.shared, &mut self.requiring, (&self.fill_color).into())?;
}

// Always passthrough the input
Expand All @@ -208,23 +208,23 @@ impl LegacyShard for Frame {
if !self.contents.is_empty() {
self.contents.warmup(ctx)?;
}
self.innerMargin.warmup(ctx);
self.outerMargin.warmup(ctx);
self.inner_margin.warmup(ctx);
self.outer_margin.warmup(ctx);
self.rounding.warmup(ctx);
self.fillColor.warmup(ctx);
self.strokeColor.warmup(ctx);
self.strokeWidth.warmup(ctx);
self.fill_color.warmup(ctx);
self.stroke_color.warmup(ctx);
self.stroke_width.warmup(ctx);

Ok(())
}

fn cleanup(&mut self, ctx: Option<&Context>) -> Result<(), &str> {
self.strokeWidth.cleanup(ctx);
self.strokeColor.cleanup(ctx);
self.fillColor.cleanup(ctx);
self.stroke_width.cleanup(ctx);
self.stroke_color.cleanup(ctx);
self.fill_color.cleanup(ctx);
self.rounding.cleanup(ctx);
self.outerMargin.cleanup(ctx);
self.innerMargin.cleanup(ctx);
self.outer_margin.cleanup(ctx);
self.inner_margin.cleanup(ctx);
if !self.contents.is_empty() {
self.contents.cleanup(ctx);
}
Expand All @@ -239,7 +239,7 @@ impl LegacyShard for Frame {
}

if let Some(ui) = util::get_current_parent_opt(self.parents.get())? {
let inner_margin = self.innerMargin.get();
let inner_margin = self.inner_margin.get();
let inner_margin = if inner_margin.is_none() {
egui::Margin::default()
} else {
Expand All @@ -251,7 +251,7 @@ impl LegacyShard for Frame {
bottom,
}
};
let outer_margin = self.outerMargin.get();
let outer_margin = self.outer_margin.get();
let outer_margin = if outer_margin.is_none() {
egui::Margin::default()
} else {
Expand All @@ -270,21 +270,21 @@ impl LegacyShard for Frame {
let (nw, ne, sw, se) = rounding.try_into()?;
egui::epaint::Rounding { nw, ne, sw, se }
};
let fill: &shards::SHVar = self.fillColor.get();
let fill: &shards::SHVar = self.fill_color.get();
let fill = if fill.is_none() {
ui.style().visuals.widgets.noninteractive.bg_fill
} else {
let color: SHColor = fill.try_into()?;
egui::Color32::from_rgba_unmultiplied(color.r, color.g, color.b, color.a)
};
let stroke = {
let width = self.strokeWidth.get();
let width = self.stroke_width.get();
let width = if width.is_none() {
ui.style().visuals.widgets.noninteractive.bg_stroke.width
} else {
width.try_into()?
};
let color = self.strokeColor.get();
let color = self.stroke_color.get();
let color = if color.is_none() {
ui.style().visuals.widgets.noninteractive.bg_stroke.color
} else {
Expand Down
2 changes: 1 addition & 1 deletion shards/egui/src/layouts/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl LegacyShard for NextRow {
Ok(())
}

fn activate(&mut self, _context: &Context, input: &Var) -> Result<Option<Var>, &str> {
fn activate(&mut self, _context: &Context, _input: &Var) -> Result<Option<Var>, &str> {
if let Some(ui) = util::get_current_parent_opt(self.parents.get())? {
ui.end_row();

Expand Down
Loading
Loading