Comments (1)
That was a more tedious task than I expected.
I added a red gradient background to the basic_table sample.
Here, I added a third column to the table and set the background color.
diff --git a/examples/basic_table.rb b/examples/basic_table.rb
index 474e1d4..fa5d834 100644
--- a/examples/basic_table.rb
+++ b/examples/basic_table.rb
@@ -30,11 +30,17 @@ end
model_handler = UI::FFI::TableModelHandler.malloc
model_handler.to_ptr.free = Fiddle::RUBY_FREE
-model_handler.NumColumns = rbcallback(4) { 2 }
-model_handler.ColumnType = rbcallback(4) { 0 }
+model_handler.NumColumns = rbcallback(4) { 3 }
+model_handler.ColumnType = rbcallback(4, [1, 1, 4]) do |_, _, column|
+ column == 2 ? UI::TableValueTypeColor : UI::TableValueTypeString
+end
model_handler.NumRows = rbcallback(4) { 5 }
model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
- UI.new_table_value_string(data[row][column])
+ if column == 2
+ UI.new_table_value_color(1, 0, 0, row / 5.0)
+ else
+ UI.new_table_value_string(data[row][column])
+ end
end
model_handler.SetCellValue = rbcallback(0, [0]) {}
@@ -43,7 +49,7 @@ model = UI.new_table_model(model_handler)
table_params = UI::FFI::TableParams.malloc
table_params.to_ptr.free = Fiddle::RUBY_FREE
table_params.Model = model
-table_params.RowBackgroundColorModelColumn = -1
+table_params.RowBackgroundColorModelColumn = 2
table = UI.new_table(table_params)
UI.table_append_text_column(table, 'Animal', 0, -1)
Full script.
# frozen_string_literal: true
require 'libui'
UI = LibUI
UI.init
main_window = UI.new_window('Animal sounds', 300, 200, 1)
hbox = UI.new_horizontal_box
UI.window_set_child(main_window, hbox)
data = [
%w[cat meow],
%w[dog woof],
%w[chicken cock-a-doodle-doo],
%w[horse neigh],
%w[cow moo]
]
# Protects BlockCaller objects from garbage collection.
@block_callers = []
def rbcallback(*args, &block)
args << [0] if args.size == 1 # Argument types are ommited
block_caller = Fiddle::Closure::BlockCaller.new(*args, &block)
@block_callers << block_caller
block_caller
end
model_handler = UI::FFI::TableModelHandler.malloc
model_handler.to_ptr.free = Fiddle::RUBY_FREE
model_handler.NumColumns = rbcallback(4) { 3 }
model_handler.ColumnType = rbcallback(4, [1, 1, 4]) do |_, _, column|
column == 2 ? UI::TableValueTypeColor : UI::TableValueTypeString
end
model_handler.NumRows = rbcallback(4) { 5 }
model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
if column == 2
UI.new_table_value_color(1, 0, 0, row / 5.0)
else
UI.new_table_value_string(data[row][column])
end
end
model_handler.SetCellValue = rbcallback(0, [0]) {}
model = UI.new_table_model(model_handler)
table_params = UI::FFI::TableParams.malloc
table_params.to_ptr.free = Fiddle::RUBY_FREE
table_params.Model = model
table_params.RowBackgroundColorModelColumn = 2
table = UI.new_table(table_params)
UI.table_append_text_column(table, 'Animal', 0, -1)
UI.table_append_text_column(table, 'Description', 1, -1)
UI.box_append(hbox, table, 1)
UI.control_show(main_window)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.free_table_model(model)
UI.quit
0
end
UI.main
UI.quit
If you want to change the text color instead of the background color, please see here.
https://github.com/AndyObtiva/glimmer-dsl-libui/blob/bc37abfb4134d8ab4e4ddc8f8fd78ce8eb147ce7/lib/glimmer/libui/control_proxy/column/text_color_column_proxy.rb#L42-L44
from libui.
Related Issues (20)
- Adding more than one area underneath a grid makes only the first area show up (Mac) HOT 2
- Small bug (I think) in examples/ directory, at the file called draw_text.rb HOT 2
- Turing Pattern HOT 2
- Examples: could an example be added for LibUI.new_scrolling_area? HOT 5
- [Possible bug or strange behaviour] On 2nd run the libui window is black HOT 8
- libui-ng HOT 8
- ARM64/AARCH64 Support HOT 26
- Exe wont start (Fiddle::DLError) Windows 11 Notebook HOT 14
- Glimmer DSL for LibUI Wins Fukuoka Ruby 2022 Special Award HOT 1
- libui-ng - "beta" ffi for it, for "early testing"? HOT 6
- Warning message when running LibUI::FFI.uiInit on Mac HOT 2
- Example for Parent and Child Windows HOT 8
- [Question] Field Edit sign restriction visible in GUI? HOT 1
- libui-ng related methods: how to use it? HOT 1
- Organising on https://github.com/kojix2 ? HOT 3
- Custom toplevel methods: aiming to enhance LibUI HOT 2
- Two things about libui-ng: one is a build failure with "rake"; the other is a suggestion HOT 2
- Table Selection API HOT 12
- Question: Why choose `fiddle` rather than `ffi`? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libui.