Bring pictures, text input and scroll devices only with the widgets that use them
The desktop rasterizer loads, decodes and smooth-copies file pictures once a program first asks a picture's size, which every widget that draws one does first, so vector icons and managed pixels draw without decoders, threads or asset paths. LanczosSnap is geometry's RectangleSnap, so a texture draw no longer reaches the Lanczos cache. A button reaches file pictures and atlas icons through the new image_lookup. kryon/image is now image_files, which re-exports the Image widget (image) and fills the pictures; kryon/icon fills the atlas. Library code imports image itself, so importing a picture-capable widget registers nothing. Navigation, copy and confirm buttons and the widget host fill the lookup where they draw, as they reached pictures before. Props modules that only name Image.Props import image_props, now also exported; unused image imports are gone. The frame and the accessibility host reach text requests and editor focus through text_editing, which text_request and text_input_platform fill, and the frame samples scrolls through scroll_sampling, which scroll_device fills. Desktop examples (C files, C bytes, executable), before -> after: button 96, 1 411 582, 448 264 -> 70, 980 794, 342 016 text 95, 1 445 077, 462 504 -> 71, 1 020 207, 356 472 textfield 107, 1 580 157, 514 496 -> 84, 1 166 840, 409 840 make pay-per-import-test checks button and textfield; tests whose programs no longer reach pictures lose their picture bindings and stubs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
389bf25e17
commit
15c3a22e43
61 files changed
+349
-131
No files matched your search
@@ -63,7 +63,11 @@ Nothing is imported by default. A program carries only the code for what it
|
||||
imports and uses. A bare window carries the window, its events and
|
||||
presenting; import a frame and you get a frame, import a rectangle and you get
|
||||
a rectangle. Optional features arrive through their import or first use, never
|
||||
through runtime flags. Make generated code smaller by cutting what isn't
|
||||
through runtime flags. Shared code reaches an optional part through a small
|
||||
slot module (such as `frame_driver`, `image_lookup`, `text_editing` and
|
||||
`scroll_sampling`) that the part's own module fills from its initializer or
|
||||
first use; shared code never imports the part itself. Make generated code
|
||||
smaller by cutting what isn't
|
||||
needed, never by merging files (owner, 2026-11-15).
|
||||
|
||||
One widget concept has one public implementation. `Text.Draw(Text.Props)` and
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
- A bare window checks only itself: `kryon/app` keeps each platform's window
|
||||
(`desktop_window`, new `page_window`) apart from its frame loop
|
||||
(`frames_desktop`, `frames_web`).
|
||||
- Pictures, text input and scroll devices come only with the widgets that
|
||||
use them; a button without an icon carries no decoders or asset paths.
|
||||
Its file pictures come with `kryon/image`, its icons with `kryon/icon`.
|
||||
- Empty desktop windows omit image decoding, smooth scaling, video and threads.
|
||||
Import `kryon/cursor` for picture cursors in custom widget hosts. Native
|
||||
desktop project builds link X11 correctly.
|
||||
|
||||
@@ -147,6 +147,13 @@ height instead of staying at the styled icon size: up to 64 units above the
|
||||
label, or up to 40 units beside it. A vector `icon_shape` still takes
|
||||
precedence over an `image` and keeps the styled size.
|
||||
|
||||
A button draws only the icons its program imports. A vector `icon_shape` and
|
||||
pixels handed over as `image.texture` always draw. A file picture in
|
||||
`image.asset_path` draws once the program imports `kryon/image`, and a
|
||||
built-in `icon_type` once it also imports `kryon/icon`. A button without an
|
||||
icon carries no picture decoder, asset path or icon atlas. The same holds for
|
||||
pictures a toolbar, title bar or modal header hands to its buttons.
|
||||
|
||||
## Breadcrumbs
|
||||
|
||||
`Breadcrumb.Draw(session: Session, props: Breadcrumb.Props, items: []Breadcrumb.BreadcrumbItem)
|
||||
|
||||
@@ -12,9 +12,9 @@ window plus what it imports. This overrides the 2026-11-13 plan's choice to
|
||||
keep accessibility in every program: an empty window keeps only window-level
|
||||
accessibility, and widget roles and nodes come with the widget imports.
|
||||
|
||||
Status: in progress. The empty window is done (17 KB executable, pushed);
|
||||
frame examples still carry pictures, text input and gamepad code they don't
|
||||
import (see "Modules outside an example's imports" and Steps).
|
||||
Status: in progress. The empty window is done (17 KB executable, pushed).
|
||||
Pictures, text input and scroll devices arrive with the widgets that use them
|
||||
(see "Pictures, text input and scroll devices"); open work is in Steps.
|
||||
|
||||
## Measurement
|
||||
|
||||
@@ -179,6 +179,32 @@ today's Ziran:
|
||||
Window, hello and box shrank by the empty-window work. Button, image and text
|
||||
grew by a few files: today's Kryon adds modules their widget imports reach.
|
||||
|
||||
### Pictures, text input and scroll devices
|
||||
|
||||
Before is Kryon 389bf25e, after adds this step; the same tree, sources and
|
||||
Ziran, one build at a time through the build queue:
|
||||
|
||||
| Example | Before C files | Before C bytes | Before exe | After C files | After C bytes | After exe |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| box | 60 | 836 562 | 284 744 | 59 | 826 953 | 284 720 |
|
||||
| button | 96 | 1 411 582 | 448 264 | 70 | 980 794 | 342 016 |
|
||||
| image | 87 | 1 320 554 | 415 400 | 88 | 1 314 034 | 416 144 |
|
||||
| text | 95 | 1 445 077 | 462 504 | 71 | 1 020 207 | 356 472 |
|
||||
| textfield | 107 | 1 580 157 | 514 496 | 84 | 1 166 840 | 409 840 |
|
||||
|
||||
Box, button, image and text no longer carry `text_request`,
|
||||
`text_input_platform` or `scroll_device`; button, text and textfield no
|
||||
longer carry the picture chain (textfield keeps its text input). The desktop
|
||||
rasterizer registers file pictures when a program first asks a picture's
|
||||
size. A button reaches file pictures and
|
||||
atlas icons through `image_lookup`: `kryon/image` (`image_files`, the export)
|
||||
fills the pictures and `kryon/icon` the atlas, while library code imports
|
||||
`image` itself, which registers nothing. Toolbar, title bar and modal header
|
||||
pictures reach their buttons the same way; navigation, copy and confirm
|
||||
buttons and the widget host fill the lookup where they draw, as they reached
|
||||
pictures before. Image's executable grew by 744 bytes (the lookup, its
|
||||
initializer and `image_files`) while its C shrank.
|
||||
|
||||
### Modules outside an example's imports
|
||||
|
||||
All 88 frame examples carry these although their `.zi` imports do not name
|
||||
@@ -188,10 +214,7 @@ them (`examples/window.zi` and `examples/hello.zi`, the two `App.Show` and
|
||||
| Module | Likely caller |
|
||||
| --- | --- |
|
||||
| `cursor` | `src/ui/tree.zi`, `src/ui/tree_frame.zi`, `src/ui/tree_input.zi` (any widget reaches `tree`) |
|
||||
| `scroll_device` | `src/ui/tree_draw.zi`, `src/ui/tree_frame.zi`, `src/ui/tree_input.zi`, `src/ui/scroll/scroll.zi`, `src/ui/tabs/tabs.zi`, `src/ui/textarea/textarea.zi`, `src/ui/gridmulti/gridmulti.zi` |
|
||||
| `gamepad_navigation` | `src/ui/tree_frame.zi` |
|
||||
| `text_request` | `src/ui/tree_draw.zi`, `src/ui/text_boundary.zi`, `src/ui/textarea/textarea.zi`, `src/ui/textfield/textfield.zi` |
|
||||
| `text_input_platform` | `src/ui/tree_draw.zi`, `src/ui/textarea/textarea.zi`, `src/ui/textfield/textfield.zi` |
|
||||
| `program_title` | `src/backend/desktop_loop.zi`, `src/backend/desktop_runtime.zi`, `src/backend/cairo_raster.zi` |
|
||||
| `accessibility_linux` | `src/backend/desktop_loop.zi`, `src/backend/accessibility_tree_linux.zi` |
|
||||
| `accessibility_tree_linux` | `src/backend/app_host_desktop.zi`, `src/backend/desktop_run.zi` |
|
||||
@@ -290,18 +313,18 @@ same way (`AccessibilityTreeUse()`).
|
||||
|
||||
Open work only; finished steps are described in Design and pushed.
|
||||
|
||||
- [ ] Pictures only with a picture: `cairo_raster` reaches `image_decode_linux`
|
||||
and `lanczos_cache` directly (lines 263 and 270), and `button` imports
|
||||
`kryon/image` for its icon slot, so 58 frame examples carry the decoders,
|
||||
threads and asset paths without drawing a picture. Register the picture
|
||||
path from the module that draws a picture; a button without an icon
|
||||
carries none of it.
|
||||
- [ ] Text input only with a text field: `tree_draw` reaches `text_request`
|
||||
and `text_input_platform` in every frame example.
|
||||
- [ ] Gamepad navigation and scroll devices only through the widgets or
|
||||
inputs that use them (`tree_frame`, `tree_draw`).
|
||||
- [ ] Extend `make pay-per-import-test` to assert each of the above (box and
|
||||
button carry no decoder or text input; image and textfield do).
|
||||
- [ ] Widgets whose picture is optional data still reach the picture chain
|
||||
without a picture once the widget draws: `text_area`'s image blocks,
|
||||
dropdown option images, avatar, badge and carousel. A block's
|
||||
image is a bare path string an app sets without importing anything, so
|
||||
moving it to `image_lookup` (as button's icon is) would drop pictures from
|
||||
apps that never import `kryon/image`; ask the owner first. Measure the 88
|
||||
frame examples again afterwards.
|
||||
- [ ] Gamepad navigation (`GamepadNavigationKey`, about 700 bytes of C) is
|
||||
still in every frame program: it turns controller buttons into the
|
||||
navigation keys any focusable node takes, and focus is per-node tree data
|
||||
(an interactive kind, or a card or text with a focus id), so no import
|
||||
marks a program that can take focus. Leave it unless such a mark appears.
|
||||
- [ ] Eleven examples don't build today: ten chart and table examples fail
|
||||
with "unknown initializer field: font" (`Text.Props` still has `font`),
|
||||
and `flow` fails because `zi2c` exits 127. Find the cause and fix it, or
|
||||
|
||||
@@ -66,7 +66,7 @@ KRYON_RAW_SOURCES = [
|
||||
KRYON_PACKAGE_SOURCES = [
|
||||
('Text', 'text', 'text/text_props.zi',
|
||||
{'Props': 'TextProps', 'Range': 'TextRange', 'Wrap': 'TextWrap'}),
|
||||
('Image', 'image', 'image/image_props.zi', {'Props': 'ImageProps'}),
|
||||
('Image', 'image_props', 'image/image_props.zi', {'Props': 'ImageProps'}),
|
||||
('Button', 'button', 'button/button_props.zi', {'Props': 'ButtonProps'}),
|
||||
('TextField', 'text_field', 'textfield/text_field_props.zi',
|
||||
{'State': 'TextFieldState', 'Input': 'TextFieldInput', 'Props': 'TextFieldProps',
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#import "session"
|
||||
#import "tree"
|
||||
#import "tree_input"
|
||||
#import "text_request"
|
||||
#import "text_editing"
|
||||
#import "widget_kind"
|
||||
#import "accessibility_linux"
|
||||
// The GIO and GLib calls the tree's objects make; a foreign declaration
|
||||
@@ -377,7 +377,7 @@ NodeMethod :: (bus: *void, sender: *u8, path: *u8, iface: *u8,
|
||||
length: usize = 0
|
||||
pointer: *u8 = VGetString(child, *length)
|
||||
value: string = NativeText(pointer, output[:])
|
||||
ok: bool = length <= cast(usize)65536 && TextRequestSend(ui, index, value, true, cast(s32)value.count, cast(s32)value.count)
|
||||
ok: bool = length <= cast(usize)65536 && TextEditingRequest(ui, index, value, true, cast(s32)value.count, cast(s32)value.count)
|
||||
VUnref(child)
|
||||
result = TupleOne(VBool(cast(s32)ok))
|
||||
} else if name == "GetNSelections" {
|
||||
@@ -395,7 +395,7 @@ NodeMethod :: (bus: *void, sender: *u8, path: *u8, iface: *u8,
|
||||
if name == "SetCaretOffset" { start = ByteOffset(index, ArgumentInt(params, 0)); end = start }
|
||||
else if name == "AddSelection" { start = ByteOffset(index, ArgumentInt(params, 0)); end = ByteOffset(index, ArgumentInt(params, 1)) }
|
||||
else if name == "SetSelection" { start = ByteOffset(index, ArgumentInt(params, 1)); end = ByteOffset(index, ArgumentInt(params, 2)) }
|
||||
result = TupleOne(VBool(cast(s32)TextRequestSend(ui, index, "", false, end, start)))
|
||||
result = TupleOne(VBool(cast(s32)TextEditingRequest(ui, index, "", false, end, start)))
|
||||
}
|
||||
if result == null { result = AccessibleMethod(name) }
|
||||
ReplyResult(invocation, result)
|
||||
|
||||
+31
-11
@@ -308,7 +308,7 @@ ScaledImageFor :: (image: *void, source: Rectangle, destination: Rectangle, snap
|
||||
if matrix.xx != 1.0 || matrix.yy != 1.0 || matrix.xy != 0.0 || matrix.yx != 0.0 ||
|
||||
matrix.x0 != 0.0 || matrix.y0 != 0.0 { return null }
|
||||
width := ImageSurfaceWidth(image); height := ImageSurfaceHeight(image)
|
||||
snapped.* = Lanczos.LanczosSnap(destination)
|
||||
snapped.* = RectangleSnap(destination)
|
||||
if !Lanczos.LanczosEligible(source, width, height, snapped.*) { return null }
|
||||
key: Lanczos.LanczosKey = .{serial, 0, 0, source, cast(s32)snapped.width, cast(s32)snapped.height}
|
||||
CairoUseSmooth()
|
||||
@@ -331,6 +331,27 @@ ScaledImageFor :: (image: *void, source: Rectangle, destination: Rectangle, snap
|
||||
image_clock: u64;
|
||||
image_bytes: s64;
|
||||
|
||||
// File pictures arrive with the first picture a program asks the size of:
|
||||
// every widget that draws one lays it out from its size first (see
|
||||
// image_raster), so ImageWidth and ImageHeight register loading, decoding
|
||||
// and smooth copies. A program that draws only managed pixels, such as
|
||||
// vector icons, carries no decoder, asset path or Lanczos worker.
|
||||
RasterPictureLoad :: #type (asset_path: string) -> *void;
|
||||
RasterPictureSmooth :: #type (image: *void, source: Rectangle, destination: Rectangle,
|
||||
snapped: *Rectangle) -> *Lanczos.LanczosEntry;
|
||||
raster_picture_load: RasterPictureLoad;
|
||||
raster_picture_smooth: RasterPictureSmooth;
|
||||
CairoUsePictures :: () {
|
||||
raster_picture_load = LoadPNG
|
||||
raster_picture_smooth = ScaledImageFor
|
||||
}
|
||||
// A file picture once pictures are in use; a managed one always.
|
||||
CairoPictureFor :: (asset_path: string, texture_id: u32) -> *void {
|
||||
if texture_id != cast(u32)0 { return CairoManagedImage(texture_id) }
|
||||
if raster_picture_load == null { return null }
|
||||
return raster_picture_load(asset_path)
|
||||
}
|
||||
|
||||
SetColor :: (color: Color) {
|
||||
SetSourceRGBA(paint, cast(float64)color.r / 255.0,
|
||||
cast(float64)color.g / 255.0, cast(float64)color.b / 255.0,
|
||||
@@ -840,6 +861,7 @@ LoadPNG :: (original_path: string) -> *void {
|
||||
|
||||
#program_export
|
||||
ImageWidth :: (asset_path: string) -> s32 {
|
||||
CairoUsePictures()
|
||||
image: *void = LoadPNG(asset_path)
|
||||
if image == null { return 0 }
|
||||
return ImageSurfaceWidth(image)
|
||||
@@ -847,6 +869,7 @@ ImageWidth :: (asset_path: string) -> s32 {
|
||||
|
||||
#program_export
|
||||
ImageHeight :: (asset_path: string) -> s32 {
|
||||
CairoUsePictures()
|
||||
image: *void = LoadPNG(asset_path)
|
||||
if image == null { return 0 }
|
||||
return ImageSurfaceHeight(image)
|
||||
@@ -894,17 +917,16 @@ RasterImage :: (asset_path: string, texture_id: u32,
|
||||
image_error = true
|
||||
return
|
||||
}
|
||||
image: *void
|
||||
if texture_id != cast(u32)0 { image = CairoManagedImage(texture_id) }
|
||||
else { image = LoadPNG(asset_path) }
|
||||
image := CairoPictureFor(asset_path, texture_id)
|
||||
if image == null {
|
||||
image_error = true
|
||||
return
|
||||
}
|
||||
sampled: *Lanczos.LanczosEntry
|
||||
snapped: Rectangle
|
||||
if texture_id == cast(u32)0 && rotation == 0.0 && origin.x == 0.0 && origin.y == 0.0 && CurrentPaintSmooth() {
|
||||
sampled = ScaledImageFor(image, source, destination, *snapped)
|
||||
if texture_id == cast(u32)0 && raster_picture_smooth != null && rotation == 0.0 &&
|
||||
origin.x == 0.0 && origin.y == 0.0 && CurrentPaintSmooth() {
|
||||
sampled = raster_picture_smooth(image, source, destination, *snapped)
|
||||
}
|
||||
Save(paint)
|
||||
polygon := CurrentPaintPolygon()
|
||||
@@ -919,7 +941,7 @@ RasterImage :: (asset_path: string, texture_id: u32,
|
||||
matrix.xy == 0.0 && matrix.yx == 0.0 && matrix.x0 == 0.0 && matrix.y0 == 0.0
|
||||
// Cairo's aliased clip and the cached copy disagree at exact half
|
||||
// pixels. Round both to the copy's device edges, also while it loads.
|
||||
image_clip := ifx device_pixels then Lanczos.LanczosSnap(clip) else clip
|
||||
image_clip := ifx device_pixels then RectangleSnap(clip) else clip
|
||||
RoundBox(image_clip, radius)
|
||||
Clip(paint)
|
||||
if polygon.count >= 3 {
|
||||
@@ -952,7 +974,7 @@ RasterImage :: (asset_path: string, texture_id: u32,
|
||||
if device_pixels {
|
||||
covered := destination
|
||||
covered.x -= origin.x; covered.y -= origin.y
|
||||
covered = Lanczos.LanczosSnap(covered)
|
||||
covered = RectangleSnap(covered)
|
||||
CanvasRectangle(paint, covered.x, covered.y, covered.width, covered.height)
|
||||
Clip(paint)
|
||||
}
|
||||
@@ -1005,9 +1027,7 @@ RasterImageMesh :: (asset_path: string, texture_id: u32, source: Rectangle,
|
||||
image_error = true
|
||||
return
|
||||
}
|
||||
image: *void
|
||||
if texture_id != cast(u32)0 { image = CairoManagedImage(texture_id) }
|
||||
else { image = LoadPNG(asset_path) }
|
||||
image := CairoPictureFor(asset_path, texture_id)
|
||||
if image == null {
|
||||
image_error = true
|
||||
return
|
||||
|
||||
@@ -203,7 +203,7 @@ CanvasLanczosImage :: (index: s32, source: Rectangle, destination: Rectangle,
|
||||
f := WebGetNumber(matrix, page_names.f)
|
||||
if WebGetNumber(matrix, page_names.b) != 0.0 || WebGetNumber(matrix, page_names.c) != 0.0 ||
|
||||
!(a > 0.0) || !(d > 0.0) { return false }
|
||||
snapped := Lanczos.LanczosSnap(Rectangle.{cast(float32)(cast(float64)destination.x * a + e),
|
||||
snapped := RectangleSnap(Rectangle.{cast(float32)(cast(float64)destination.x * a + e),
|
||||
cast(float32)(cast(float64)destination.y * d + f), cast(float32)(cast(float64)destination.width * a),
|
||||
cast(float32)(cast(float64)destination.height * d)})
|
||||
if !Lanczos.LanczosEligible(source, texture.width, texture.height, snapped) { return false }
|
||||
|
||||
@@ -445,16 +445,6 @@ LanczosWait :: () -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
// The device pixels a cached draw covers: DESTINATION's edges rounded to
|
||||
// whole pixels.
|
||||
LanczosSnap :: (destination: Rectangle) -> Rectangle {
|
||||
left := LanczosFloor(destination.x + 0.5)
|
||||
top := LanczosFloor(destination.y + 0.5)
|
||||
right := LanczosFloor(destination.x + destination.width + 0.5)
|
||||
bottom := LanczosFloor(destination.y + destination.height + 0.5)
|
||||
return .{cast(float32)left, cast(float32)top, cast(float32)(right - left), cast(float32)(bottom - top)}
|
||||
}
|
||||
|
||||
// Whether SOURCE of a WIDTH by HEIGHT picture drawn over SNAPPED device
|
||||
// pixels is worth a Lanczos copy: a whole-pixel draw of the source at its
|
||||
// own size needs none.
|
||||
|
||||
@@ -307,7 +307,7 @@ PixmapSetImage :: (slot: s32, path: string, width: s32, height: s32, pixels: []u
|
||||
width := pixmap_image_widths[slot]; height := pixmap_image_heights[slot]
|
||||
count := cast(s64)width * height
|
||||
if width <= 0 || height <= 0 || PixmapSourceCount(slot) < count { return -1 }
|
||||
snapped.* = Lanczos.LanczosSnap(destination)
|
||||
snapped.* = RectangleSnap(destination)
|
||||
if !Lanczos.LanczosEligible(source, width, height, snapped.*) { return -1 }
|
||||
key: Lanczos.LanczosKey = .{PixmapLanczosContent(slot), pixmap_image_revisions[slot], PIXMAP_LANCZOS_SESSION,
|
||||
source, cast(s32)snapped.width, cast(s32)snapped.height}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#import "style"
|
||||
#import "tooltip_common"
|
||||
Text :: #import "kryon/text";
|
||||
Image :: #import "kryon/image";
|
||||
Image :: #import "kryon/image_props";
|
||||
Button :: #import "kryon/button";
|
||||
TextField :: #import "kryon/text_field";
|
||||
TextArea :: #import "kryon/text_area";
|
||||
|
||||
@@ -11,6 +11,8 @@ Fieldset :: #import "fieldset";
|
||||
GuidedTour :: #import "guidedtour";
|
||||
HoverCard :: #import "hovercard";
|
||||
Image :: #import "image";
|
||||
// Guests' buttons carry built-in icons (see image_lookup).
|
||||
#import "icon"
|
||||
InlineEdit :: #import "inlineedit";
|
||||
Modal :: #import "modal_frame";
|
||||
MoneyField :: #import "moneyfield";
|
||||
@@ -446,6 +448,8 @@ WidgetHostCall :: (context: *void, module: *u8, function: *u8,
|
||||
if !widget_host_active {
|
||||
return 0
|
||||
}
|
||||
// Guests' buttons carry file pictures.
|
||||
Image.ImageUsePictures()
|
||||
owner := TextFromCString(module)
|
||||
name := TextFromCString(function)
|
||||
if ModuleName(owner, "image_raster") &&
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Button :: #import "button_props";
|
||||
Image :: #import "image";
|
||||
Image :: #import "image_props";
|
||||
Theme :: #import "theme";
|
||||
// Portable compositions can submit the same public widget contract to a
|
||||
// retained UI host. The host binds this effect to the ordinary implementation;
|
||||
@@ -18,8 +18,8 @@ Theme :: #import "theme";
|
||||
#import "focus"
|
||||
#import "font_metrics"
|
||||
#import "geometry"
|
||||
#import "icon"
|
||||
#import "image_behavior"
|
||||
#import "image_lookup"
|
||||
#import "paint_queue"
|
||||
#import "style"
|
||||
#import "style_sheet"
|
||||
@@ -293,11 +293,12 @@ Theme :: #import "theme";
|
||||
radius + 2.0, 12, 2.0, ColorFromPacked(focus))
|
||||
}
|
||||
// A built-in icon_type is drawn from the icon atlas unless the caller
|
||||
// supplied its own image.
|
||||
// supplied its own image. Atlas icons come with kryon/icon and file
|
||||
// pictures with kryon/image (see image_lookup).
|
||||
icon_image: Image.Props = props.image
|
||||
if icon_image.asset_path == "" && icon_image.texture.id == cast(u32)0 &&
|
||||
props.icon_type != 0 {
|
||||
icon_image = ImageForIcon(props.icon_type, bounds, props.label)
|
||||
icon_image = IconLookupImage(props.icon_type, bounds, props.label)
|
||||
}
|
||||
has_shape: bool = props.icon_shape != ""
|
||||
has_image: bool = icon_image.asset_path != "" ||
|
||||
@@ -330,7 +331,7 @@ Theme :: #import "theme";
|
||||
image.bounds = Rectangle.{bounds.x + content.icon_x,
|
||||
bounds.y + content.icon_y, content.icon_size,
|
||||
content.icon_size}
|
||||
texture: Texture2D = Image.ImageTextureFor(image)
|
||||
texture: Texture2D = ImageLookupTexture(image)
|
||||
tint_color: u32 = cast(u32)0xffffffff
|
||||
if image.tint != cast(u32)0 {
|
||||
tint_color = image.tint
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
Image :: #import "image";
|
||||
#import "drawing_props"
|
||||
#import "font_metrics"
|
||||
#import "geometry"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Image :: #import "image";
|
||||
Image :: #import "image_props";
|
||||
#import "control_props"
|
||||
#import "drawing_props"
|
||||
#import "geometry"
|
||||
|
||||
@@ -6,6 +6,8 @@ Button :: #import "button";
|
||||
#import "font_metrics"
|
||||
#import "geometry"
|
||||
#import "icon"
|
||||
// Its icons are atlas pictures, which its button draws (see image_lookup).
|
||||
#import "image"
|
||||
#import "input_protocol"
|
||||
#import "paint_queue"
|
||||
#import "session"
|
||||
@@ -232,6 +234,7 @@ Draw :: (session: Session, props: Props,
|
||||
submitted.invisible = true
|
||||
submitted.state = cast(ButtonState)ButtonStateAuto
|
||||
submitted_before := TreeSubmittedCount(session)
|
||||
ImageUsePictures()
|
||||
unused Button.Draw(session, submitted)
|
||||
submitted_after := TreeSubmittedCount(session)
|
||||
if submitted_after > submitted_before { result.node = submitted_after - 1 }
|
||||
|
||||
@@ -3,6 +3,8 @@ Button :: #import "button";
|
||||
#import "control_props"
|
||||
#import "geometry"
|
||||
#import "icon"
|
||||
// Its icons are atlas pictures, which its button draws (see image_lookup).
|
||||
#import "image"
|
||||
#import "session"
|
||||
#import "system_clipboard"
|
||||
#import "tree"
|
||||
@@ -118,6 +120,7 @@ Draw :: (session: Session, props: Props,
|
||||
}
|
||||
}
|
||||
submitted_before := TreeSubmittedCount(session)
|
||||
ImageUsePictures()
|
||||
activation_result := Button.Draw(session, button)
|
||||
submitted_after := TreeSubmittedCount(session)
|
||||
if submitted_after > submitted_before { result.node = submitted_after - 1 }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Image :: #import "image";
|
||||
Image :: #import "image_props";
|
||||
#import "dropdown_behavior"
|
||||
#import "geometry"
|
||||
|
||||
|
||||
@@ -65,6 +65,16 @@ RectangleIntersection :: (a: Rectangle, b: Rectangle) -> Rectangle {
|
||||
return result
|
||||
}
|
||||
|
||||
// The whole pixels a rectangle covers, each edge rounded to the nearest
|
||||
// pixel, so pictures drawn side by side own their shared edge once.
|
||||
RectangleSnap :: (bounds: Rectangle) -> Rectangle {
|
||||
left := FloorInteger(bounds.x + 0.5)
|
||||
top := FloorInteger(bounds.y + 0.5)
|
||||
right := FloorInteger(bounds.x + bounds.width + 0.5)
|
||||
bottom := FloorInteger(bounds.y + bounds.height + 0.5)
|
||||
return .{cast(float32)left, cast(float32)top, cast(float32)(right - left), cast(float32)(bottom - top)}
|
||||
}
|
||||
|
||||
// Axis-aligned coverage of a rectangle rotated clockwise about a world point.
|
||||
RotatedRectangleBounds :: (bounds: Rectangle, origin: Vector2, rotation: float32) -> Rectangle {
|
||||
camera: Camera = .{.offset = origin, .target = origin, .rotation = rotation, .zoom = 1.0}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Image :: #import "image";
|
||||
Image :: #import "image_props";
|
||||
#import "geometry"
|
||||
|
||||
GridMultiLayout :: enum { GridMultiIcon :: 0; GridMultiCompact :: 1 }
|
||||
|
||||
+6
-1
@@ -1,5 +1,6 @@
|
||||
Image :: #import "image";
|
||||
Image :: #import "image_props";
|
||||
#import "geometry"
|
||||
#import "image_lookup"
|
||||
|
||||
// These values are persisted by applications and match icons/*.json.
|
||||
IconType :: enum {
|
||||
@@ -133,6 +134,10 @@ IconType :: enum {
|
||||
IconExpand :: 127
|
||||
}
|
||||
|
||||
// Widgets with an icon slot, such as a button, find these icons once a
|
||||
// program imports kryon/icon; they draw them as pictures (kryon/image).
|
||||
icon_lookup_registered: bool = IconLookupUse(ImageForIcon);
|
||||
|
||||
// Icon IDs are stable across releases because applications persist them.
|
||||
// The atlas positions follow icons/*.json; callers render the returned props
|
||||
// through Image, including when the icon is decorative.
|
||||
|
||||
@@ -8,6 +8,8 @@ Theme :: #import "theme";
|
||||
host_api :: #system_library "host_api";
|
||||
ImageHostedHost :: (session: Session, image: Image.Props) #foreign host_api;
|
||||
Draw :: (session: Session, image: Image.Props) { ImageHostedHost(session, image) }
|
||||
// The host draws a portable composition's pictures.
|
||||
ImageUsePictures :: () {}
|
||||
} else {
|
||||
#import "session"
|
||||
#import "semantic"
|
||||
@@ -16,6 +18,7 @@ Theme :: #import "theme";
|
||||
#import "font_metrics"
|
||||
#import "geometry"
|
||||
using BehaviorModule :: #import "image_behavior";
|
||||
#import "image_lookup"
|
||||
#import "image_raster"
|
||||
Bitmaps :: #import "bitmap_store";
|
||||
#import "paint_queue"
|
||||
@@ -79,6 +82,11 @@ ImageTextureFor :: (image: Image.Props) -> Texture2D {
|
||||
return texture
|
||||
}
|
||||
|
||||
// Code that hands a button its pictures, such as a widget host drawing its
|
||||
// guests or a copy button showing its atlas icons, brings file pictures for
|
||||
// it when it draws (see image_lookup).
|
||||
ImageUsePictures :: () { image_texture_lookup = ImageTextureFor }
|
||||
|
||||
// What an image draws this frame: its picture once that is ready, else its
|
||||
// preview with the source mapped onto the preview's pixels. Asking for the
|
||||
// picture also starts a host loading it; the preview is asked for only
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// kryon/image: the Image widget (image), and file pictures for widgets that
|
||||
// show one beside their content, such as a button's icon (see image_lookup).
|
||||
// Library code imports image itself, so only a program that imports
|
||||
// kryon/image carries those pictures.
|
||||
using Image :: #import "image";
|
||||
#if !#defined(KRYON_HOSTED_UI) {
|
||||
ImageFilesUse :: () -> bool {
|
||||
ImageUsePictures()
|
||||
return true
|
||||
}
|
||||
image_files_registered: bool = ImageFilesUse();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// A widget that can show a picture beside its own content, such as a
|
||||
// button's icon, draws file pictures and built-in icons only when the
|
||||
// program imports them: kryon/image fills the texture lookup and kryon/icon
|
||||
// the icon atlas, each from its module initializer. Without them such a
|
||||
// widget still draws the pixels it is handed as a texture, and carries no
|
||||
// decoder, asset path or atlas.
|
||||
using Image :: #import "image_props";
|
||||
#import "drawing_props"
|
||||
#import "geometry"
|
||||
|
||||
ImageTextureLookup :: #type (image: Image.Props) -> Texture2D;
|
||||
IconImageLookup :: #type (icon_type: s32, bounds: Rectangle, alt_text: string) -> Image.Props;
|
||||
image_texture_lookup: ImageTextureLookup;
|
||||
icon_image_lookup: IconImageLookup;
|
||||
|
||||
ImageLookupUse :: (lookup: ImageTextureLookup) -> bool {
|
||||
image_texture_lookup = lookup
|
||||
return true
|
||||
}
|
||||
|
||||
IconLookupUse :: (lookup: IconImageLookup) -> bool {
|
||||
icon_image_lookup = lookup
|
||||
return true
|
||||
}
|
||||
|
||||
// The texture IMAGE draws with: its own, or its file's once kryon/image is
|
||||
// imported (see ImageTextureFor).
|
||||
ImageLookupTexture :: (image: Image.Props) -> Texture2D {
|
||||
if image.texture.id != cast(u32)0 || image.asset_path == "" || image_texture_lookup == null {
|
||||
return image.texture
|
||||
}
|
||||
return image_texture_lookup(image)
|
||||
}
|
||||
|
||||
// A built-in icon's picture once kryon/icon is imported, else none.
|
||||
IconLookupImage :: (icon_type: s32, bounds: Rectangle, alt_text: string) -> Image.Props {
|
||||
if icon_image_lookup == null { return .{} }
|
||||
return icon_image_lookup(icon_type, bounds, alt_text)
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using Modal :: #import "modal_props";
|
||||
using ActionModule :: #import "modal";
|
||||
Button :: #import "button";
|
||||
Image :: #import "image";
|
||||
Overlay :: #import "overlay";
|
||||
Theme :: #import "theme";
|
||||
// Portable compositions submit the same dialog to a retained UI host; the
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Image :: #import "image";
|
||||
Image :: #import "image_props";
|
||||
#import "control_props"
|
||||
#import "geometry"
|
||||
#import "modal_behavior"
|
||||
|
||||
@@ -76,6 +76,7 @@ hovercard/hovercard.zi
|
||||
hovercard/hover_card_props.zi
|
||||
icon.zi
|
||||
image/image_behavior.zi
|
||||
image/image_lookup.zi
|
||||
image/image_mesh.zi
|
||||
image/image_props.zi
|
||||
image/image_raster.zi
|
||||
@@ -152,6 +153,7 @@ router_props.zi
|
||||
scene_tree_props.zi
|
||||
scroll/scroll_behavior.zi
|
||||
scroll_device.zi
|
||||
scroll_sampling.zi
|
||||
scroll/scroll_props.zi
|
||||
scroll/scroll.zi
|
||||
scrubfield/scrubfield.zi
|
||||
@@ -207,6 +209,7 @@ textfield/textfield.zi
|
||||
text_host.zi
|
||||
text_input.zi
|
||||
text_input_platform.zi
|
||||
text_editing.zi
|
||||
textfield/text_field_props.zi
|
||||
textarea/text_area_props.zi
|
||||
text_layout.zi
|
||||
|
||||
@@ -155,6 +155,8 @@ DrawNavigationDockItem :: (session: Session, props: PropsModule.Props,
|
||||
button.id = props.id
|
||||
button.bounds = bounds
|
||||
button.label = item.label
|
||||
// The bar draws its items' pictures, on its own and on their buttons.
|
||||
Image.ImageUsePictures()
|
||||
button.image = item.image
|
||||
button.icon_shape = item.icon_shape
|
||||
button.selected = item.active && props.motion == null
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Image :: #import "image";
|
||||
Image :: #import "image_props";
|
||||
#import "dropdown_behavior"
|
||||
#import "geometry"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Image :: #import "image";
|
||||
Image :: #import "image_props";
|
||||
#import "transition"
|
||||
#import "geometry"
|
||||
#import "tree_input"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using PropsModule :: #import "navigation_bar_config_props";
|
||||
Button :: #import "button";
|
||||
Dropdown :: #import "dropdown";
|
||||
Image :: #import "image";
|
||||
Modal :: #import "modal_frame";
|
||||
Overlay :: #import "overlay";
|
||||
Theme :: #import "theme";
|
||||
|
||||
@@ -2,6 +2,7 @@ ScrollSchema :: #import "scroll_props";
|
||||
#import "control_props"
|
||||
#import "geometry"
|
||||
#import "scroll_behavior"
|
||||
#import "scroll_sampling"
|
||||
#import "session"
|
||||
#import "style"
|
||||
#import "style_sheet"
|
||||
@@ -55,6 +56,10 @@ SCROLL_DEVICE_SLOTS :: 9
|
||||
scroll_devices: [SCROLL_DEVICE_SLOTS]ScrollDevice;
|
||||
scroll_device_current: s32;
|
||||
|
||||
// The frame samples the device through scroll_sampling once a program
|
||||
// imports a scroll.
|
||||
scroll_sampling_registered: bool = ScrollSamplingUse(BeginScrollFrame, ScrollDeviceMoving);
|
||||
|
||||
ScrollDeviceSlot :: (session: Session) -> s32 {
|
||||
slot := SessionIndex(session)
|
||||
if slot <= 0 || slot >= SCROLL_DEVICE_SLOTS { return 0 }
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Scrolls sample the pointer, wheel and clock once per frame (see
|
||||
// scroll_device). The frame reaches the device through these slots, which
|
||||
// scroll_device fills from its module initializer, so a program without a
|
||||
// scroll, tabs, text area or grid carries none of it.
|
||||
#import "geometry"
|
||||
#import "session"
|
||||
|
||||
ScrollSampleFrame :: #type (session: Session, mouse: Vector2, pressed: bool, down: bool,
|
||||
released: bool, wheel: float32, now_seconds: float64) -> void;
|
||||
ScrollSampleQuery :: #type (session: Session) -> bool;
|
||||
|
||||
scroll_sample_frame: ScrollSampleFrame;
|
||||
scroll_sample_moving: ScrollSampleQuery;
|
||||
|
||||
ScrollSamplingUse :: (frame: ScrollSampleFrame, moving: ScrollSampleQuery) -> bool {
|
||||
scroll_sample_frame = frame
|
||||
scroll_sample_moving = moving
|
||||
return true
|
||||
}
|
||||
|
||||
// The host's pointer, wheel and clock for this frame (see BeginScrollFrame).
|
||||
ScrollSampleBegin :: (session: Session, mouse: Vector2, pressed: bool, down: bool,
|
||||
released: bool, wheel: float32, now_seconds: float64) {
|
||||
if scroll_sample_frame != null {
|
||||
scroll_sample_frame(session, mouse, pressed, down, released, wheel, now_seconds)
|
||||
}
|
||||
}
|
||||
|
||||
// True while a drag, glide or fling still moves a scroll (see ScrollDeviceMoving).
|
||||
ScrollSampleMoving :: (session: Session) -> bool {
|
||||
return scroll_sample_moving != null && scroll_sample_moving(session)
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Editing text comes with the widgets that edit it. The frame and the
|
||||
// platform (such as its accessibility) reach editing through these slots:
|
||||
// text_request fills the request slots when the editing widgets register
|
||||
// their segmentation (see text_boundary), and text_input_platform fills the
|
||||
// focus slots when an editor first takes focus. A program without a text
|
||||
// field or area carries neither module.
|
||||
#import "session"
|
||||
|
||||
TextEditingSend :: #type (session: Session, index: s32, value: string,
|
||||
replace: bool, cursor: s32, anchor: s32) -> bool;
|
||||
TextEditingSession :: #type (session: Session) -> void;
|
||||
TextEditingQuery :: #type (session: Session) -> bool;
|
||||
|
||||
text_editing_send: TextEditingSend;
|
||||
text_editing_clear: TextEditingSession;
|
||||
text_editing_frame_begin: TextEditingSession;
|
||||
text_editing_focused: TextEditingQuery;
|
||||
|
||||
TextEditingUseRequests :: (send: TextEditingSend, clear: TextEditingSession) -> bool {
|
||||
text_editing_send = send
|
||||
text_editing_clear = clear
|
||||
return true
|
||||
}
|
||||
|
||||
TextEditingUseFocus :: (frame_begin: TextEditingSession, focused: TextEditingQuery) {
|
||||
text_editing_frame_begin = frame_begin
|
||||
text_editing_focused = focused
|
||||
}
|
||||
|
||||
// A platform's edit of node INDEX (see TextRequestSend); false when no
|
||||
// editing widget could take it.
|
||||
TextEditingRequest :: (session: Session, index: s32, value: string,
|
||||
replace: bool, cursor: s32, anchor: s32) -> bool {
|
||||
if text_editing_send == null { return false }
|
||||
return text_editing_send(session, index, value, replace, cursor, anchor)
|
||||
}
|
||||
|
||||
// The session closes: its outstanding request goes with it.
|
||||
TextEditingClear :: (session: Session) {
|
||||
if text_editing_clear != null { text_editing_clear(session) }
|
||||
}
|
||||
|
||||
// A new frame starts (see TextInputFocusFrameBegin).
|
||||
TextEditingFrameBegin :: (session: Session) {
|
||||
if text_editing_frame_begin != null { text_editing_frame_begin(session) }
|
||||
}
|
||||
|
||||
// True while an editor has focus, so the frame keeps composing.
|
||||
TextEditingFocused :: (session: Session) -> bool {
|
||||
return text_editing_focused != null && text_editing_focused(session)
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#import "session"
|
||||
#import "text_editing"
|
||||
host_api :: #system_library "host_api";
|
||||
SetPlatformTextKeyboardVisible :: (session: Session, visible: bool) #foreign host_api;
|
||||
|
||||
@@ -38,12 +39,14 @@ text_input_queues: [9]TextInputQueueState;
|
||||
text_keyboards: [9]TextKeyboardState;
|
||||
text_focus_frames: [9]TextFocusFrameState;
|
||||
|
||||
// An editable text field or area has focus in the frame being built.
|
||||
// An editable text field or area has focus in the frame being built. The
|
||||
// first focus brings the frame's focus tracking (see text_editing).
|
||||
#program_export
|
||||
TextInputNoteFocused :: (session: Session) {
|
||||
if !SessionValid(session) {
|
||||
return
|
||||
}
|
||||
TextEditingUseFocus(TextInputFocusFrameBegin, TextInputFocused)
|
||||
index := SessionIndex(session)
|
||||
if !TextInputOwnerMatches(text_focus_frames[index].owner, session) {
|
||||
text_focus_frames[index] = .{}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#import "session"
|
||||
#import "text_editing"
|
||||
#import "tree"
|
||||
#import "tree_input"
|
||||
Utf8 :: #import "std/utf8";
|
||||
@@ -6,12 +7,13 @@ Utf8 :: #import "std/utf8";
|
||||
// Cut points in edited text are grapheme boundaries. The editing widgets
|
||||
// register the segmentation (see text_boundary): a request can only reach an
|
||||
// editing widget, so a program without one keeps the Unicode tables out.
|
||||
// The same registration opens requests to the platform (see text_editing).
|
||||
TextBoundary :: #type (value: string, at: s32) -> s32;
|
||||
text_boundary: TextBoundary;
|
||||
|
||||
TextRequestUseBoundary :: (boundary: TextBoundary) -> bool {
|
||||
text_boundary = boundary
|
||||
return true
|
||||
return TextEditingUseRequests(TextRequestSend, TextRequestClear)
|
||||
}
|
||||
|
||||
// A platform asks for an edit; the widget still validates its value limits
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Dropdown :: #import "dropdown";
|
||||
Image :: #import "image";
|
||||
Image :: #import "image_props";
|
||||
#import "geometry"
|
||||
|
||||
Props :: struct {
|
||||
|
||||
@@ -2,7 +2,6 @@ using TitleBarSchema :: #import "title_bar_props";
|
||||
Button :: #import "button";
|
||||
DropdownWidget :: #import "dropdown";
|
||||
DropdownSchema :: #import "dropdown_props";
|
||||
Image :: #import "image";
|
||||
Theme :: #import "theme";
|
||||
// Portable compositions use the same title bar as retained native hosts.
|
||||
#if #defined(KRYON_HOSTED_UI) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using PropsModule :: #import "toolbar_props";
|
||||
Button :: #import "button";
|
||||
Dropdown :: #import "dropdown";
|
||||
Image :: #import "image";
|
||||
Theme :: #import "theme";
|
||||
#import "session"
|
||||
#import "control_props"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Dropdown :: #import "dropdown";
|
||||
Image :: #import "image";
|
||||
Image :: #import "image_props";
|
||||
#import "drawing_props"
|
||||
|
||||
IconRowItem :: struct {
|
||||
|
||||
+5
-6
@@ -3,10 +3,9 @@
|
||||
#import "session"
|
||||
#import "tree"
|
||||
#import "tree_input"
|
||||
#import "text_request"
|
||||
#import "text_input_platform"
|
||||
#import "text_editing"
|
||||
#import "text_selection_host"
|
||||
Scroll :: #import "scroll_device";
|
||||
#import "scroll_sampling"
|
||||
|
||||
using FrameStatus;
|
||||
|
||||
@@ -44,7 +43,7 @@ BeginFrame :: (session: Session, screen_key: u64,
|
||||
frame_current_modifiers[slot] = active_modifiers[slot]
|
||||
frame_retained = SessionFlagSet(frame_retained, slot, false)
|
||||
unused TreeKeyboardRoute(session)
|
||||
TextInputFocusFrameBegin(session)
|
||||
TextEditingFrameBegin(session)
|
||||
PaintClear(session)
|
||||
frame_paint_unchanged = SessionFlagSet(frame_paint_unchanged, SessionIndex(session), false)
|
||||
TreeStart(session, screen_key, bounds)
|
||||
@@ -58,7 +57,7 @@ BeginFrame :: (session: Session, screen_key: u64,
|
||||
RetainFrame :: (session: Session) -> bool {
|
||||
if !SessionValid(session) { return false }
|
||||
slot := SessionIndex(session)
|
||||
if SessionFlagGet(frame_input_changed, slot) || !SessionFlagGet(paint_snapshots_valid, slot) || TextInputFocused(session) || TextSelectionBusy(session) || Scroll.ScrollDeviceMoving(session) ||
|
||||
if SessionFlagGet(frame_input_changed, slot) || !SessionFlagGet(paint_snapshots_valid, slot) || TextEditingFocused(session) || TextSelectionBusy(session) || ScrollSampleMoving(session) ||
|
||||
!trees[slot].building || trees[slot].error != cast(FrameStatus)FrameOk ||
|
||||
trees[slot].submitted_count != 1 || trees[slot].committed_count < 1 ||
|
||||
trees[slot].scope_depth != 1 || PendingPaintCount(session) != 0 { return false }
|
||||
@@ -223,6 +222,6 @@ CloseSession :: (session: Session) -> bool {
|
||||
TreeDispose(session)
|
||||
PaintDispose(session)
|
||||
TreeInputReset(session)
|
||||
TextRequestClear(session)
|
||||
TextEditingClear(session)
|
||||
return SessionClose(session)
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
#import "input_take"
|
||||
#import "frame_input_provider"
|
||||
#import "gamepad_navigation"
|
||||
Scroll :: #import "scroll_device";
|
||||
#import "scroll_sampling"
|
||||
|
||||
using FrameStatus;
|
||||
|
||||
@@ -30,7 +30,7 @@ TreeFrameRun :: (session: Session, input: FrameDriverInput) -> FrameDriverResult
|
||||
unused TreePointerUpdate(session, pointer)
|
||||
TreeSecondaryPointerUpdate(session, input.secondary)
|
||||
unused PointerWheelSend(session, pointer.x, pointer.y, wheel)
|
||||
Scroll.BeginScrollFrame(session, .{pointer.x, pointer.y}, pointer.pressed,
|
||||
ScrollSampleBegin(session, .{pointer.x, pointer.y}, pointer.pressed,
|
||||
pointer.down, pointer.released, wheel, input.seconds)
|
||||
if input.frame_input != null && !FrameInputProviderBegin(input.frame_input, session) { return result }
|
||||
published := session
|
||||
|
||||
@@ -22,6 +22,8 @@ Is :: (x: s32, y: s32, color: u32) -> bool {
|
||||
|
||||
// A 2 by 2 image drawn over the whole 64 by 64 surface.
|
||||
Draw :: (path: string, smooth: bool, tint: Color) -> bool {
|
||||
// A widget asks a picture's size before drawing it, which brings files.
|
||||
if Raster.ImageWidth(path) <= 0 { return false }
|
||||
Raster.BeginRasterFrame()
|
||||
Texture.emitting_smooth = smooth
|
||||
full: Rectangle = .{0.0, 0.0, 64.0, 64.0}
|
||||
|
||||
@@ -24,6 +24,8 @@ Is :: (x: s32, y: s32, color: u32) -> bool {
|
||||
}
|
||||
|
||||
Draw :: (path: string, columns: s32, rows: s32, clip: Rectangle) -> bool {
|
||||
// A widget asks a picture's size before drawing it, which brings files.
|
||||
if Raster.ImageWidth(path) <= 0 { return false }
|
||||
Raster.BeginRasterFrame()
|
||||
Raster.RasterImageMesh(path, 0, .{0.0, 0.0, 2.0, 2.0}, points[:], columns, rows,
|
||||
clip, .{255, 255, 255, 255})
|
||||
|
||||
@@ -11,6 +11,8 @@ Lanczos :: #import "lanczos_cache";
|
||||
CLIP :: Rectangle.{7.0, 9.0, 113.0, 103.0}
|
||||
|
||||
Draw :: (path: string, source: Rectangle, bounds: Rectangle, tint: Color, smooth: bool) -> bool {
|
||||
// A widget asks a picture's size before drawing it, which brings files.
|
||||
if Raster.ImageWidth(path) <= 0 { return false }
|
||||
Raster.BeginRasterFrame()
|
||||
Texture.emitting_smooth = smooth
|
||||
Raster.RasterImage(path, 0, source, bounds, CLIP, .{}, 0.0, 0.0, tint)
|
||||
@@ -35,6 +37,7 @@ Save :: (directory: string, name: string, index: s32) -> bool {
|
||||
// Two uniform pictures meeting at any fractional edge must cover each
|
||||
// device pixel once. A translucent fixture also detects double coverage.
|
||||
Adjacent :: (path: string, edge: float32, horizontal: bool, smooth: bool) -> bool {
|
||||
if Raster.ImageWidth(path) <= 0 { return false }
|
||||
Raster.BeginRasterFrame()
|
||||
Texture.emitting_smooth = smooth
|
||||
a := Rectangle.{-8.25, -8.25, edge + 8.25, 160.0}
|
||||
@@ -89,7 +92,7 @@ main :: (argc: s32, argv: **u8) -> s32 {
|
||||
}
|
||||
if Lanczos.LanczosPending() { print("an exact copy started another: % %\n", sources[kind], index); return 7 }
|
||||
if !Save(directory, sources[kind], index) { return 8 }
|
||||
snapped := Lanczos.LanczosSnap(targets[index])
|
||||
snapped := RectangleSnap(targets[index])
|
||||
print("cairo % % % % % %\n", sources[kind], index, snapped.x, snapped.y, snapped.width, snapped.height)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ Test :: () -> s32 {
|
||||
if !Draw(path, boxes[index], targets[index], tints[index], true) { return 60 + kind * 4 + index }
|
||||
for i: 0..65535 { if frame[i] != kept[i] { return 70 + kind * 4 + index } }
|
||||
if Lanczos.LanczosPending() { return 80 + kind * 4 + index }
|
||||
Publish(sources[kind], index, Lanczos.LanczosSnap(targets[index]))
|
||||
Publish(sources[kind], index, RectangleSnap(targets[index]))
|
||||
}
|
||||
// A sharp draw never makes a copy.
|
||||
if !Draw(path, boxes[1], targets[1], tints[0], false) || Lanczos.LanczosPending() { return 90 + kind }
|
||||
|
||||
@@ -41,6 +41,14 @@ not_without_pictures: [10]string = .["image_decode_linux", "avif_decode", "lancz
|
||||
"ziran_image_decode", "riff", "bmff", "video_linux", "std_thread_linux",
|
||||
"std_parallel_linux", "app_asset_path"];
|
||||
|
||||
// What a frame example carries none of when it shows no picture, edits no
|
||||
// text and has no scroll, tabs, text area or grid: the picture chain, text
|
||||
// input and the scroll device.
|
||||
not_in_a_plain_frame: [14]string = .["image_decode_linux", "avif_decode", "lanczos_cache",
|
||||
"ziran_image_decode", "riff", "bmff", "native_api", "video_linux", "std_thread_linux",
|
||||
"std_parallel_linux", "app_asset_path", "text_request", "text_input_platform",
|
||||
"scroll_device"];
|
||||
|
||||
failures: s32;
|
||||
|
||||
Fail :: (example: string, message: string, module: string) {
|
||||
@@ -193,19 +201,39 @@ main :: () -> s32 {
|
||||
if !BuildFrame(ziran, "examples/box") {
|
||||
Fail("box", "does not build", "examples/box")
|
||||
} else {
|
||||
Expect("box", "build/examples/box/generated/desktop/c", box_present[:], not_without_pictures[:])
|
||||
Expect("box", "build/examples/box/generated/desktop/c", box_present[:], not_in_a_plain_frame[:])
|
||||
}
|
||||
|
||||
image_present: [6]string = .["image", "image_decode_linux", "avif_decode",
|
||||
"lanczos_cache", "riff", "bmff"]
|
||||
image_absent: [1]string = .["video_linux"]
|
||||
// A button without an icon: no picture, no text input, no scrolls.
|
||||
button_present: [3]string = .["button", "tree", "tree_frame"]
|
||||
if !BuildFrame(ziran, "examples/button") {
|
||||
Fail("button", "does not build", "examples/button")
|
||||
} else {
|
||||
Expect("button", "build/examples/button/generated/desktop/c", button_present[:],
|
||||
not_in_a_plain_frame[:])
|
||||
}
|
||||
|
||||
image_present: [11]string = .["image", "image_decode_linux", "avif_decode",
|
||||
"ziran_image_decode", "lanczos_cache", "riff", "bmff", "native_api",
|
||||
"std_thread_linux", "std_parallel_linux", "app_asset_path"]
|
||||
image_absent: [3]string = .["video_linux", "text_request", "text_input_platform"]
|
||||
if !BuildFrame(ziran, "examples/image") {
|
||||
Fail("image", "does not build", "examples/image")
|
||||
} else {
|
||||
Expect("image", "build/examples/image/generated/desktop/c", image_present[:], image_absent[:])
|
||||
}
|
||||
|
||||
textfield_present: [5]string = .["textfield", "text_request", "text_input_platform",
|
||||
"text_boundary", "scroll_device"]
|
||||
textfield_absent: [1]string = .["video_linux"]
|
||||
if !BuildFrame(ziran, "examples/textfield") {
|
||||
Fail("textfield", "does not build", "examples/textfield")
|
||||
} else {
|
||||
Expect("textfield", "build/examples/textfield/generated/desktop/c", textfield_present[:],
|
||||
textfield_absent[:])
|
||||
}
|
||||
|
||||
if failures > 0 { return 1 }
|
||||
print("pay per import: window, hello, box and image carry only what they import\n")
|
||||
print("pay per import: window, hello, box, button, image and textfield carry only what they import\n")
|
||||
return 0
|
||||
}
|
||||
@@ -77,7 +77,7 @@ main :: (argc: s32, argv: **u8) -> s32 {
|
||||
}
|
||||
if Pixels.PixmapLanczosPending() { print("an exact copy started another: % %\n", sources[kind], index); return 7 }
|
||||
if !Save(directory, sources[kind], index) { return 8 }
|
||||
snapped := Lanczos.LanczosSnap(targets[index])
|
||||
snapped := RectangleSnap(targets[index])
|
||||
print("pixmap % % % % % %\n", sources[kind], index, snapped.x, snapped.y, snapped.width, snapped.height)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,6 @@ MeasureGlyphWidth :: (value: string, font: s32, typeface: string) -> s32 {
|
||||
}
|
||||
#program_export
|
||||
MeasureGlyphLineHeight :: (font: s32, typeface: string) -> s32 { unused typeface; return font }
|
||||
#program_export
|
||||
ImageWidth :: (path: string) -> s32 { unused path; return 0 }
|
||||
#program_export
|
||||
ImageHeight :: (path: string) -> s32 { unused path; return 0 }
|
||||
|
||||
#program_export
|
||||
RasterText :: (value: string, x: s32, y: s32, font: s32, color: Color) {
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
"tests/system_clipboard_host.zi"
|
||||
],
|
||||
"bindings": [
|
||||
"image_raster:ImageWidth=widget_benchmark_host:ImageWidth",
|
||||
"image_raster:ImageHeight=widget_benchmark_host:ImageHeight",
|
||||
"system_clipboard:SystemClipboardOpenHost=system_clipboard_host:SystemClipboardOpenHost",
|
||||
"system_clipboard:SystemClipboardByteHost=system_clipboard_host:SystemClipboardByteHost",
|
||||
"system_clipboard:SystemClipboardWriteHost=system_clipboard_host:SystemClipboardWriteHost",
|
||||
|
||||
@@ -62,18 +62,6 @@ RasterRoundedRectangleOutline :: (bounds: Rectangle, radius: float32,
|
||||
sample.outline_color = color
|
||||
}
|
||||
|
||||
#program_export
|
||||
ImageWidth :: (asset_path: string) -> s32 {
|
||||
unused asset_path
|
||||
return 0
|
||||
}
|
||||
|
||||
#program_export
|
||||
ImageHeight :: (asset_path: string) -> s32 {
|
||||
unused asset_path
|
||||
return 0
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterLine :: (line: Rectangle, color: Color) {
|
||||
unused line; unused color
|
||||
|
||||
@@ -3,9 +3,7 @@ source=$repo/tests/ziran_button_theme_raster_test.zi
|
||||
|
||||
widget_host=ziran_button_theme_raster_host
|
||||
widget_mesh_host=ziran_mesh_noop_host
|
||||
set -- \
|
||||
--bind image_raster:ImageWidth=ziran_button_theme_raster_host:ImageWidth \
|
||||
--bind image_raster:ImageHeight=ziran_button_theme_raster_host:ImageHeight
|
||||
set --
|
||||
. "$repo/tests/widget_raster_bindings.sh"
|
||||
|
||||
widget_std="$ziran_root/std"
|
||||
|
||||
@@ -4,6 +4,8 @@ Theme :: #import "theme";
|
||||
|
||||
Button :: #import "kryon/button";
|
||||
Image :: #import "kryon/image";
|
||||
// Built-in icon_type icons draw once a program imports kryon/icon.
|
||||
#import "kryon/icon"
|
||||
#import "button_behavior"
|
||||
#import "control_props"
|
||||
#import "geometry"
|
||||
|
||||
@@ -5,8 +5,6 @@ source=$repo/tests/ziran_dialog_test.zi
|
||||
widget_host=ziran_widget_noop_host
|
||||
widget_mesh_host=ziran_mesh_noop_host
|
||||
set -- \
|
||||
--bind image_raster:ImageWidth=ziran_widget_noop_host:ImageWidth \
|
||||
--bind image_raster:ImageHeight=ziran_widget_noop_host:ImageHeight \
|
||||
--bind system_clipboard:SystemClipboardOpenHost=system_clipboard_host:SystemClipboardOpenHost \
|
||||
--bind system_clipboard:SystemClipboardByteHost=system_clipboard_host:SystemClipboardByteHost \
|
||||
--bind system_clipboard:SystemClipboardWriteHost=system_clipboard_host:SystemClipboardWriteHost
|
||||
|
||||
@@ -6,18 +6,6 @@
|
||||
outlines: s32;
|
||||
outline_x: float32;
|
||||
|
||||
#program_export
|
||||
ImageWidth :: (asset_path: string) -> s32 {
|
||||
unused asset_path
|
||||
return 0
|
||||
}
|
||||
|
||||
#program_export
|
||||
ImageHeight :: (asset_path: string) -> s32 {
|
||||
unused asset_path
|
||||
return 0
|
||||
}
|
||||
|
||||
#program_export
|
||||
MeasureGlyphWidth :: (value: string, font: s32, typeface: string) -> s32 {
|
||||
unused font
|
||||
|
||||
@@ -4,9 +4,7 @@ source=$repo/tests/ziran_keyboard_navigation_test.zi
|
||||
|
||||
widget_host=ziran_keyboard_navigation_host
|
||||
widget_mesh_host=ziran_mesh_noop_host
|
||||
set -- \
|
||||
--bind image_raster:ImageWidth=ziran_keyboard_navigation_host:ImageWidth \
|
||||
--bind image_raster:ImageHeight=ziran_keyboard_navigation_host:ImageHeight
|
||||
set --
|
||||
. "$repo/tests/widget_raster_bindings.sh"
|
||||
|
||||
widget_std="$ziran_root/std"
|
||||
|
||||
@@ -5,8 +5,6 @@ source=$repo/tests/ziran_press_focus_test.zi
|
||||
widget_host=ziran_composition_widget_host
|
||||
widget_mesh_host=ziran_mesh_noop_host
|
||||
set -- \
|
||||
--bind image_raster:ImageWidth=ziran_button_widget_host:ImageWidth \
|
||||
--bind image_raster:ImageHeight=ziran_button_widget_host:ImageHeight \
|
||||
--bind system_clipboard:SystemClipboardOpenHost=system_clipboard_host:SystemClipboardOpenHost \
|
||||
--bind system_clipboard:SystemClipboardByteHost=system_clipboard_host:SystemClipboardByteHost \
|
||||
--bind system_clipboard:SystemClipboardWriteHost=system_clipboard_host:SystemClipboardWriteHost
|
||||
|
||||
@@ -5,8 +5,6 @@ source=$repo/tests/ziran_text_field_menu_test.zi
|
||||
widget_host=ziran_context_menu_widget_host
|
||||
widget_mesh_host=ziran_context_menu_widget_host
|
||||
set -- \
|
||||
--bind image_raster:ImageWidth=ziran_widget_noop_host:ImageWidth \
|
||||
--bind image_raster:ImageHeight=ziran_widget_noop_host:ImageHeight \
|
||||
--bind system_clipboard:SystemClipboardOpenHost=system_clipboard_host:SystemClipboardOpenHost \
|
||||
--bind system_clipboard:SystemClipboardByteHost=system_clipboard_host:SystemClipboardByteHost \
|
||||
--bind system_clipboard:SystemClipboardWriteHost=system_clipboard_host:SystemClipboardWriteHost
|
||||
|
||||
@@ -10,8 +10,6 @@ source=$repo/tests/ziran_text_field_tab_test.zi
|
||||
widget_host=ziran_widget_noop_host
|
||||
widget_mesh_host=ziran_mesh_noop_host
|
||||
set -- \
|
||||
--bind image_raster:ImageWidth=ziran_widget_noop_host:ImageWidth \
|
||||
--bind image_raster:ImageHeight=ziran_widget_noop_host:ImageHeight \
|
||||
--bind system_clipboard:SystemClipboardOpenHost=system_clipboard_host:SystemClipboardOpenHost \
|
||||
--bind system_clipboard:SystemClipboardByteHost=system_clipboard_host:SystemClipboardByteHost \
|
||||
--bind system_clipboard:SystemClipboardWriteHost=system_clipboard_host:SystemClipboardWriteHost
|
||||
|
||||
@@ -5,8 +5,6 @@ source=$repo/tests/ziran_text_input_focus_test.zi
|
||||
widget_host=ziran_composition_widget_host
|
||||
widget_mesh_host=ziran_mesh_noop_host
|
||||
set -- \
|
||||
--bind image_raster:ImageWidth=ziran_widget_noop_host:ImageWidth \
|
||||
--bind image_raster:ImageHeight=ziran_widget_noop_host:ImageHeight \
|
||||
--bind system_clipboard:SystemClipboardOpenHost=system_clipboard_host:SystemClipboardOpenHost \
|
||||
--bind system_clipboard:SystemClipboardByteHost=system_clipboard_host:SystemClipboardByteHost \
|
||||
--bind system_clipboard:SystemClipboardWriteHost=system_clipboard_host:SystemClipboardWriteHost
|
||||
|
||||
+2
-1
@@ -136,7 +136,8 @@ text = "src/ui/text/text.zi"
|
||||
text_measure = "src/ui/text/text_measure.zi"
|
||||
text_typeface = "src/ui/text_typeface.zi"
|
||||
text_align = "src/ui/text_align.zi"
|
||||
image = "src/ui/image/image.zi"
|
||||
image = "src/ui/image/image_files.zi"
|
||||
image_props = "src/ui/image/image_props.zi"
|
||||
svg_shape = "src/ui/svg_shape.zi"
|
||||
bitmap_image = "src/ui/bitmap_image.zi"
|
||||
image_mesh = "src/ui/image/image_mesh.zi"
|
||||
|
||||
Reference in new issue
Block a user