Add TableView and TreeView as a package over Kryon
Both widgets move here from Kryon. They import Kryon's building blocks by package-qualified paths, and their behavior tests run as portable bundles and in Go, binding Kryon's host capabilities by import path.
This commit is contained in:
commit
ce29750a42
16 files changed
+1717
No files matched your search
@@ -0,0 +1,31 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
path: data-views
|
||||
|
||||
- uses: actions/setup-go@v6
|
||||
with:
|
||||
go-version: '1.25.x'
|
||||
|
||||
- name: Build the ziran launcher
|
||||
run: |
|
||||
git clone --depth 1 https://github.com/ziranlang/ziran.git ziran
|
||||
make -C ziran
|
||||
echo "$PWD/ziran/build/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Test
|
||||
working-directory: data-views
|
||||
run: |
|
||||
ziran fetch --locked
|
||||
make check
|
||||
@@ -0,0 +1,2 @@
|
||||
build/
|
||||
ziran.local.toml
|
||||
@@ -0,0 +1,28 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2026, Waozi
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -0,0 +1,39 @@
|
||||
.DEFAULT_GOAL := check
|
||||
|
||||
ZIRAN ?= ziran
|
||||
BUILD := build
|
||||
HOST := tree_view_host
|
||||
|
||||
# The behavior test draws through Kryon's host capabilities; its host module
|
||||
# provides them. Kryon's modules are named by their import paths.
|
||||
BINDS := \
|
||||
--bind kryon/font_metrics:MeasureGlyphWidth=$(HOST):MeasureGlyphWidth \
|
||||
--bind kryon/font_metrics:MeasureGlyphLineHeight=$(HOST):MeasureGlyphLineHeight \
|
||||
--bind kryon/raster_text:RasterText=$(HOST):RasterText \
|
||||
--bind kryon/raster_text:RasterTextClipped=$(HOST):RasterTextClipped \
|
||||
--bind kryon/raster_shape:RasterRoundedRectangle=$(HOST):RasterRoundedRectangle \
|
||||
--bind kryon/raster_shape:RasterRoundedRectangleOutline=$(HOST):RasterRoundedRectangleOutline \
|
||||
--bind kryon/raster:RasterLine=$(HOST):RasterLine \
|
||||
--bind kryon/paint_queue:RasterImage=$(HOST):RasterImage
|
||||
|
||||
.PHONY: check clean
|
||||
|
||||
check:
|
||||
$(ZIRAN) check --project
|
||||
$(ZIRAN) bundle --project --entry table_view_behavior:main \
|
||||
-o $(BUILD)/table-view.zib tests/table_view_behavior.zi
|
||||
test "$$($(ZIRAN) run --project $(BUILD)/table-view.zib)" = 0
|
||||
$(ZIRAN) bundle --project $(BINDS) --entry tree_view_behavior:main \
|
||||
-o $(BUILD)/tree-view.zib tests/tree_view_behavior.zi
|
||||
test "$$($(ZIRAN) run --project $(BUILD)/tree-view.zib)" = 0
|
||||
@if command -v go >/dev/null; then \
|
||||
rm -rf $(BUILD)/tree-view-go && \
|
||||
$(ZIRAN) build --project --target=go --pkg main --exe $(BINDS) \
|
||||
--entry tree_view_behavior:main -o $(BUILD)/tree-view-go \
|
||||
tests/tree_view_behavior.zi && \
|
||||
cd $(BUILD)/tree-view-go && env -u DISPLAY -u WAYLAND_DISPLAY \
|
||||
GO111MODULE=off go run *.go ; \
|
||||
fi
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD)
|
||||
@@ -0,0 +1,33 @@
|
||||
# DataViews
|
||||
|
||||
DataViews adds `TableView` and `TreeView` to
|
||||
[Kryon](https://github.com/kryonlabs/kryon) applications. Both are retained
|
||||
Kryon widgets written in Ziran: the table draws a header, rows, cells, and a
|
||||
keyboard selection over caller-owned data, and the tree shows nested items
|
||||
with expand, collapse, and keyboard navigation. They use Kryon's styles, so
|
||||
the `TableView` and `TreeView` rules in any Kryon style pack apply.
|
||||
|
||||
## Use it
|
||||
|
||||
```sh
|
||||
ziran add https://github.com/kryonlabs/data-views.git
|
||||
```
|
||||
|
||||
```zi
|
||||
using Tables :: #import "data_views/TableView";
|
||||
using Trees :: #import "data_views/TreeView";
|
||||
```
|
||||
|
||||
## Develop
|
||||
|
||||
`make check` checks the package and runs the behavior tests as portable
|
||||
bundles, and in Go when `go` is installed. It uses the `ziran` launcher and
|
||||
the Ziran and Kryon commits pinned in `ziran.lock`. To test against local
|
||||
checkouts, put them next to this one and keep this in an ignored
|
||||
`ziran.local.toml`:
|
||||
|
||||
```toml
|
||||
[overrides]
|
||||
ziran = "../ziran"
|
||||
kryon = "../kryon"
|
||||
```
|
||||
@@ -0,0 +1,2 @@
|
||||
using TableViewPropsModule :: #import "table_view_props";
|
||||
using TableViewModule :: #import "table_view";
|
||||
@@ -0,0 +1,2 @@
|
||||
using TreeViewPropsModule :: #import "tree_view_props";
|
||||
using TreeViewModule :: #import "tree_view";
|
||||
@@ -0,0 +1,672 @@
|
||||
#import "kryon/drawing_props"
|
||||
#import "kryon/geometry"
|
||||
#import "kryon/style"
|
||||
#import "kryon/style_sheet"
|
||||
#import "kryon/control_props"
|
||||
|
||||
using ButtonTone;
|
||||
using ButtonEmphasis;
|
||||
using ControlSize;
|
||||
using StyleField;
|
||||
|
||||
TableViewMetrics :: struct {
|
||||
default_row_height: s32
|
||||
min_header_height: s32
|
||||
default_min_column_width: s32
|
||||
header_text_pad_x: s32
|
||||
resize_tolerance: s32
|
||||
scrollbar_width: s32
|
||||
}
|
||||
|
||||
TableViewLayout :: struct {
|
||||
row_height: s32
|
||||
header_height: s32
|
||||
body: Rectangle
|
||||
frozen_rows: s32
|
||||
scroll_body_height: s32
|
||||
max_scroll: s32
|
||||
}
|
||||
|
||||
TableViewScrollLayout :: struct {
|
||||
first: s32
|
||||
y_offset: s32
|
||||
visible_rows: s32
|
||||
}
|
||||
|
||||
TableViewSelection :: struct {
|
||||
row: s32
|
||||
column_slot: s32
|
||||
}
|
||||
|
||||
TableViewSelectionClearDecision :: struct {
|
||||
row: s32
|
||||
column: s32
|
||||
changed: bool
|
||||
}
|
||||
|
||||
TableViewSortDecision :: struct {
|
||||
selected_row: s32
|
||||
selected_column: s32
|
||||
sort_column: s32
|
||||
sort_direction: s32
|
||||
changed: bool
|
||||
}
|
||||
|
||||
TableViewHeaderPointerDecision :: struct {
|
||||
sort: bool
|
||||
}
|
||||
|
||||
TableViewRowPointerDecision :: struct {
|
||||
mark_clickable: bool
|
||||
click: bool
|
||||
context: bool
|
||||
consume_release: bool
|
||||
}
|
||||
|
||||
TableViewRowClickDecision :: struct {
|
||||
selected_row: s32
|
||||
selected_column: s32
|
||||
activated_row: s32
|
||||
activated_column: s32
|
||||
changed: bool
|
||||
}
|
||||
|
||||
TableViewRowContextDecision :: struct {
|
||||
row: s32
|
||||
column: s32
|
||||
changed: bool
|
||||
}
|
||||
|
||||
TableViewClipboardDecision :: struct {
|
||||
copy_selection: bool
|
||||
paste: bool
|
||||
}
|
||||
|
||||
TableViewResizeClearDecision :: struct {
|
||||
clear: bool
|
||||
}
|
||||
|
||||
TableViewResizeStartDecision :: struct {
|
||||
begin: bool
|
||||
column: s32
|
||||
}
|
||||
|
||||
TableViewResizeDragDecision :: struct {
|
||||
update: bool
|
||||
finish: bool
|
||||
consume_release: bool
|
||||
mark_clickable: bool
|
||||
}
|
||||
|
||||
TableViewKeyboardIntent :: struct {
|
||||
move_row: s32
|
||||
move_column: s32
|
||||
tab: bool
|
||||
tab_backwards: bool
|
||||
activate: bool
|
||||
clear_selection: bool
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewPanelRole :: () -> s32 {
|
||||
return 2
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewHeaderRole :: () -> s32 {
|
||||
return 13
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewDividerRole :: () -> s32 {
|
||||
return 18
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewRowRole :: () -> s32 {
|
||||
return 21
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewCellRole :: () -> s32 {
|
||||
return 22
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewSelectionRole :: () -> s32 {
|
||||
return 23
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewFactsFor :: (class_name: s32, state: s32) -> StyleFacts {
|
||||
return StyleControlRoleFacts(StyleKindTableView(), 0, class_name,
|
||||
StyleAny(), ButtonToneNeutral, ButtonEmphasisSoft, ControlSizeMedium,
|
||||
state)
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewRoleFactsFor :: (class_name: s32, role: s32, state: s32) -> StyleFacts {
|
||||
return StyleControlRoleFacts(StyleKindTableView(), 0, class_name, role,
|
||||
ButtonToneNeutral, ButtonEmphasisSoft, ControlSizeMedium, state)
|
||||
}
|
||||
|
||||
TableViewMetric :: (fields: u32, field: u32, value: float32,
|
||||
fallback: float32, scale: float32, allow_zero: bool) -> s32 {
|
||||
if (fields & field) == cast(u32)0 || value < 0.0 ||
|
||||
(!allow_zero && value <= 0.0) {
|
||||
value = fallback
|
||||
}
|
||||
return cast(s32)(value * scale)
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewMetricsFor :: (scale: float32, table: StyleFrame, header: StyleFrame,
|
||||
cell: StyleFrame, divider: StyleFrame) -> TableViewMetrics {
|
||||
if scale <= 0.0 { scale = 1.0 }
|
||||
metrics: TableViewMetrics
|
||||
metrics.default_row_height = TableViewMetric(table.value.fields,
|
||||
cast(u32)StyleContentOffset, table.value.offset_y, 28.0, scale, false)
|
||||
metrics.min_header_height = TableViewMetric(header.value.fields,
|
||||
cast(u32)StyleContentOffset, header.value.offset_y, 30.0, scale, false)
|
||||
metrics.default_min_column_width = TableViewMetric(cell.value.fields,
|
||||
cast(u32)StyleContentOffset, cell.value.offset_x, 32.0, scale, false)
|
||||
metrics.header_text_pad_x = TableViewMetric(header.value.fields,
|
||||
cast(u32)StylePaddingX, header.value.padding_x, 6.0, scale, true)
|
||||
metrics.resize_tolerance = TableViewMetric(divider.value.fields,
|
||||
cast(u32)StylePaddingX, divider.value.padding_x, 5.0, scale, true)
|
||||
metrics.scrollbar_width = TableViewMetric(divider.value.fields,
|
||||
cast(u32)StyleContentOffset, divider.value.offset_y, 8.0, scale, true)
|
||||
return metrics
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewRowHeight :: (requested_row_height: s32, scale: float32,
|
||||
metrics: TableViewMetrics) -> s32 {
|
||||
if scale <= 0.0 { scale = 1.0 }
|
||||
if requested_row_height > 0 {
|
||||
height: s32 = cast(s32)(cast(float32)requested_row_height * scale)
|
||||
if height > 0 { return height }
|
||||
}
|
||||
return metrics.default_row_height
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewHeaderHeight :: (requested_header_height: s32, scale: float32,
|
||||
metrics: TableViewMetrics) -> s32 {
|
||||
if scale <= 0.0 { scale = 1.0 }
|
||||
height: s32 = metrics.min_header_height
|
||||
if requested_header_height > 0 {
|
||||
height = cast(s32)(cast(float32)requested_header_height * scale)
|
||||
}
|
||||
if height < metrics.min_header_height { height = metrics.min_header_height }
|
||||
return height
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewBodyBounds :: (bounds: Rectangle, header_height: s32) -> Rectangle {
|
||||
body: Rectangle
|
||||
body.x = bounds.x
|
||||
body.y = bounds.y + cast(float32)header_height
|
||||
body.width = bounds.width
|
||||
body.height = bounds.height - cast(float32)header_height
|
||||
if body.height < 0.0 { body.height = 0.0 }
|
||||
return body
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewFrozenRows :: (requested: s32, row_count: s32, body_height: s32,
|
||||
row_height: s32) -> s32 {
|
||||
frozen: s32 = requested
|
||||
if frozen < 0 { frozen = 0 }
|
||||
if frozen > row_count { frozen = row_count }
|
||||
if row_height <= 0 { row_height = 1 }
|
||||
max_frozen: s32 = body_height / row_height
|
||||
if max_frozen < 0 { max_frozen = 0 }
|
||||
if frozen > max_frozen { frozen = max_frozen }
|
||||
return frozen
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewScrollBodyHeight :: (body_height: s32, frozen_rows: s32,
|
||||
row_height: s32) -> s32 {
|
||||
height: s32 = body_height - frozen_rows * row_height
|
||||
if height < 0 { return 0 }
|
||||
return height
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewMaxScroll :: (row_count: s32, frozen_rows: s32, row_height: s32,
|
||||
scroll_body_height: s32) -> s32 {
|
||||
rows: s32 = row_count - frozen_rows
|
||||
if rows < 0 { rows = 0 }
|
||||
max_scroll: s32 = rows * row_height - scroll_body_height
|
||||
if max_scroll < 0 { return 0 }
|
||||
return max_scroll
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewLayoutFor :: (bounds: Rectangle, row_count: s32,
|
||||
requested_row_height: s32, requested_header_height: s32,
|
||||
requested_frozen_rows: s32, scale: float32,
|
||||
metrics: TableViewMetrics) -> TableViewLayout {
|
||||
layout: TableViewLayout
|
||||
layout.row_height = TableViewRowHeight(requested_row_height, scale, metrics)
|
||||
layout.header_height = TableViewHeaderHeight(requested_header_height, scale, metrics)
|
||||
layout.body = TableViewBodyBounds(bounds, layout.header_height)
|
||||
layout.frozen_rows = TableViewFrozenRows(requested_frozen_rows, row_count,
|
||||
cast(s32)layout.body.height, layout.row_height)
|
||||
layout.scroll_body_height = TableViewScrollBodyHeight(cast(s32)layout.body.height,
|
||||
layout.frozen_rows, layout.row_height)
|
||||
layout.max_scroll = TableViewMaxScroll(row_count, layout.frozen_rows,
|
||||
layout.row_height, layout.scroll_body_height)
|
||||
return layout
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewScrollFor :: (scroll_y: s32, frozen_rows: s32, row_height: s32,
|
||||
scroll_body_height: s32) -> TableViewScrollLayout {
|
||||
layout: TableViewScrollLayout
|
||||
if scroll_y < 0 { scroll_y = 0 }
|
||||
if row_height <= 0 { row_height = 1 }
|
||||
layout.first = frozen_rows + scroll_y / row_height
|
||||
layout.y_offset = scroll_y % row_height
|
||||
if scroll_body_height <= 0 {
|
||||
layout.visible_rows = 0
|
||||
} else {
|
||||
layout.visible_rows = scroll_body_height / row_height + 1
|
||||
}
|
||||
return layout
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewDefaultColumnWidth :: (bounds_width: s32, visible_columns: s32) -> s32 {
|
||||
if visible_columns <= 0 { return 0 }
|
||||
return bounds_width / visible_columns
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewColumnWidth :: (requested_width: s32, default_width: s32) -> s32 {
|
||||
if requested_width > 0 { return requested_width }
|
||||
return default_width
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewHeaderBounds :: (bounds: Rectangle, column_x: s32,
|
||||
column_width: s32, header_height: s32) -> Rectangle {
|
||||
header: Rectangle
|
||||
header.x = cast(float32)column_x
|
||||
header.y = bounds.y
|
||||
header.width = cast(float32)column_width
|
||||
header.height = cast(float32)header_height
|
||||
return header
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewRowBounds :: (bounds: Rectangle, layout: TableViewLayout,
|
||||
row_index: s32, draw_index: s32, scroll: TableViewScrollLayout,
|
||||
scrolling: bool) -> Rectangle {
|
||||
row: Rectangle
|
||||
row.x = bounds.x
|
||||
if scrolling {
|
||||
local: s32 = draw_index - layout.frozen_rows
|
||||
row.y = bounds.y + cast(float32)(layout.header_height +
|
||||
layout.frozen_rows * layout.row_height +
|
||||
local * layout.row_height - scroll.y_offset)
|
||||
} else {
|
||||
row.y = bounds.y + cast(float32)(layout.header_height +
|
||||
row_index * layout.row_height)
|
||||
}
|
||||
row.width = bounds.width
|
||||
row.height = cast(float32)layout.row_height
|
||||
return row
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewCellBounds :: (row: Rectangle, column_x: s32, column_width: s32) -> Rectangle {
|
||||
cell: Rectangle
|
||||
cell.x = cast(float32)column_x
|
||||
cell.y = row.y
|
||||
cell.width = cast(float32)column_width
|
||||
cell.height = row.height
|
||||
return cell
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewViewport :: (bounds: Rectangle, layout: TableViewLayout,
|
||||
scrolling: bool) -> Rectangle {
|
||||
viewport: Rectangle
|
||||
viewport.x = bounds.x
|
||||
viewport.y = bounds.y + cast(float32)layout.header_height
|
||||
viewport.width = bounds.width
|
||||
if scrolling {
|
||||
viewport.y += cast(float32)(layout.frozen_rows * layout.row_height)
|
||||
viewport.height = cast(float32)layout.scroll_body_height
|
||||
} else {
|
||||
viewport.height = cast(float32)(layout.frozen_rows * layout.row_height)
|
||||
}
|
||||
if viewport.height < 0.0 { viewport.height = 0.0 }
|
||||
return viewport
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewScrollbarBoundsFor :: (bounds: Rectangle, layout: TableViewLayout,
|
||||
scrollbar_width: s32) -> Rectangle {
|
||||
scrollbar: Rectangle
|
||||
scrollbar.x = bounds.x + bounds.width - cast(float32)scrollbar_width
|
||||
scrollbar.y = bounds.y + cast(float32)(layout.header_height +
|
||||
layout.frozen_rows * layout.row_height)
|
||||
scrollbar.width = cast(float32)scrollbar_width
|
||||
scrollbar.height = cast(float32)layout.scroll_body_height
|
||||
if scrollbar.width < 0.0 { scrollbar.width = 0.0 }
|
||||
if scrollbar.height < 0.0 { scrollbar.height = 0.0 }
|
||||
return scrollbar
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewMinimumColumnWidth :: (requested_min_width: s32, scale: float32,
|
||||
metrics: TableViewMetrics) -> s32 {
|
||||
if scale <= 0.0 { scale = 1.0 }
|
||||
if requested_min_width > 0 {
|
||||
width: s32 = cast(s32)(cast(float32)requested_min_width * scale)
|
||||
if width > 0 { return width }
|
||||
}
|
||||
return metrics.default_min_column_width
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewHeaderAngleFor :: (requested_angle: float32) -> float32 {
|
||||
if requested_angle != requested_angle { return 0.0 }
|
||||
if requested_angle < -89.0 { return -89.0 }
|
||||
if requested_angle > 89.0 { return 89.0 }
|
||||
return requested_angle
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewResizeColumnWidthFor :: (start_width: s32, start_x: s32,
|
||||
pointer_x: s32, minimum_width: s32) -> s32 {
|
||||
width: s32 = start_width + pointer_x - start_x
|
||||
if width < minimum_width {
|
||||
return minimum_width
|
||||
}
|
||||
return width
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewResizeStartFor :: (active: bool, content_disabled: bool,
|
||||
table_disabled: bool, resizable: bool, has_column_widths: bool,
|
||||
pressed: bool, pointer_in_header: bool,
|
||||
column: s32) -> TableViewResizeStartDecision {
|
||||
decision: TableViewResizeStartDecision
|
||||
decision.column = column
|
||||
decision.begin = !active && !content_disabled && !table_disabled &&
|
||||
resizable && has_column_widths && pressed && pointer_in_header &&
|
||||
column >= 0
|
||||
return decision
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewResizeDragFor :: (active: bool, same_table: bool,
|
||||
content_disabled: bool, table_disabled: bool, resizable: bool,
|
||||
has_column_widths: bool, down: bool,
|
||||
released: bool) -> TableViewResizeDragDecision {
|
||||
decision: TableViewResizeDragDecision
|
||||
if !active || !same_table {
|
||||
return decision
|
||||
}
|
||||
can_update: bool = !content_disabled && !table_disabled && resizable &&
|
||||
has_column_widths
|
||||
decision.update = can_update && down
|
||||
decision.finish = released
|
||||
decision.consume_release = released
|
||||
decision.mark_clickable = can_update && down
|
||||
return decision
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewResizeClearFor :: (active: bool, owner_captured: bool,
|
||||
content_disabled: bool, released: bool, same_table: bool,
|
||||
table_disabled: bool, resizable: bool,
|
||||
has_column_widths: bool) -> TableViewResizeClearDecision {
|
||||
decision: TableViewResizeClearDecision
|
||||
if !active {
|
||||
return decision
|
||||
}
|
||||
if owner_captured {
|
||||
decision.clear = true
|
||||
return decision
|
||||
}
|
||||
if (content_disabled || released) &&
|
||||
(content_disabled || !same_table || table_disabled || !resizable ||
|
||||
!has_column_widths) {
|
||||
decision.clear = true
|
||||
}
|
||||
return decision
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewHeaderHotFor :: (disabled: bool, pointer_in_headers: bool,
|
||||
pointer_in_header: bool, captured: bool) -> bool {
|
||||
return !disabled && pointer_in_headers && pointer_in_header && !captured
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewRowHotFor :: (disabled: bool, custom_cells: bool,
|
||||
pointer_in_viewport: bool, row_hot: bool) -> bool {
|
||||
return !disabled && !custom_cells && pointer_in_viewport && row_hot
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewSelectedRowFor :: (selected_row: s32, row_count: s32) -> s32 {
|
||||
if row_count <= 0 { return -1 }
|
||||
if selected_row < 0 { return 0 }
|
||||
if selected_row >= row_count { return row_count - 1 }
|
||||
return selected_row
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewSelectionMoveRow :: (row: s32, row_count: s32,
|
||||
direction: s32) -> s32 {
|
||||
if row_count <= 0 { return -1 }
|
||||
row = TableViewSelectedRowFor(row, row_count)
|
||||
if direction < 0 && row > 0 { row -= 1 }
|
||||
if direction > 0 && row < row_count - 1 { row += 1 }
|
||||
return row
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewColumnSlotFor :: (slot: s32, visible_columns: s32) -> s32 {
|
||||
if visible_columns <= 0 { return -1 }
|
||||
if slot < 0 { return 0 }
|
||||
if slot >= visible_columns { return visible_columns - 1 }
|
||||
return slot
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewSelectionMoveColumn :: (slot: s32, visible_columns: s32,
|
||||
direction: s32) -> s32 {
|
||||
if visible_columns <= 0 { return -1 }
|
||||
slot = TableViewColumnSlotFor(slot, visible_columns)
|
||||
if direction < 0 && slot > 0 { slot -= 1 }
|
||||
if direction > 0 && slot < visible_columns - 1 { slot += 1 }
|
||||
return slot
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewSelectionTab :: (row: s32, column_slot: s32, row_count: s32,
|
||||
visible_columns: s32, backwards: bool) -> TableViewSelection {
|
||||
selection: TableViewSelection
|
||||
selection.row = TableViewSelectedRowFor(row, row_count)
|
||||
selection.column_slot = TableViewColumnSlotFor(column_slot, visible_columns)
|
||||
if selection.row < 0 || selection.column_slot < 0 {
|
||||
return selection
|
||||
}
|
||||
if backwards {
|
||||
if selection.column_slot > 0 {
|
||||
selection.column_slot -= 1
|
||||
} else {
|
||||
selection.column_slot = visible_columns - 1
|
||||
if selection.row > 0 { selection.row -= 1 }
|
||||
}
|
||||
} else {
|
||||
if selection.column_slot < visible_columns - 1 {
|
||||
selection.column_slot += 1
|
||||
} else {
|
||||
selection.column_slot = 0
|
||||
if selection.row < row_count - 1 { selection.row += 1 }
|
||||
}
|
||||
}
|
||||
return selection
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewSelectionClearFor :: (selected_row: s32,
|
||||
selected_column: s32) -> TableViewSelectionClearDecision {
|
||||
decision: TableViewSelectionClearDecision
|
||||
decision.row = selected_row
|
||||
decision.column = selected_column
|
||||
if selected_row >= 0 || selected_column >= 0 {
|
||||
decision.row = -1
|
||||
decision.column = -1
|
||||
decision.changed = true
|
||||
}
|
||||
return decision
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewKeyboardIntentFor :: (up: bool, down: bool, left: bool, right: bool,
|
||||
tab: bool, tab_backwards: bool, enter: bool, f2: bool,
|
||||
escape: bool) -> TableViewKeyboardIntent {
|
||||
intent: TableViewKeyboardIntent
|
||||
if up { intent.move_row = -1 }
|
||||
if down { intent.move_row = 1 }
|
||||
if left { intent.move_column = -1 }
|
||||
if right { intent.move_column = 1 }
|
||||
intent.tab = tab
|
||||
intent.tab_backwards = tab_backwards
|
||||
intent.activate = enter || f2
|
||||
intent.clear_selection = escape
|
||||
return intent
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewHeaderPointerDecisionFor :: (disabled: bool, header_hot: bool,
|
||||
released: bool, has_sort_column: bool) -> TableViewHeaderPointerDecision {
|
||||
decision: TableViewHeaderPointerDecision
|
||||
decision.sort = !disabled && header_hot && released && has_sort_column
|
||||
return decision
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewSortDecisionFor :: (column: s32, previous_sort_column: s32,
|
||||
previous_sort_direction: s32) -> TableViewSortDecision {
|
||||
decision: TableViewSortDecision
|
||||
decision.selected_row = -1
|
||||
decision.selected_column = column
|
||||
decision.sort_column = column
|
||||
decision.sort_direction = previous_sort_direction
|
||||
if column < 0 {
|
||||
decision.selected_column = -1
|
||||
decision.sort_column = previous_sort_column
|
||||
return decision
|
||||
}
|
||||
if previous_sort_column != column || previous_sort_direction == 0 {
|
||||
decision.sort_direction = 1
|
||||
} else if previous_sort_direction > 0 {
|
||||
decision.sort_direction = -1
|
||||
} else {
|
||||
decision.sort_direction = 0
|
||||
}
|
||||
decision.changed = true
|
||||
return decision
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewRowPointerDecisionFor :: (disabled: bool, hot: bool,
|
||||
left_released: bool, right_released: bool, has_selection: bool,
|
||||
has_context: bool) -> TableViewRowPointerDecision {
|
||||
decision: TableViewRowPointerDecision
|
||||
decision.mark_clickable = !disabled && hot
|
||||
decision.click = decision.mark_clickable && left_released && has_selection
|
||||
decision.context = decision.mark_clickable && right_released && has_context
|
||||
decision.consume_release = decision.click
|
||||
return decision
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewClipboardDecisionFor :: (modifier_down: bool,
|
||||
copy_pressed: bool, cut_pressed: bool, paste_pressed: bool,
|
||||
has_paste_target: bool) -> TableViewClipboardDecision {
|
||||
decision: TableViewClipboardDecision
|
||||
if !modifier_down {
|
||||
return decision
|
||||
}
|
||||
decision.copy_selection = copy_pressed || cut_pressed
|
||||
decision.paste = paste_pressed && has_paste_target
|
||||
return decision
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewActivationShouldRun :: (clicked_column: s32, same_table: bool,
|
||||
last_row: s32, row: s32, last_column: s32, elapsed_seconds: float32) -> bool {
|
||||
if clicked_column < 0 {
|
||||
return false
|
||||
}
|
||||
if !same_table {
|
||||
return false
|
||||
}
|
||||
if last_row != row || last_column != clicked_column {
|
||||
return false
|
||||
}
|
||||
return elapsed_seconds <= 0.45
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewRowClickDecisionFor :: (row: s32, clicked_column: s32,
|
||||
same_table: bool, last_row: s32, last_column: s32,
|
||||
elapsed_seconds: float32) -> TableViewRowClickDecision {
|
||||
decision: TableViewRowClickDecision
|
||||
decision.selected_row = row
|
||||
decision.selected_column = clicked_column
|
||||
decision.activated_row = -1
|
||||
decision.activated_column = -1
|
||||
if TableViewActivationShouldRun(clicked_column, same_table, last_row,
|
||||
row, last_column, elapsed_seconds) {
|
||||
decision.activated_row = row
|
||||
decision.activated_column = clicked_column
|
||||
}
|
||||
decision.changed = true
|
||||
return decision
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewRowContextDecisionFor :: (row: s32,
|
||||
clicked_column: s32) -> TableViewRowContextDecision {
|
||||
decision: TableViewRowContextDecision
|
||||
decision.row = row
|
||||
decision.column = clicked_column
|
||||
decision.changed = true
|
||||
return decision
|
||||
}
|
||||
|
||||
#program_export
|
||||
TableViewSelectionScrollOffset :: (row: s32, frozen_rows: s32,
|
||||
row_height: s32, view_height: s32, scroll_offset: s32,
|
||||
max_scroll: s32) -> s32 {
|
||||
if scroll_offset < 0 { scroll_offset = 0 }
|
||||
if max_scroll < 0 { max_scroll = 0 }
|
||||
if row < frozen_rows || view_height <= 0 {
|
||||
if scroll_offset > max_scroll { return max_scroll }
|
||||
return scroll_offset
|
||||
}
|
||||
if row_height <= 0 { row_height = 1 }
|
||||
top: s32 = (row - frozen_rows) * row_height
|
||||
bottom: s32 = top + row_height
|
||||
if top < scroll_offset {
|
||||
scroll_offset = top
|
||||
} else if bottom > scroll_offset + view_height {
|
||||
scroll_offset = bottom - view_height
|
||||
}
|
||||
if scroll_offset < 0 { scroll_offset = 0 }
|
||||
if scroll_offset > max_scroll { scroll_offset = max_scroll }
|
||||
return scroll_offset
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#import "kryon/geometry"
|
||||
|
||||
TableText :: struct {
|
||||
value: string
|
||||
}
|
||||
|
||||
TableRow :: struct {
|
||||
cells: *TableText
|
||||
cell_count: s32
|
||||
}
|
||||
|
||||
TableViewProps :: struct {
|
||||
bounds: Rectangle
|
||||
id: s32
|
||||
class_name: s32
|
||||
columns: *TableText
|
||||
column_count: s32
|
||||
rows: *TableRow
|
||||
row_count: s32
|
||||
column_widths: *s32
|
||||
selected_row: *s32
|
||||
selected_column: *s32
|
||||
activated_row: *s32
|
||||
activated_column: *s32
|
||||
right_clicked_row: *s32
|
||||
right_clicked_column: *s32
|
||||
sort_column: *s32
|
||||
scroll_offset: *s32
|
||||
row_height: s32
|
||||
column_enabled: *s32
|
||||
column_order: *s32
|
||||
sort_direction: *s32
|
||||
disabled: bool
|
||||
resizable: bool
|
||||
min_column_width: s32
|
||||
freeze_rows: s32
|
||||
header_height: s32
|
||||
header_angle: float32
|
||||
custom_cells: bool
|
||||
copy_text: string
|
||||
pasted_text: *TableText
|
||||
pasted_row: *s32
|
||||
pasted_column: *s32
|
||||
selection_start_row: *s32
|
||||
selection_start_column: *s32
|
||||
selection_end_row: *s32
|
||||
selection_end_column: *s32
|
||||
}
|
||||
@@ -0,0 +1,528 @@
|
||||
#import "kryon/session"
|
||||
#import "kryon/drawing_props"
|
||||
#import "kryon/geometry"
|
||||
#import "kryon/style"
|
||||
#import "kryon/control_props"
|
||||
#import "kryon/font_metrics"
|
||||
#import "kryon/paint_queue"
|
||||
#import "kryon/semantic"
|
||||
#import "kryon/scroll"
|
||||
#import "kryon/style_sheet"
|
||||
#import "kryon/surface"
|
||||
#import "kryon/tree"
|
||||
#import "kryon/tree_input"
|
||||
#import "tree_view_props"
|
||||
#import "kryon/widget_kind"
|
||||
|
||||
using SemanticKind;
|
||||
using TreeViewNavigation;
|
||||
using WidgetKind;
|
||||
using ButtonTone;
|
||||
using ButtonEmphasis;
|
||||
using ControlSize;
|
||||
using ButtonState;
|
||||
using StyleField;
|
||||
|
||||
TreeViewMetrics :: struct {
|
||||
default_row_height: s32
|
||||
indent_x: s32
|
||||
depth_indent: s32
|
||||
marker_width: s32
|
||||
text_gap: s32
|
||||
scrollbar_width: s32
|
||||
}
|
||||
|
||||
TreeViewScrollLayout :: struct {
|
||||
first: s32
|
||||
y_offset: s32
|
||||
}
|
||||
|
||||
TreeViewTextPaint :: struct {
|
||||
marker_x: s32
|
||||
marker_y: s32
|
||||
text_x: s32
|
||||
text_y: s32
|
||||
}
|
||||
|
||||
TreeViewRowDecision :: struct {
|
||||
select: bool
|
||||
selected_id: s32
|
||||
consume_release: bool
|
||||
changed: bool
|
||||
}
|
||||
|
||||
TreeViewHas :: (fields: u32, field: u32) -> bool {
|
||||
return (fields & field) != cast(u32)0
|
||||
}
|
||||
|
||||
TreeViewMetric :: (fields: u32, field: u32, value: float32,
|
||||
fallback: float32, scale: float32, allow_zero: bool) -> s32 {
|
||||
if !TreeViewHas(fields, field) || value < 0.0 ||
|
||||
(!allow_zero && value <= 0.0) {
|
||||
value = fallback
|
||||
}
|
||||
return cast(s32)(value * scale)
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewMetricsFor :: (scale: float32, panel: StyleFrame,
|
||||
item: StyleFrame) -> TreeViewMetrics {
|
||||
if scale <= 0.0 { scale = 1.0 }
|
||||
metrics: TreeViewMetrics
|
||||
row_height: float32 = 28.0
|
||||
if TreeViewHas(item.value.fields, cast(u32)StyleFontSize) &&
|
||||
TreeViewHas(item.value.fields, cast(u32)StylePaddingY) {
|
||||
row_height = item.value.font_size + item.value.padding_y * 2.0
|
||||
}
|
||||
metrics.default_row_height = TreeViewMetric(item.value.fields,
|
||||
cast(u32)StyleContentOffset, item.value.offset_y, row_height, scale, false)
|
||||
metrics.indent_x = TreeViewMetric(panel.value.fields,
|
||||
cast(u32)StylePaddingX, panel.value.padding_x, 8.0, scale, true)
|
||||
metrics.depth_indent = TreeViewMetric(item.value.fields,
|
||||
cast(u32)StyleContentOffset, item.value.offset_x, 18.0, scale, false)
|
||||
metrics.marker_width = TreeViewMetric(item.value.fields,
|
||||
cast(u32)StyleIconSize, item.value.icon_size, 16.0, scale, false)
|
||||
metrics.text_gap = TreeViewMetric(item.value.fields,
|
||||
cast(u32)StyleGap, item.value.gap, 2.0, scale, true)
|
||||
metrics.scrollbar_width = TreeViewMetric(panel.value.fields,
|
||||
cast(u32)StyleIconSize, panel.value.icon_size, 8.0, scale, true)
|
||||
return metrics
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewRowHeight :: (requested_row_height: s32, scale: float32,
|
||||
metrics: TreeViewMetrics) -> s32 {
|
||||
if scale <= 0.0 { scale = 1.0 }
|
||||
if requested_row_height > 0 {
|
||||
height: s32 = cast(s32)(cast(float32)requested_row_height * scale)
|
||||
if height > 0 { return height }
|
||||
}
|
||||
return metrics.default_row_height
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewContentHeight :: (item_count: s32, row_height: s32) -> s32 {
|
||||
if item_count <= 0 || row_height <= 0 { return 0 }
|
||||
height: s64 = cast(s64)item_count * cast(s64)row_height
|
||||
if height > cast(s64)2147483647 { return 2147483647 }
|
||||
return cast(s32)height
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewMaxScroll :: (viewport_height: s32, content_height: s32) -> s32 {
|
||||
max_scroll: s32 = content_height - viewport_height
|
||||
if max_scroll < 0 { return 0 }
|
||||
return max_scroll
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewScrollFor :: (scroll_y: s32, row_height: s32) -> TreeViewScrollLayout {
|
||||
layout: TreeViewScrollLayout
|
||||
if scroll_y < 0 { scroll_y = 0 }
|
||||
if row_height <= 0 { row_height = 1 }
|
||||
layout.first = scroll_y / row_height
|
||||
layout.y_offset = scroll_y % row_height
|
||||
return layout
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewVisibleRows :: (viewport_height: s32, row_height: s32) -> s32 {
|
||||
if viewport_height <= 0 { return 0 }
|
||||
if row_height <= 0 { row_height = 1 }
|
||||
return viewport_height / row_height + 1
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewRowBounds :: (bounds: Rectangle, visible_index: s32,
|
||||
row_height: s32, y_offset: s32) -> Rectangle {
|
||||
row: Rectangle
|
||||
row.x = bounds.x
|
||||
row.y = bounds.y + cast(float32)(visible_index * row_height - y_offset)
|
||||
row.width = bounds.width
|
||||
row.height = cast(float32)row_height
|
||||
return row
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewIndent :: (depth: s32, metrics: TreeViewMetrics) -> s32 {
|
||||
if depth < 0 { depth = 0 }
|
||||
return metrics.indent_x + depth * metrics.depth_indent
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewMarkerBounds :: (row: Rectangle, depth: s32,
|
||||
metrics: TreeViewMetrics) -> Rectangle {
|
||||
marker: Rectangle
|
||||
indent: s32 = TreeViewIndent(depth, metrics)
|
||||
marker.x = row.x + cast(float32)indent
|
||||
marker.y = row.y
|
||||
marker.width = cast(float32)metrics.marker_width
|
||||
marker.height = row.height
|
||||
return marker
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewTextBounds :: (row: Rectangle, depth: s32,
|
||||
metrics: TreeViewMetrics) -> Rectangle {
|
||||
text: Rectangle
|
||||
indent: s32 = TreeViewIndent(depth, metrics)
|
||||
x: float32 = row.x + cast(float32)(indent + metrics.marker_width + metrics.text_gap)
|
||||
text.x = x
|
||||
text.y = row.y
|
||||
text.width = row.width - (x - row.x)
|
||||
if text.width < 0.0 { text.width = 0.0 }
|
||||
text.height = row.height
|
||||
return text
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewTextPaintFor :: (marker: Rectangle, text: Rectangle,
|
||||
text_line_height: s32) -> TreeViewTextPaint {
|
||||
paint: TreeViewTextPaint
|
||||
paint.marker_x = cast(s32)marker.x
|
||||
paint.marker_y = cast(s32)marker.y + (cast(s32)marker.height - text_line_height) / 2
|
||||
paint.text_x = cast(s32)text.x
|
||||
paint.text_y = cast(s32)text.y + (cast(s32)text.height - text_line_height) / 2
|
||||
return paint
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewMarkerText :: (expanded: bool) -> string {
|
||||
if expanded { return "v" }
|
||||
return ">"
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewRowDecisionFor :: (hot: bool, released: bool, selectable: bool,
|
||||
has_selection: bool, item_id: s32) -> TreeViewRowDecision {
|
||||
decision: TreeViewRowDecision
|
||||
decision.selected_id = item_id
|
||||
if hot && released && selectable && has_selection {
|
||||
decision.select = true
|
||||
decision.consume_release = true
|
||||
decision.changed = true
|
||||
}
|
||||
return decision
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewScrollbarBoundsFor :: (bounds: Rectangle, scrollbar_width: s32) -> Rectangle {
|
||||
bar: Rectangle
|
||||
if scrollbar_width < 0 { scrollbar_width = 0 }
|
||||
bar.x = bounds.x + bounds.width - cast(float32)scrollbar_width
|
||||
bar.y = bounds.y
|
||||
bar.width = cast(float32)scrollbar_width
|
||||
bar.height = bounds.height
|
||||
return bar
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewRowKey :: (item: TreeItem, index: s32) -> u64 {
|
||||
if item.id > 0 { return cast(u64)cast(u32)item.id }
|
||||
return cast(u64)4294967296 + cast(u64)cast(u32)(index + 1)
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewFace :: (kind: s32, name: s32, class_name: s32,
|
||||
state: s32) -> StyleFrame {
|
||||
defaults: StyleData
|
||||
defaults.fields = cast(u32)StyleBackground | cast(u32)StyleForeground |
|
||||
cast(u32)StyleBorder | cast(u32)StyleBorderWidth |
|
||||
cast(u32)StyleRadius | cast(u32)StyleOpacity |
|
||||
cast(u32)StyleFontSize | cast(u32)StylePaddingX |
|
||||
cast(u32)StylePaddingY | cast(u32)StyleGap
|
||||
defaults.background = cast(u32)0xffffffff
|
||||
defaults.foreground = cast(u32)0x171717ff
|
||||
defaults.border = cast(u32)0xd1d5dbff
|
||||
defaults.border_width = 1.0
|
||||
defaults.radius = 4.0
|
||||
defaults.opacity = 1.0
|
||||
defaults.font_size = 14.0
|
||||
defaults.padding_x = 8.0
|
||||
defaults.padding_y = 7.0
|
||||
defaults.gap = 2.0
|
||||
if kind == StyleKindTreeViewItem() {
|
||||
defaults.background = cast(u32)0x00000000
|
||||
defaults.border = cast(u32)0x00000000
|
||||
defaults.border_width = 0.0
|
||||
if state == ButtonStateHover {
|
||||
defaults.background = cast(u32)0xe5e7ebff
|
||||
} else if state == ButtonStatePressed {
|
||||
defaults.background = cast(u32)0xd1d5dbff
|
||||
} else if state == ButtonStateSelected {
|
||||
defaults.background = cast(u32)0xdbeafeff
|
||||
defaults.foreground = cast(u32)0x1d4ed8ff
|
||||
}
|
||||
}
|
||||
if state == ButtonStateDisabled { defaults.opacity = 0.45 }
|
||||
facts: StyleFacts = StyleControlRoleFacts(kind, name,
|
||||
class_name, StyleAny(), cast(s32)ButtonToneNeutral,
|
||||
cast(s32)ButtonEmphasisFilled, cast(s32)ControlSizeMedium, state)
|
||||
frame: StyleFrame
|
||||
frame.value = ResolveInstalledStyleRules(defaults,
|
||||
facts, state)
|
||||
return frame
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewScrollFace :: (kind: s32, class_name: s32,
|
||||
disabled: bool) -> StyleFrame {
|
||||
defaults: StyleData
|
||||
defaults.fields = cast(u32)StyleBackground | cast(u32)StyleRadius |
|
||||
cast(u32)StyleOpacity | cast(u32)StyleIconSize |
|
||||
cast(u32)StylePaddingX
|
||||
defaults.background = cast(u32)0xe5e7ebff
|
||||
defaults.radius = 4.0
|
||||
defaults.opacity = 1.0
|
||||
defaults.icon_size = 8.0
|
||||
defaults.padding_x = 2.0
|
||||
if kind == StyleKindScrollThumb() {
|
||||
defaults.background = cast(u32)0x9ca3afff
|
||||
defaults.icon_size = 16.0
|
||||
}
|
||||
state: s32 = ButtonStateNormal
|
||||
if disabled { state = ButtonStateDisabled }
|
||||
facts: StyleFacts = StyleControlRoleFacts(kind, 0,
|
||||
class_name, StyleAny(), cast(s32)ButtonToneNeutral,
|
||||
cast(s32)ButtonEmphasisFilled, cast(s32)ControlSizeMedium, state)
|
||||
frame: StyleFrame
|
||||
frame.value = ResolveInstalledStyleRules(defaults,
|
||||
facts, state)
|
||||
return frame
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewThumbKey :: () -> u64 {
|
||||
return cast(u64)4294967295
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewNavigationIndex :: (items: []TreeItem, selected_id: s32,
|
||||
navigation: TreeViewNavigation) -> s32 {
|
||||
if navigation == cast(TreeViewNavigation)TreeViewNavigationNone ||
|
||||
(cast(s32)items.count) <= 0 { return -1 }
|
||||
current: s32 = -1
|
||||
index: s32 = 0
|
||||
while index < (cast(s32)items.count) {
|
||||
if items[index].id == selected_id {
|
||||
current = index
|
||||
break
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
direction: s32 = 1
|
||||
candidate: s32 = 0
|
||||
if navigation == cast(TreeViewNavigation)TreeViewNavigationEnd {
|
||||
direction = -1
|
||||
candidate = (cast(s32)items.count) - 1
|
||||
} else if navigation == cast(TreeViewNavigation)TreeViewNavigationUp {
|
||||
direction = -1
|
||||
candidate = current - 1
|
||||
if current < 0 { candidate = (cast(s32)items.count) - 1 }
|
||||
} else if navigation == cast(TreeViewNavigation)TreeViewNavigationDown {
|
||||
candidate = current + 1
|
||||
} else if navigation != cast(TreeViewNavigation)TreeViewNavigationHome {
|
||||
return -1
|
||||
}
|
||||
while candidate >= 0 && candidate < (cast(s32)items.count) {
|
||||
if items[candidate].selectable { return candidate }
|
||||
candidate += direction
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewRevealScroll :: (index: s32, row_height: s32,
|
||||
viewport_height: s32, scroll: s32, max_scroll: s32) -> s32 {
|
||||
if index < 0 || row_height <= 0 { return ScrollClamp(scroll, max_scroll) }
|
||||
top: s64 = cast(s64)index * cast(s64)row_height
|
||||
bottom: s64 = top + cast(s64)row_height
|
||||
next: s64 = cast(s64)scroll
|
||||
if top < next {
|
||||
next = top
|
||||
} else if bottom > next + cast(s64)viewport_height {
|
||||
next = bottom - cast(s64)viewport_height
|
||||
}
|
||||
if next < 0 { next = 0 }
|
||||
if next > cast(s64)max_scroll { next = cast(s64)max_scroll }
|
||||
return cast(s32)next
|
||||
}
|
||||
|
||||
// Items and view state are application values. Each visible row is a retained
|
||||
// selectable node whose bounds are clipped to the viewport for pointer input.
|
||||
#program_export
|
||||
TreeView :: (session: Session, props: TreeViewProps, items: []TreeItem) -> TreeViewResult {
|
||||
result: TreeViewResult
|
||||
result.node = -1
|
||||
result.selected_id = props.selected_id
|
||||
bounds: Rectangle = props.bounds
|
||||
parent: Rectangle = TreeCurrentParentBounds(session)
|
||||
if bounds.width <= 0.0 { bounds.width = parent.width }
|
||||
if bounds.height <= 0.0 { bounds.height = parent.height }
|
||||
measured_bounds: Rectangle = bounds
|
||||
scale: float32 = props.scale
|
||||
if scale <= 0.0 { scale = 1.0 }
|
||||
panel_state: s32 = ButtonStateNormal
|
||||
if props.disabled { panel_state = ButtonStateDisabled }
|
||||
panel: StyleFrame = TreeViewFace(StyleKindTreeView(), props.id,
|
||||
props.class_name, panel_state)
|
||||
item_face: StyleFrame = TreeViewFace(StyleKindTreeViewItem(), 0,
|
||||
props.class_name, ButtonStateNormal)
|
||||
metrics: TreeViewMetrics = TreeViewMetricsFor(scale, panel, item_face)
|
||||
row_height: s32 = TreeViewRowHeight(props.row_height, scale, metrics)
|
||||
if row_height <= 0 { row_height = 1 }
|
||||
content_height: s32 = TreeViewContentHeight((cast(s32)items.count), row_height)
|
||||
max_scroll: s32 = TreeViewMaxScroll(cast(s32)bounds.height, content_height)
|
||||
scroll: s64 = cast(s64)props.scroll_offset
|
||||
if !props.disabled { scroll += cast(s64)props.scroll_delta }
|
||||
if scroll < 0 { scroll = 0 }
|
||||
if scroll > cast(s64)max_scroll { scroll = cast(s64)max_scroll }
|
||||
result.scroll_offset = cast(s32)scroll
|
||||
key: u64 = props.key
|
||||
if key == cast(u64)0 && props.id > 0 { key = cast(u64)cast(u32)props.id }
|
||||
if key == cast(u64)0 { key = TreeNextKey(session) }
|
||||
if TreeIsBuilding(session) {
|
||||
result.node = TreeSubmitCurrent(session, key, WidgetKindTreeView, bounds)
|
||||
if result.node < 0 { return result }
|
||||
bounds = TreeSubmittedNodeAt(session, result.node).bounds
|
||||
if !TreePushScope(session, result.node) { return result }
|
||||
TreeSetSemantic(session, result.node, cast(SemanticKind)SemanticTree, 0)
|
||||
}
|
||||
track_face: StyleFrame = TreeViewScrollFace(StyleKindScroll(),
|
||||
props.class_name, props.disabled)
|
||||
thumb_face: StyleFrame = TreeViewScrollFace(StyleKindScrollThumb(),
|
||||
props.class_name, props.disabled)
|
||||
scroll_metrics: ScrollMetrics = ScrollMetricsFor(scale,
|
||||
track_face, thumb_face)
|
||||
scroll_metrics.scrollbar_width = metrics.scrollbar_width
|
||||
has_scrollbar: bool = max_scroll > 0 && metrics.scrollbar_width > 0
|
||||
if has_scrollbar && TreeIsBuilding(session) && !props.disabled {
|
||||
previous_thumb: s32 = TreePrevious(session, result.node,
|
||||
TreeViewThumbKey(), WidgetKindSlider)
|
||||
drag: PointerDrag = TreeTakeDragAt(session, previous_thumb)
|
||||
if drag.active || drag.ended {
|
||||
initial_paint: ScrollBarPaint = ScrollBarPaintFor(
|
||||
cast(s32)(bounds.x + bounds.width) - metrics.scrollbar_width,
|
||||
cast(s32)bounds.y, cast(s32)bounds.height, content_height,
|
||||
result.scroll_offset, max_scroll, scroll_metrics)
|
||||
result.scroll_offset = ScrollDragOffsetFor(drag.y,
|
||||
initial_paint.track_bounds.y, drag.grab_y,
|
||||
max_scroll, initial_paint)
|
||||
}
|
||||
}
|
||||
if props.focused && !props.disabled {
|
||||
selected_index: s32 = TreeViewNavigationIndex(items,
|
||||
result.selected_id, props.navigation)
|
||||
if selected_index >= 0 {
|
||||
result.selected_id = items[selected_index].id
|
||||
result.scroll_offset = TreeViewRevealScroll(selected_index,
|
||||
row_height, cast(s32)bounds.height, result.scroll_offset,
|
||||
max_scroll)
|
||||
}
|
||||
}
|
||||
opacity: float32 = StyleOpacityValue(panel.value.fields,
|
||||
panel.value.opacity)
|
||||
PaintRoundedFill(session, result.node, measured_bounds, panel.value.radius, 12,
|
||||
ColorFromPacked(Opacity(panel.value.background, opacity)))
|
||||
if panel.value.border_width > 0.0 {
|
||||
PaintRoundedOutline(session, result.node, measured_bounds,
|
||||
panel.value.radius, 12, panel.value.border_width,
|
||||
ColorFromPacked(Opacity(panel.value.border, opacity)))
|
||||
}
|
||||
layout: TreeViewScrollLayout = TreeViewScrollFor(result.scroll_offset,
|
||||
row_height)
|
||||
visible: s32 = TreeViewVisibleRows(cast(s32)bounds.height, row_height)
|
||||
visible_index: s32 = 0
|
||||
while visible_index < visible &&
|
||||
layout.first + visible_index < (cast(s32)items.count) {
|
||||
index: s32 = layout.first + visible_index
|
||||
item: TreeItem = items[index]
|
||||
row: Rectangle = TreeViewRowBounds(bounds, visible_index,
|
||||
row_height, layout.y_offset)
|
||||
clipped: Rectangle = RectangleIntersection(row, bounds)
|
||||
if clipped.height > 0.0 && clipped.width > 0.0 {
|
||||
item_key: u64 = TreeViewRowKey(item, index)
|
||||
previous: s32 = -1
|
||||
if TreeIsBuilding(session) {
|
||||
previous = TreePrevious(session, result.node, item_key,
|
||||
WidgetKindSelectable)
|
||||
}
|
||||
activated: bool = TreeTakeActivationAt(session, previous)
|
||||
if activated && !props.disabled && item.selectable {
|
||||
result.changed = result.selected_id != item.id
|
||||
result.selected_id = item.id
|
||||
}
|
||||
selected: bool = result.selected_id == item.id
|
||||
state: s32 = ResolveState(cast(s32)ButtonStateAuto,
|
||||
props.disabled || !item.selectable, false,
|
||||
TreePressedAt(session, previous), TreeHoveredAt(session, previous),
|
||||
false, selected)
|
||||
face: StyleFrame = TreeViewFace(StyleKindTreeViewItem(),
|
||||
item.id, props.class_name, state)
|
||||
node: s32 = -1
|
||||
if TreeIsBuilding(session) {
|
||||
node = TreeSubmitCurrent(session, item_key, WidgetKindSelectable,
|
||||
clipped)
|
||||
if node < 0 { break }
|
||||
TreeSetInteractive(session, node, props.disabled || !item.selectable,
|
||||
false, item.id)
|
||||
TreeSetSelected(session, node, selected)
|
||||
TreeSetLabel(session, node, item.label)
|
||||
TreeSetSemantic(session, node, cast(SemanticKind)SemanticTreeItem, 0)
|
||||
}
|
||||
item_opacity: float32 = StyleOpacityValue(face.value.fields,
|
||||
face.value.opacity)
|
||||
if face.value.background != cast(u32)0 {
|
||||
PaintRoundedFill(session, node, clipped, face.value.radius, 12,
|
||||
ColorFromPacked(Opacity(face.value.background,
|
||||
item_opacity)))
|
||||
}
|
||||
font: s32 = ResolveFont(0,
|
||||
StyleFontValue(face.value.fields, face.value.font_size), 14)
|
||||
line_height: s32 = GlyphLineHeight(font, face.value.typeface)
|
||||
marker: Rectangle = TreeViewMarkerBounds(row, item.depth,
|
||||
metrics)
|
||||
label: Rectangle = TreeViewTextBounds(row, item.depth, metrics)
|
||||
paint: TreeViewTextPaint = TreeViewTextPaintFor(marker, label,
|
||||
line_height)
|
||||
text_color: Color = ColorFromPacked(Opacity(
|
||||
face.value.foreground, item_opacity))
|
||||
marker_clip: Rectangle = RectangleIntersection(marker, bounds)
|
||||
label_clip: Rectangle = RectangleIntersection(label, bounds)
|
||||
PaintClippedLabel(session, node, TreeViewMarkerText(item.expanded),
|
||||
paint.marker_x, paint.marker_y, font, text_color,
|
||||
marker_clip)
|
||||
PaintClippedLabel(session, node, item.label, paint.text_x,
|
||||
paint.text_y, font, text_color, label_clip)
|
||||
}
|
||||
visible_index += 1
|
||||
}
|
||||
if has_scrollbar {
|
||||
bar: ScrollBarPaint = ScrollBarPaintFor(
|
||||
cast(s32)(bounds.x + bounds.width) - metrics.scrollbar_width,
|
||||
cast(s32)bounds.y, cast(s32)bounds.height, content_height,
|
||||
result.scroll_offset, max_scroll, scroll_metrics)
|
||||
track_node: s32 = -1
|
||||
thumb_node: s32 = -1
|
||||
if TreeIsBuilding(session) {
|
||||
track_node = TreeSubmitCurrent(session, TreeViewThumbKey() + cast(u64)1,
|
||||
WidgetKindCustom, bar.track_bounds)
|
||||
thumb_node = TreeSubmitCurrent(session, TreeViewThumbKey(),
|
||||
WidgetKindSlider, bar.thumb_bounds)
|
||||
TreeSetInteractive(session, thumb_node, props.disabled, false, props.id)
|
||||
}
|
||||
PaintRoundedFill(session, track_node, bar.track_bounds,
|
||||
track_face.value.radius, 12,
|
||||
ColorFromPacked(Opacity(track_face.value.background,
|
||||
StyleOpacityValue(track_face.value.fields,
|
||||
track_face.value.opacity))))
|
||||
PaintRoundedFill(session, thumb_node, bar.thumb_bounds,
|
||||
thumb_face.value.radius, 12,
|
||||
ColorFromPacked(Opacity(thumb_face.value.background,
|
||||
StyleOpacityValue(thumb_face.value.fields,
|
||||
thumb_face.value.opacity))))
|
||||
}
|
||||
if TreeIsBuilding(session) { End(session) }
|
||||
result.changed = result.selected_id != props.selected_id
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#import "kryon/geometry"
|
||||
|
||||
TreeItem :: struct {
|
||||
label: string
|
||||
depth: s32
|
||||
id: s32
|
||||
expanded: bool
|
||||
selectable: bool
|
||||
}
|
||||
|
||||
TreeViewNavigation :: enum {
|
||||
TreeViewNavigationNone :: 0
|
||||
TreeViewNavigationHome :: 1
|
||||
TreeViewNavigationEnd :: 2
|
||||
TreeViewNavigationUp :: 3
|
||||
TreeViewNavigationDown :: 4
|
||||
}
|
||||
|
||||
// Items are a borrowed slice passed to TreeView, not a pointer in this record.
|
||||
// The caller stores the returned selection and scroll value between frames.
|
||||
TreeViewProps :: struct {
|
||||
key: u64
|
||||
bounds: Rectangle
|
||||
id: s32
|
||||
class_name: s32
|
||||
selected_id: s32
|
||||
scroll_offset: s32
|
||||
scroll_delta: s32
|
||||
row_height: s32
|
||||
scale: float32
|
||||
focused: bool
|
||||
navigation: TreeViewNavigation
|
||||
disabled: bool
|
||||
}
|
||||
|
||||
TreeViewResult :: struct {
|
||||
node: s32
|
||||
selected_id: s32
|
||||
scroll_offset: s32
|
||||
changed: bool
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#import "TableView"
|
||||
|
||||
// Keyboard selection clamps to the rows that exist.
|
||||
#program_export
|
||||
main :: () -> s32 {
|
||||
if TableViewSelectedRowFor(8, 3) != 2 { return 1 }
|
||||
if TableViewSelectedRowFor(-1, 3) != 0 { return 2 }
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
#import "kryon/session"
|
||||
test_session: Session;
|
||||
TestSession :: () -> Session {
|
||||
if !SessionValid(test_session) { test_session = SessionOpen() }
|
||||
return test_session
|
||||
}
|
||||
|
||||
#import "kryon/geometry"
|
||||
#import "kryon/paint_queue"
|
||||
#import "kryon/semantic"
|
||||
#import "kryon/tree"
|
||||
#import "kryon/tree_input"
|
||||
#import "tree_view"
|
||||
#import "tree_view_props"
|
||||
#import "kryon/widget_kind"
|
||||
#import "tree_view_host"
|
||||
|
||||
using SemanticKind;
|
||||
using TreeViewNavigation;
|
||||
using WidgetKind;
|
||||
|
||||
phase: s32;
|
||||
selected: s32;
|
||||
scroll: s32;
|
||||
|
||||
#program_export
|
||||
Frame :: () -> s32 {
|
||||
items: [3]TreeItem
|
||||
items[0] = TreeItem.{"First", 0, 1, false, true}
|
||||
items[1] = TreeItem.{"Second", 1, 2, true, true}
|
||||
items[2] = TreeItem.{"Third", 2, 3, false, true}
|
||||
if phase == 8 { items[1].selectable = false }
|
||||
props: TreeViewProps
|
||||
props.key = cast(u64)20
|
||||
props.bounds = Rectangle.{10.0, 10.0, 120.0, 48.0}
|
||||
props.row_height = 20
|
||||
props.selected_id = selected
|
||||
props.scroll_offset = scroll
|
||||
if phase == 0 { props.selected_id = 1 }
|
||||
if phase == 1 { props.scroll_delta = 12 }
|
||||
if phase == 2 {
|
||||
props.disabled = true
|
||||
props.scroll_delta = 100
|
||||
}
|
||||
if phase == 3 { props.scroll_offset = 0 }
|
||||
if phase >= 6 { props.focused = true }
|
||||
if phase == 6 || phase == 8 {
|
||||
props.navigation = cast(TreeViewNavigation)TreeViewNavigationUp
|
||||
}
|
||||
if phase == 7 { props.navigation = cast(TreeViewNavigation)TreeViewNavigationEnd }
|
||||
if phase == 9 {
|
||||
props.navigation = cast(TreeViewNavigation)TreeViewNavigationHome
|
||||
props.disabled = true
|
||||
}
|
||||
if phase == 10 {
|
||||
props.navigation = cast(TreeViewNavigation)TreeViewNavigationDown
|
||||
}
|
||||
if phase == 11 {
|
||||
props.navigation = cast(TreeViewNavigation)TreeViewNavigationHome
|
||||
}
|
||||
TreeStart(TestSession(), cast(u64)1, Rectangle.{0.0, 0.0, 160.0, 100.0})
|
||||
result: TreeViewResult = TreeView(TestSession(), props, items[0:3])
|
||||
if !TreeFinish(TestSession()) || TreeCount(TestSession()) != 7 || result.node != 1 ||
|
||||
TreeNodeAt(TestSession(), 1).semantic_kind != cast(SemanticKind)SemanticTree ||
|
||||
TreeNodeAt(TestSession(), 3).semantic_kind != cast(SemanticKind)SemanticTreeItem ||
|
||||
TreeNodeAt(TestSession(), 3).semantic_label != "Second" ||
|
||||
TreeNodeAt(TestSession(), 6).kind != WidgetKindSlider { return -10 }
|
||||
if phase == 0 {
|
||||
if result.selected_id != 1 || result.changed ||
|
||||
result.scroll_offset != 0 ||
|
||||
TreeNodeAt(TestSession(), 4).bounds.height != 8.0 ||
|
||||
TreeHitAt(TestSession(), 20.0, 59.0) != -1 { return -1 }
|
||||
TreePointerUpdate(TestSession(), PointerFrame.{20.0, 35.0, true, true, false})
|
||||
TreePointerUpdate(TestSession(), PointerFrame.{20.0, 35.0, false, false, true})
|
||||
} else if phase == 1 {
|
||||
if result.selected_id != 2 || !result.changed ||
|
||||
result.scroll_offset != 12 ||
|
||||
TreeNodeAt(TestSession(), 2).bounds.y != 10.0 ||
|
||||
TreeNodeAt(TestSession(), 2).bounds.height != 8.0 ||
|
||||
TreeHitAt(TestSession(), 20.0, 9.0) != -1 { return -2 }
|
||||
} else if phase == 2 {
|
||||
if result.selected_id != 2 || result.changed ||
|
||||
result.scroll_offset != 12 ||
|
||||
TreeHitAt(TestSession(), 20.0, 25.0) != -1 { return -3 }
|
||||
} else if phase == 3 {
|
||||
if result.selected_id != 2 || result.scroll_offset != 0 ||
|
||||
TreeNodeAt(TestSession(), 6).bounds.y != 10.0 ||
|
||||
TreeHitAt(TestSession(), 126.0, 20.0) != 6 { return -4 }
|
||||
TreePointerUpdate(TestSession(), PointerFrame.{126.0, 20.0, true, true, false})
|
||||
TreePointerUpdate(TestSession(), PointerFrame.{126.0, 40.0, true, false, false})
|
||||
} else if phase == 4 {
|
||||
if result.selected_id != 2 || result.scroll_offset != 7 ||
|
||||
result.changed { return -5 }
|
||||
TreePointerUpdate(TestSession(), PointerFrame.{126.0, 45.0, false, false, true})
|
||||
} else if phase == 5 {
|
||||
if result.selected_id != 2 || result.scroll_offset != 9 ||
|
||||
result.changed { return -6 }
|
||||
} else if phase == 6 {
|
||||
if result.selected_id != 1 || result.scroll_offset != 0 ||
|
||||
!result.changed { return -7 }
|
||||
} else if phase == 7 {
|
||||
if result.selected_id != 3 || result.scroll_offset != 12 ||
|
||||
!result.changed { return -8 }
|
||||
} else if phase == 8 {
|
||||
if result.selected_id != 1 || result.scroll_offset != 0 ||
|
||||
!result.changed { return -9 }
|
||||
} else if phase == 9 {
|
||||
if result.selected_id != 1 || result.scroll_offset != 0 ||
|
||||
result.changed { return -11 }
|
||||
} else if phase == 10 {
|
||||
if result.selected_id != 2 || result.scroll_offset != 0 ||
|
||||
!result.changed { return -12 }
|
||||
} else {
|
||||
if result.selected_id != 1 || result.scroll_offset != 0 ||
|
||||
!result.changed { return -13 }
|
||||
}
|
||||
PaintFlush(TestSession())
|
||||
selected = result.selected_id
|
||||
scroll = result.scroll_offset
|
||||
old: s32 = phase
|
||||
phase += 1
|
||||
return old
|
||||
}
|
||||
|
||||
#program_export
|
||||
main :: () -> s32 {
|
||||
index: s32 = 0
|
||||
while index < 12 {
|
||||
if Frame() != index || TreeViewHostFailed() ||
|
||||
TreeViewLabelCount() != (index + 1) * 6 { return 1 }
|
||||
index += 1
|
||||
}
|
||||
if TreeViewFillCount() < 6 { return 2 }
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#import "kryon/drawing_props"
|
||||
#import "kryon/geometry"
|
||||
|
||||
fills: s32;
|
||||
labels: s32;
|
||||
failed: bool;
|
||||
|
||||
#program_export
|
||||
MeasureGlyphWidth :: (value: string, font: s32,
|
||||
typeface: string) -> s32 {
|
||||
unused value
|
||||
unused font
|
||||
unused typeface
|
||||
return 0
|
||||
}
|
||||
|
||||
#program_export
|
||||
MeasureGlyphLineHeight :: (font: s32, typeface: string) -> s32 {
|
||||
if font != 14 || typeface.count != 0 { failed = true }
|
||||
return 12
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterRoundedRectangle :: (bounds: Rectangle, radius: float32,
|
||||
segments: s32, color: Color) {
|
||||
unused radius
|
||||
unused segments
|
||||
unused color
|
||||
if bounds.x < 10.0 || bounds.y < 10.0 ||
|
||||
bounds.x + bounds.width > 130.0 ||
|
||||
bounds.y + bounds.height > 58.0 { failed = true }
|
||||
fills += 1
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterRoundedRectangleOutline :: (bounds: Rectangle, radius: float32,
|
||||
segments: s32, width: float32, color: Color) {
|
||||
unused radius
|
||||
unused segments
|
||||
unused width
|
||||
unused color
|
||||
if bounds.x != 10.0 || bounds.y != 10.0 ||
|
||||
bounds.width != 120.0 || bounds.height != 48.0 { failed = true }
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterLine :: (line: Rectangle, color: Color) {
|
||||
unused line
|
||||
unused color
|
||||
failed = true
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterText :: (value: string, x: s32, y: s32, font: s32,
|
||||
color: Color) {
|
||||
unused value
|
||||
unused x
|
||||
unused y
|
||||
unused font
|
||||
unused color
|
||||
failed = true
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTextClipped :: (value: string, x: s32, y: s32, font: s32,
|
||||
color: Color, clip: Rectangle) {
|
||||
unused value
|
||||
unused x
|
||||
unused y
|
||||
unused color
|
||||
if font != 14 || clip.x < 10.0 || clip.y < 10.0 ||
|
||||
clip.x + clip.width > 130.0 ||
|
||||
clip.y + clip.height > 58.0 { failed = true }
|
||||
labels += 1
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterImage :: (asset_path: string, texture_id: u32,
|
||||
source: Rectangle, destination: Rectangle, clip: Rectangle,
|
||||
origin: Vector2, rotation: float32, radius: float32,
|
||||
tint: Color) {
|
||||
unused asset_path
|
||||
unused texture_id
|
||||
unused source
|
||||
unused destination
|
||||
unused clip
|
||||
unused origin
|
||||
unused rotation
|
||||
unused radius
|
||||
unused tint
|
||||
failed = true
|
||||
}
|
||||
|
||||
#program_export
|
||||
TreeViewHostFailed :: () -> bool { return failed }
|
||||
|
||||
#program_export
|
||||
TreeViewLabelCount :: () -> s32 { return labels }
|
||||
|
||||
#program_export
|
||||
TreeViewFillCount :: () -> s32 { return fills }
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"format": 1,
|
||||
"packages": [
|
||||
{
|
||||
"commit": "42c649dab1c97213b0ffd84d673fde3ec5a4b950",
|
||||
"dependencies": {"raylib": "p5a77c9c35110e925"},
|
||||
"id": "p4c79176f910b74b8",
|
||||
"name": "Kryon",
|
||||
"ref": "master",
|
||||
"url": "https://github.com/kryonlabs/kryon.git"
|
||||
},
|
||||
{
|
||||
"commit": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e",
|
||||
"dependencies": {},
|
||||
"id": "p5a77c9c35110e925",
|
||||
"name": "raylib",
|
||||
"ref": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e",
|
||||
"source": true,
|
||||
"url": "https://github.com/raysan5/raylib.git"
|
||||
}
|
||||
],
|
||||
"root": {
|
||||
"dependencies": {"kryon": "p4c79176f910b74b8"},
|
||||
"name": "DataViews"
|
||||
},
|
||||
"toolchain": {
|
||||
"commit": "363b2ec5461aa1ec457176b2acf77fc9b92f2175",
|
||||
"ref": "master",
|
||||
"url": "https://github.com/ziranlang/ziran.git"
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "DataViews"
|
||||
module_roots = ["src", "tests"]
|
||||
|
||||
[toolchain]
|
||||
git = "https://github.com/ziranlang/ziran.git"
|
||||
ref = "master"
|
||||
|
||||
[dependencies.kryon]
|
||||
git = "https://github.com/kryonlabs/kryon.git"
|
||||
ref = "master"
|
||||
|
||||
[exports]
|
||||
TableView = "src/TableView/module.zi"
|
||||
TreeView = "src/TreeView/module.zi"
|
||||
Reference in new issue
Block a user